From 81aeed86efbcc30100ec920b5328aee5ffcea660 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Wed, 7 Feb 2018 13:51:42 +0100 Subject: [PATCH] Linted all pirate, git, tmdb and searchHistory scripts. --- seasoned_api/src/git/gitRepository.js | 11 ++- seasoned_api/src/pirate/pirateRepository.js | 75 +++++++++---------- .../src/searchHistory/searchHistory.js | 43 ++++++----- seasoned_api/src/tmdb/cache.js | 70 ++++++++--------- 4 files changed, 98 insertions(+), 101 deletions(-) diff --git a/seasoned_api/src/git/gitRepository.js b/seasoned_api/src/git/gitRepository.js index 54d0891..703ce2c 100644 --- a/seasoned_api/src/git/gitRepository.js +++ b/seasoned_api/src/git/gitRepository.js @@ -1,10 +1,9 @@ -const assert = require('assert'); class GitRepository { - - dumpHook(body) { - console.log(body); - } + static dumpHook(body) { + /* eslint-disable no-console */ + console.log(body); + } } -module.exports = GitRepository; \ No newline at end of file +module.exports = GitRepository; diff --git a/seasoned_api/src/pirate/pirateRepository.js b/seasoned_api/src/pirate/pirateRepository.js index ca2a4fb..8dce82b 100644 --- a/seasoned_api/src/pirate/pirateRepository.js +++ b/seasoned_api/src/pirate/pirateRepository.js @@ -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) { + const options = { + pythonPath: '/usr/bin/python3', + // pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3', + args: [searchterm, '-s', 'piratebay', '--print'], + }; - var options = { - pythonPath: '/usr/bin/python3', - // pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3', - args: [searchterm, '-s', 'piratebay', '--print'] - } - - PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback); - // PythonShell does not support return -}; + PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback); + // PythonShell does not support return +} async function callPythonAddMagnet(magnet, callback) { - var options = { - pythonPath: '/usr/bin/python', - // pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3', - args: [magnet] - } + const options = { + pythonPath: '/usr/bin/python', + // pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3', + args: [magnet], + }; - PythonShell.run('../app/magnet.py', options, callback); + PythonShell.run('../app/magnet.py', options, callback); } async function SearchPiratebay(query) { - return await new Promise((resolve, reject) => { - return find(query, function(err, results) { - if (err) { - console.log('THERE WAS A FUCKING ERROR!') - reject(Error('There was a error when searching for torrents')) - } - if (results) { - console.log('result', results); - resolve(JSON.parse(results, null, '\t')); - } - }) - }) + return await new Promise((resolve, reject) => find(query, (err, results) => { + if (err) { + /* 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) { - if (err) { - console.log(err) - } - resolve({ success: true }) - }) - }) + return await new Promise(resolve => callPythonAddMagnet(magnet, (err, results) => { + if (err) { + /* eslint-disable no-console */ + console.log(err); + } + /* eslint-disable no-console */ + console.log(results); + resolve({ success: true }); + })); } -module.exports = { SearchPiratebay, AddMagnet } +module.exports = { SearchPiratebay, AddMagnet }; diff --git a/seasoned_api/src/searchHistory/searchHistory.js b/seasoned_api/src/searchHistory/searchHistory.js index 1fabb31..c51590e 100644 --- a/seasoned_api/src/searchHistory/searchHistory.js +++ b/seasoned_api/src/searchHistory/searchHistory.js @@ -1,39 +1,38 @@ const establishedDatabase = require('src/database/database'); class SearchHistory { + constructor(database) { + this.database = database || establishedDatabase; + this.queries = { + 'create': 'insert into search_history (search_query, user_name) values (?, ?)', + 'read': 'select search_query from search_history where user_name = ? order by id desc', + }; + } - constructor(database) { - this.database = database || establishedDatabase; - this.queries = { - 'create': 'insert into search_history (search_query, user_name) values (?, ?)', - 'read': 'select search_query from search_history where user_name = ? order by id desc', - }; - } - - /** + /** * Retrive a search queries for a user from the database. * @param {User} user existing user * @returns {Promise} */ - read(user) { - return this.database.all(this.queries.read, user) - .then(rows => rows.map(row => row.search_query)); - } + read(user) { + return this.database.all(this.queries.read, user) + .then(rows => rows.map(row => row.search_query)); + } - /** + /** * Creates a new search entry in the database. * @param {User} user a new user * @param {String} searchQuery the query the user searched for * @returns {Promise} */ - create(user, searchQuery) { - return this.database.run(this.queries.create, [searchQuery, user]).catch((error) => { - if (error.message.includes('FOREIGN')) { - throw new Error('Could not create search history.'); - } - }); - } - + create(user, searchQuery) { + 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; diff --git a/seasoned_api/src/tmdb/cache.js b/seasoned_api/src/tmdb/cache.js index 4c8b62e..584df15 100644 --- a/seasoned_api/src/tmdb/cache.js +++ b/seasoned_api/src/tmdb/cache.js @@ -2,43 +2,43 @@ const assert = require('assert'); const establishedDatabase = require('src/database/database'); class Cache { - constructor(database) { - this.database = database || establishedDatabase - this.queries = { - '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 (?, ?, ?)', - }; - } + constructor(database) { + this.database = database || establishedDatabase; + this.queries = { + 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 (?, ?, ?)', + }; + } - /** - * Retrieve an unexpired cache entry by key. - * @param {String} key of the cache entry - * @returns {Object} - */ - get(key) { - return Promise.resolve() - .then(() => this.database.get(this.queries.read, [key])) - .then((row) => { - assert(row, 'Could not find cache enrty with that key.'); - return JSON.parse(row.value); - }) - } + /** + * Retrieve an unexpired cache entry by key. + * @param {String} key of the cache entry + * @returns {Object} + */ + get(key) { + return Promise.resolve() + .then(() => this.database.get(this.queries.read, [key])) + .then((row) => { + assert(row, 'Could not find cache enrty with that key.'); + return JSON.parse(row.value); + }); + } - /** - * Insert cache entry with key and value. - * @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} - */ - set(key, value, timeToLive = 172800) { - const json = JSON.stringify(value); - return Promise.resolve() - .then(() => this.database.run(this.queries.create, [key, json, timeToLive])) - .then(() => value); - } + /** + * Insert cache entry with key and value. + * @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} + */ + set(key, value, timeToLive = 172800) { + const json = JSON.stringify(value); + return Promise.resolve() + .then(() => this.database.run(this.queries.create, [key, json, timeToLive])) + .then(() => value); + } } module.exports = Cache;