Merge pull request #80 from KevinMidboe/linting

Linting
This commit is contained in:
2018-02-07 14:24:43 +01:00
committed by GitHub
54 changed files with 852 additions and 877 deletions

View File

@@ -1,3 +1,12 @@
{
"extends": "airbnb-base"
"extends": [
"airbnb-base"
],
"rules": {
"indent": ["error", 3],
"prefer-destructuring": 0,
"camelcase": 0,
"import/no-unresolved": 0,
"import/no-extraneous-dependencies": 0
}
}

View File

@@ -5,7 +5,7 @@
"start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js",
"test": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. mocha --recursive test/system",
"coverage": "cross-env PLANFLIX_CONFIG=conf/test.json NODE_PATH=. istanbul cover -x script/autogenerate-documentation.js --include-all-sources --dir test/.coverage node_modules/mocha/bin/_mocha --recursive test/**/* -- --report lcovonly && cat test/.coverage/lcov.info | coveralls && rm -rf test/.coverage",
"lint": "./node_modules/.bin/eslint src/webserver/"
"lint": "./node_modules/.bin/eslint src/"
},
"dependencies": {
"bcrypt-nodejs": "^0.0.3",

View File

@@ -25,11 +25,11 @@ class Config {
throw new Error(`Filed "${section} => ${option}" does not exist.`);
}
const field = new Field(this.fields[section][option])
const field = new Field(this.fields[section][option]);
if (field.value === '') {
const envField = process.env[[section.toUpperCase(), option.toUpperCase()].join('_')]
if (envField !== undefined && envField.length !== 0) { return envField }
const envField = process.env[[section.toUpperCase(), option.toUpperCase()].join('_')];
if (envField !== undefined && envField.length !== 0) { return envField; }
}
if (field.value === undefined) {

View File

@@ -1,5 +1,4 @@
class EnvironmentVariables {
constructor(variables) {
this.variables = variables || process.env;
}

View File

@@ -2,7 +2,6 @@ const Filters = require('./filters.js');
const EnvironmentVariables = require('./environmentVariables.js');
class Field {
constructor(rawValue, environmentVariables) {
this.rawValue = rawValue;
this.filters = new Filters(rawValue);

View File

@@ -1,5 +1,4 @@
class Filters {
constructor(value) {
this.value = value;
this.delimiter = '|';

View File

@@ -1,5 +1,6 @@
const configuration = require('src/config/configuration').getInstance();
const SqliteDatabase = require('src/database/sqliteDatabase');
const database = new SqliteDatabase(configuration.get('database', 'host'));
/**

View File

@@ -1,8 +1,7 @@
const assert = require('assert');
class GitRepository {
dumpHook(body) {
static dumpHook(body) {
/* eslint-disable no-console */
console.log(body);
}
}

View File

@@ -6,7 +6,6 @@ class Player {
this.product = undefined;
this.title = undefined;
this.state = undefined;
}
}

View File

@@ -1,54 +1,53 @@
const assert = require('assert');
var PythonShell = require('python-shell');
var async = require('async');
const PythonShell = require('python-shell');
async function find(searchterm, callback) {
var options = {
const options = {
pythonPath: '/usr/bin/python3',
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
args: [searchterm, '-s', 'piratebay', '--print']
}
args: [searchterm, '-s', 'piratebay', '--print'],
};
PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback);
// PythonShell does not support return
};
}
async function callPythonAddMagnet(magnet, callback) {
var options = {
const options = {
pythonPath: '/usr/bin/python',
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
args: [magnet]
}
args: [magnet],
};
PythonShell.run('../app/magnet.py', options, callback);
}
async function SearchPiratebay(query) {
return await new Promise((resolve, reject) => {
return find(query, function(err, results) {
return await new Promise((resolve, reject) => find(query, (err, results) => {
if (err) {
console.log('THERE WAS A FUCKING ERROR!')
reject(Error('There was a error when searching for torrents'))
/* eslint-disable no-console */
console.log('THERE WAS A FUCKING ERROR!');
reject(Error('There was a error when searching for torrents'));
}
if (results) {
/* eslint-disable no-console */
console.log('result', results);
resolve(JSON.parse(results, null, '\t'));
}
})
})
}));
}
async function AddMagnet(magnet) {
return await new Promise((resolve) => {
return callPythonAddMagnet(magnet, function(err, results) {
return await new Promise(resolve => callPythonAddMagnet(magnet, (err, results) => {
if (err) {
console.log(err)
/* eslint-disable no-console */
console.log(err);
}
resolve({ success: true })
})
})
/* eslint-disable no-console */
console.log(results);
resolve({ success: true });
}));
}
module.exports = { SearchPiratebay, AddMagnet }
module.exports = { SearchPiratebay, AddMagnet };

View File

@@ -5,8 +5,8 @@ const convertStreamToUser = require('src/plex/stream/convertStreamToUser');
const ConvertStreamToPlayback = require('src/plex/stream/convertStreamToPlayback');
function convertPlexToStream(plexStream) {
const stream = convertPlexToSeasoned(plexStream)
const plexStreamMedia = plexStream.Media[0]
const stream = convertPlexToSeasoned(plexStream);
const plexStreamMedia = plexStream.Media[0];
stream.mediaInfo = convertStreamToMediaInfo(plexStreamMedia);
stream.player = convertStreamToPlayer(plexStream.Player);

View File

@@ -1,10 +1,3 @@
/*
* @Author: KevinMidboe
* @Date: 2017-05-03 23:26:46
* @Last Modified by: KevinMidboe
* @Last Modified time: 2017-05-03 23:27:59
*/
const configuration = require('src/config/configuration').getInstance();
function hookDumpController(req, res) {

View File

@@ -1,25 +1,24 @@
class mailTemplate {
constructor(mediaItem) {
this.mediaItem = mediaItem;
this.posterURL = 'https://image.tmdb.org/t/p/w600';
}
toText() {
return this.mediaItem.title + ' (' + this.mediaItem.year + ')'; // plain text body
return `${this.mediaItem.title} (${this.mediaItem.year})`; // plain text body
}
toHTML() {
const info = {
name: this.mediaItem.title,
year: '(' + this.mediaItem.year + ')',
poster: this.posterURL + this.mediaItem.poster
}
year: `(${this.mediaItem.year})`,
poster: this.posterURL + this.mediaItem.poster,
};
return `
<h1>${info.name} ${info.year}</h1>
<img src="${info.poster}">
`
`;
}
}

View File

@@ -1,79 +1,72 @@
const assert = require('assert');
const convertPlexToSeasoned = require('src/plex/convertPlexToSeasoned');
const convertPlexToStream = require('src/plex/convertPlexToStream');
var rp = require('request-promise');
const PLEX_METHODS = ['lookup', 'playing']
const rp = require('request-promise');
class PlexRepository {
search(query, callback) {
var options = {
uri: 'http://10.0.0.44:32400/search?query=' + query,
headers: {
'Accept': 'application/json'
},
json: true
}
return rp(options)
.then((result) => this.mapResults(result))
.then(([mappedResults, resultCount]) => {
return { 'results': mappedResults, 'total_results': resultCount }
})
}
compareTmdbToPlex(tmdb, plexResult) {
return Promise.resolve()
.then(() => {
plexResult.results.map((plexItem) => {
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year)
tmdb.matchedInPlex = true;
})
return tmdb
})
}
inPlex(tmdbResult) {
return Promise.resolve()
.then(() => this.search(tmdbResult.title))
.then((plexResult) => this.compareTmdbToPlex(tmdbResult, plexResult))
.then(plexResult => this.compareTmdbToPlex(tmdbResult, plexResult));
}
mapResults(response) {
search(query) {
const options = {
uri: `http://10.0.0.44:32400/search?query=${query}`,
headers: {
Accept: 'application/json',
},
json: true,
};
return rp(options)
.then(result => this.mapResults(result))
.then(([mappedResults, resultCount]) => ({ results: mappedResults, total_results: resultCount }));
}
static compareTmdbToPlex(tmdb, plexResult) {
return Promise.resolve()
.then(() => {
if (! response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0]
plexResult.results.map((plexItem) => {
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year) { tmdb.matchedInPlex = true; }
return tmdb;
});
return tmdb;
});
}
static mapResults(response) {
return Promise.resolve()
.then(() => {
if (!response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0];
const mappedResults = response.MediaContainer.Metadata.filter((element) => {
return (element.type === 'movie' || element.type === 'show')
}).map((element) => convertPlexToSeasoned(element))
return [mappedResults, mappedResults.length]
return (element.type === 'movie' || element.type === 'show');
}).map((element) => convertPlexToSeasoned(element));
return [mappedResults, mappedResults.length];
})
.catch((error) => {throw new Error(error)})
.catch((error) => { throw new Error(error); });
}
nowPlaying() {
var options = {
const options = {
uri: 'http://10.0.0.44:32400/status/sessions',
headers: {
'Accept': 'application/json'
Accept: 'application/json',
},
json: true
}
json: true,
};
return rp(options)
.then((result) => {
if (result.MediaContainer.size > 0) {
var playing = result.MediaContainer.Video.map(convertPlexToStream);
return {'size': Object.keys(playing).length, 'video': playing };
} else {
return { 'size': 0, 'video': [] };
const playing = result.MediaContainer.Video.map(convertPlexToStream);
return { size: Object.keys(playing).length, video: playing };
}
return { size: 0, video: [] };
})
.catch((err) => {
throw new Error('Error handling plex playing. Error: ' + err);
})
throw new Error(`Error handling plex playing. Error: ${err}`);
});
}
// multipleInPlex(tmdbResults) {

View File

@@ -1,66 +1,57 @@
const assert = require('assert');
const PlexRepository = require('src/plex/plexRepository');
const plexRepository = new PlexRepository();
const configuration = require('src/config/configuration').getInstance();
const Cache = require('src/tmdb/cache');
const configuration = require('src/config/configuration').getInstance();
const TMDB = require('src/tmdb/tmdb');
const cache = new Cache();
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
var Promise = require('bluebird');
var rp = require('request-promise');
const establishedDatabase = require('src/database/database');
const MailTemplate = require('src/plex/mailTemplate')
const plexRepository = new PlexRepository();
const cache = new Cache();
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
var pythonShell = require('python-shell');
const MailTemplate = require('src/plex/mailTemplate');
const nodemailer = require('nodemailer');
class RequestRepository {
constructor(cache, database) {
this.database = database || establishedDatabase;
this.queries = {
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
'fetchRequstedItems': "SELECT * FROM requests",
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
'checkIfIdRequested': "SELECT * FROM requests WHERE id IS ? AND type IS ?",
}
insertRequest: "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
fetchRequstedItems: 'SELECT * FROM requests',
updateRequestedById: 'UPDATE requests SET status = ? WHERE id is ? AND type is ?',
checkIfIdRequested: 'SELECT * FROM requests WHERE id IS ? AND type IS ?',
};
}
search(query, type, page) {
return Promise.resolve()
.then(() => tmdb.search(query, type, page))
// .then((tmdbResult) => plexRepository.multipleInPlex(tmdbResult))
.then((result) => {
return result
})
.catch((error) => {return 'error in the house' + error})
.then(result => result)
.catch(error => `error in the house${error}`);
}
lookup(identifier, type = 'movie') {
return Promise.resolve()
.then(() => tmdb.lookup(identifier, type))
.then((tmdbMovie) => this.checkID(tmdbMovie))
.then((tmdbMovie) => plexRepository.inPlex(tmdbMovie))
.then(tmdbMovie => this.checkID(tmdbMovie))
.then(tmdbMovie => plexRepository.inPlex(tmdbMovie))
.catch((error) => {
console.log(error)
})
throw new Error(error);
});
}
checkID(tmdbMovie) {
return Promise.resolve()
.then(() => this.database.get(this.queries.checkIfIdRequested, [tmdbMovie.id, tmdbMovie.type]))
.then((result, error) => {
if (error) { throw new Error(error); }
let already_requested = false;
if (result)
already_requested = true
if (result) { already_requested = true; }
tmdbMovie.requested = already_requested;
return tmdbMovie;
})
});
}
/**
@@ -69,22 +60,19 @@ class RequestRepository {
* @returns {Promise} If nothing has gone wrong.
*/
sendRequest(identifier, type, ip, user_agent, user) {
tmdb.lookup(identifier, type).then(movie => {
if (user === 'false')
user = 'NULL';
console.log(user)
tmdb.lookup(identifier, type).then((movie) => {
if (user === 'false') { user = 'NULL'; }
// Add request to database
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type])
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type]);
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: configuration.get('mail', 'user_pi'),
pass: configuration.get('mail', 'password_pi')
}
pass: configuration.get('mail', 'password_pi'),
},
// host: configuration.get('mail', 'host'),
// port: 26,
// ignoreTLS: true,
@@ -92,16 +80,16 @@ class RequestRepository {
// secure: false, // secure:true for port 465, secure:false for port 587
});
const mailTemplate = new MailTemplate(movie)
const mailTemplate = new MailTemplate(movie);
// setup email data with unicode symbols
let mailOptions = {
const mailOptions = {
// TODO get the mail adr from global location (easy to add)
from: 'MovieRequester <pi.midboe@gmail.com>', // sender address
to: 'kevin.midboe@gmail.com', // list of receivers
subject: 'Download request', // Subject line
text: mailTemplate.toText(),
html: mailTemplate.toHTML()
html: mailTemplate.toHTML(),
};
// send mail with defined transport object
@@ -111,12 +99,10 @@ class RequestRepository {
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
})
});
// TODO add better response when done.
return Promise.resolve();
}
fetchRequested() {
@@ -126,7 +112,6 @@ class RequestRepository {
updateRequestedById(id, type, status) {
return this.database.run(this.queries.updateRequestedById, [status, id, type]);
}
}
module.exports = RequestRepository;

View File

@@ -8,7 +8,6 @@ class convertStreamToPlayback {
this.videoProfile = plexStream.videoProfile;
this.duration = plexStream.duration;
this.container = plexStream.container;
}
}

View File

@@ -1,7 +1,6 @@
const establishedDatabase = require('src/database/database');
class SearchHistory {
constructor(database) {
this.database = database || establishedDatabase;
this.queries = {
@@ -27,13 +26,13 @@ class SearchHistory {
* @returns {Promise}
*/
create(user, searchQuery) {
return this.database.run(this.queries.create, [searchQuery, user]).catch((error) => {
return this.database.run(this.queries.create, [searchQuery, user])
.catch((error) => {
if (error.message.includes('FOREIGN')) {
throw new Error('Could not create search history.');
}
});
}
}
module.exports = SearchHistory;

View File

@@ -1,22 +1,17 @@
const assert = require('assert');
const Stray = require('src/seasoned/stray');
const establishedDatabase = require('src/database/database');
var pythonShell = require('python-shell');
function foo(e) {
throw('Foooo');
}
const pythonShell = require('python-shell');
class StrayRepository {
constructor(database) {
this.database = database || establishedDatabase;
this.queries = {
'read': 'SELECT * FROM stray_eps WHERE id = ?',
'readAll': 'SELECT id, name, season, episode, verified FROM stray_eps',
'readAllFiltered': 'SELECT id, name, season, episode, verified FROM stray_eps WHERE verified = ',
'checkVerified': 'SELECT id FROM stray_eps WHERE verified = 0 AND id = ?',
'verify': 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
read: 'SELECT * FROM stray_eps WHERE id = ?',
readAll: 'SELECT id, name, season, episode, verified FROM stray_eps',
readAllFiltered: 'SELECT id, name, season, episode, verified FROM stray_eps WHERE verified = ',
checkVerified: 'SELECT id FROM stray_eps WHERE verified = 0 AND id = ?',
verify: 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
};
}
@@ -24,11 +19,11 @@ class StrayRepository {
return this.database.get(this.queries.read, strayId).then((row) => {
assert.notEqual(row, undefined, `Could not find list with id ${strayId}.`);
return row;
})
});
}
readAll(verified = null, page = 1) {
var dbSearchQuery = this.queries.readAll;
readAll(verified = null) {
let dbSearchQuery = this.queries.readAll;
if (verified != null) {
dbSearchQuery = this.queries.readAllFiltered + verified.toString();
}
@@ -40,19 +35,19 @@ class StrayRepository {
stray.episode = row.episode;
stray.verified = row.verified;
return stray;
}))
}));
}
verifyStray(strayId) {
return this.database.get(this.queries.checkVerified, strayId).then((row) => {
assert.notEqual(row, undefined, `Stray '${strayId}' already verified.`);
var options = {
const options = {
pythonPath: '/usr/bin/python3',
args: [strayId]
}
args: [strayId],
};
pythonShell.run('../app/moveSeasoned.py', options, function (err, results) {
pythonShell.run('../app/moveSeasoned.py', options, (err, results) => {
if (err) throw err;
// TODO Add error handling!! StrayRepository.ERROR
// results is an array consisting of messages collected during execution
@@ -60,7 +55,7 @@ class StrayRepository {
});
return this.database.run(this.queries.verify, strayId);
})
});
}
}

View File

@@ -3,12 +3,12 @@ const establishedDatabase = require('src/database/database');
class Cache {
constructor(database) {
this.database = database || establishedDatabase
this.database = database || establishedDatabase;
this.queries = {
'read': 'SELECT value, time_to_live, created_at, DATETIME("now", "localtime") as now, ' +
read: 'SELECT value, time_to_live, created_at, DATETIME("now", "localtime") as now, ' +
'DATETIME(created_at, "+" || time_to_live || " seconds") as expires ' +
'FROM cache WHERE key = ? AND now < expires',
'create': 'INSERT OR REPLACE INTO cache (key, value, time_to_live) VALUES (?, ?, ?)',
create: 'INSERT OR REPLACE INTO cache (key, value, time_to_live) VALUES (?, ?, ?)',
};
}
@@ -23,7 +23,7 @@ class Cache {
.then((row) => {
assert(row, 'Could not find cache enrty with that key.');
return JSON.parse(row.value);
})
});
}
/**
@@ -31,7 +31,7 @@ class Cache {
* @param {String} key of the cache entry
* @param {String} value of the cache entry
* @param {Number} timeToLive the number of seconds before entry expires
* @returns {Object}
* @returns {Object}
*/
set(key, value, timeToLive = 172800) {
const json = JSON.stringify(value);

View File

@@ -2,7 +2,6 @@ const User = require('src/user/user');
const jwt = require('jsonwebtoken');
class Token {
constructor(user) {
this.user = user;
}

View File

@@ -2,7 +2,6 @@ const assert = require('assert');
const establishedDatabase = require('src/database/database');
class UserRepository {
constructor(database) {
this.database = database || establishedDatabase;
this.queries = {
@@ -53,7 +52,6 @@ class UserRepository {
changePassword(user, password) {
return this.database.run(this.queries.change, [password, user.username]);
}
}
module.exports = UserRepository;

View File

@@ -2,7 +2,6 @@ const bcrypt = require('bcrypt-nodejs');
const UserRepository = require('src/user/userRepository');
class UserSecurity {
constructor(database) {
this.userRepository = new UserRepository(database);
}

View File

@@ -8,7 +8,6 @@ const configuration = require('src/config/configuration').getInstance();
// TODO: Have our raven router check if there is a value, if not don't enable raven.
Raven.config(configuration.get('raven', 'DSN')).install();
const app = express(); // define our app using express
app.use(Raven.requestHandler());
// this will let us get the data from a POST

View File

@@ -9,7 +9,7 @@ const requestRepository = new RequestRepository();
* @returns {Callback}
*/
function historyController(req, res) {
const user = req.loggedInUser;
// const user = req.loggedInUser;
requestRepository.fetchRequested()
.then((requestedItems) => {

View File

@@ -2,11 +2,9 @@
* @Author: KevinMidboe
* @Date: 2017-05-03 23:26:46
* @Last Modified by: KevinMidboe
* @Last Modified time: 2017-05-03 23:27:59
* @Last Modified time: 2018-02-06 20:54:22
*/
const configuration = require('src/config/configuration').getInstance();
function hookDumpController(req, res) {
console.log(req);
}

View File

@@ -1,4 +1,5 @@
const PlexRepository = require('src/plex/plexRepository');
const plexRepository = new PlexRepository();
function playingController(req, res) {
@@ -8,7 +9,7 @@ function playingController(req, res) {
})
.catch((error) => {
res.status(500).send({ success: false, error: error.message });
})
});
}
module.exports = playingController;

View File

@@ -1,4 +1,5 @@
const RequestRepository = require('src/plex/requestRepository');
const requestRepository = new RequestRepository();
/**

View File

@@ -1,4 +1,5 @@
const PlexRepository = require('src/plex/plexRepository');
const plexRepository = new PlexRepository();
/**
@@ -9,19 +10,19 @@ const plexRepository = new PlexRepository();
* @returns {Callback}
*/
function searchMediaController(req, res) {
const { query, page } = req.query;
const { query } = req.query;
plexRepository.searchMedia(query)
plexRepository.search(query)
.then((media) => {
if (media !== undefined || media.length > 0) {
res.send(media);
} else {
res.status(404).send({ success: false, error: 'Search query did not return any results.'})
res.status(404).send({ success: false, error: 'Search query did not return any results.' });
}
})
.catch((error) => {
res.status(500).send({ success: false, error: error.message });
})
});
}
module.exports = searchMediaController;

View File

@@ -1,6 +1,7 @@
const SearchHistory = require('src/searchHistory/searchHistory');
const Cache = require('src/tmdb/cache');
const RequestRepository = require('src/plex/requestRepository.js');
const cache = new Cache();
const requestRepository = new RequestRepository(cache);
const searchHistory = new SearchHistory();
@@ -18,7 +19,7 @@ function searchRequestController(req, res) {
})
.catch((error) => {
res.status(500).send({ success: false, error: error.message });
})
});
}
module.exports = searchRequestController;

View File

@@ -1,4 +1,5 @@
const RequestRepository = require('src/plex/requestRepository.js');
const requestRepository = new RequestRepository();
/**
@@ -13,7 +14,7 @@ function submitRequestController(req, res) {
const id = req.params.mediaId;
const type = req.query.type;
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
const user_agent = req.headers['user-agent']
const user_agent = req.headers['user-agent'];
const user = req.headers.loggedinuser;
requestRepository.sendRequest(id, type, ip, user_agent, user)

View File

@@ -1,4 +1,5 @@
const RequestRepository = require('src/plex/requestRepository');
const requestRepository = new RequestRepository();
/**

View File

@@ -1,4 +1,5 @@
const StrayRepository = require('src/seasoned/strayRepository');
const strayRepository = new StrayRepository();

View File

@@ -1,5 +1,5 @@
const configuration = require('src/config/configuration').getInstance();
const StrayRepository = require('src/seasoned/strayRepository');
const strayRepository = new StrayRepository();
function strayByIdController(req, res) {

View File

@@ -1,10 +1,10 @@
const configuration = require('src/config/configuration').getInstance();
const Cache = require('src/tmdb/cache');
const TMDB = require('src/tmdb/tmdb');
const cache = new Cache();
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
/**
* Controller: Retrieve nowplaying movies / now airing shows
* @param {Request} req http request variable
@@ -14,7 +14,6 @@ const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
function listSearchController(req, res) {
const listname = req.params.listname;
const { type, id, page } = req.query;
console.log(listname, type, id, page)
tmdb.listSearch(listname, type, id, page)
.then((results) => {
res.send(results);

View File

@@ -1,6 +1,7 @@
const configuration = require('src/config/configuration').getInstance();
const Cache = require('src/tmdb/cache');
const TMDB = require('src/tmdb/tmdb');
const cache = new Cache();
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));

View File

@@ -1,6 +1,7 @@
const configuration = require('src/config/configuration').getInstance();
const Cache = require('src/tmdb/cache');
const TMDB = require('src/tmdb/tmdb');
const cache = new Cache();
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
@@ -19,7 +20,7 @@ function searchMediaController(req, res) {
if (movies !== undefined || movies.length > 0) {
res.send(movies);
} else {
res.status(404).send({ success: false, error: 'Search query did not return any results.'})
res.status(404).send({ success: false, error: 'Search query did not return any results.' });
}
})
.catch((error) => {

View File

@@ -1,4 +1,5 @@
const SearchHistory = require('src/searchHistory/searchHistory');
const searchHistory = new SearchHistory();
/**

View File

@@ -2,6 +2,7 @@ const User = require('src/user/user');
const Token = require('src/user/token');
const UserSecurity = require('src/user/userSecurity');
const configuration = require('src/config/configuration').getInstance();
const secret = configuration.get('authentication', 'secret');
const userSecurity = new UserSecurity();

View File

@@ -1,5 +1,6 @@
const User = require('src/user/user');
const UserSecurity = require('src/user/userSecurity');
const userSecurity = new UserSecurity();
/**

View File

@@ -1,10 +1,10 @@
const mustBeAuthenticated = (req, res, next) => {
if (req.loggedInUser === undefined) {
return res.status(401).send({
success: false,
error: 'You must be logged in.',
}); }
});
}
return next();
};

View File

@@ -1,5 +1,6 @@
/* eslint-disable no-param-reassign */
const configuration = require('src/config/configuration').getInstance();
const secret = configuration.get('authentication', 'secret');
const Token = require('src/user/token');

View File

@@ -2,7 +2,10 @@ const config = require('src/config/configuration').getInstance();
const app = require('./app');
module.exports = app.listen(config.get('webserver', 'port'), () => {
/* eslint-disable no-console */
console.log('seasonedAPI');
/* eslint-disable no-console */
console.log(`Database is located at ${config.get('database', 'host')}`);
/* eslint-disable no-console */
console.log(`Webserver is listening on ${config.get('webserver', 'port')}`);
})
});