mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-01-06 05:29:34 -06:00
Add test for authentication endpoint.
This commit is contained in:
@@ -28,15 +28,18 @@ export default () => {
|
||||
const port = server.get('port');
|
||||
|
||||
sequelize.sync().then(() => {
|
||||
server.listen(port, () => {
|
||||
console.log(`Express server listening on - http://${hostname}:${port}`);
|
||||
});
|
||||
if (!module.parent) {
|
||||
server.listen(port, () => {
|
||||
console.log(
|
||||
`Express server listening on - http://${hostname}:${port}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||
// application specific logging, throwing an error, or other logic here
|
||||
});
|
||||
|
||||
return {create, start};
|
||||
|
||||
@@ -7,7 +7,7 @@ const sequelize = new Sequelize(
|
||||
{
|
||||
dialect: 'postgres',
|
||||
host: 'localhost',
|
||||
// logging: false,
|
||||
logging: false,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@ const init = server => {
|
||||
});
|
||||
|
||||
server.use('/api', apiRoute);
|
||||
|
||||
server.use((err, req, res, next) => {
|
||||
if (err) {
|
||||
console.log('Error in routes/index', err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import uuid from 'uuid/v1';
|
||||
import uuid from 'uuid';
|
||||
import btoa from 'btoa';
|
||||
import request from 'request-promise';
|
||||
|
||||
const rxAuthToken = /authenticationToken="([^"]+)"/;
|
||||
|
||||
const options = (username, password) => ({
|
||||
const urlParams = (username, password) => ({
|
||||
url: 'https://plex.tv/users/sign_in.xml',
|
||||
headers: {
|
||||
'X-Plex-Client-Identifier': uuid(),
|
||||
@@ -18,8 +18,7 @@ const encryptUserCreds = (username, password) => {
|
||||
};
|
||||
|
||||
const fetchToken = async (username, password) => {
|
||||
const res = await request.post(options(username, password));
|
||||
console.log(res);
|
||||
const res = await request.post(urlParams(username, password));
|
||||
const token = res.match(rxAuthToken)[1];
|
||||
return token;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@ const importLibraries = async () => {
|
||||
const importMostWatched = async req => {
|
||||
const plexApi = plexApiClient();
|
||||
const mostWatched = await plexApi.getMostWatched(req);
|
||||
console.log('6========', mostWatched);
|
||||
mostWatched.forEach(async libraryData => {
|
||||
await updateLibrary([libraryData]);
|
||||
});
|
||||
@@ -70,7 +69,6 @@ const updateLibrary = libraryData => {
|
||||
};
|
||||
|
||||
const createLibrary = libraryData => {
|
||||
console.log(libraryData[1]);
|
||||
libraryData.forEach(async data => {
|
||||
await models.PlexLibrary.upsert(
|
||||
{
|
||||
|
||||
@@ -8,7 +8,6 @@ const getAuthToken = async (req, res) => {
|
||||
const {password} = req.query;
|
||||
|
||||
auth(username, password).then(data => {
|
||||
console.log(data);
|
||||
return res.json(data);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -74,7 +74,6 @@ const request = async function(url) {
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.response) {
|
||||
// console.log('data', error.response.data);
|
||||
console.log('status', error.response.status);
|
||||
console.log('headers', error.response.headers);
|
||||
return reject(error.response);
|
||||
@@ -100,7 +99,6 @@ const getMostWatched = async function(req) {
|
||||
const urlParams = mostWatchedUrlParams(req);
|
||||
const mostWatchedUrl = buildUrl(urlParams);
|
||||
const response = await request(mostWatchedUrl);
|
||||
console.log(response.MediaContainer.Metadata);
|
||||
return response.MediaContainer.Metadata;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user