Linted all pirate, git, tmdb and searchHistory scripts.
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
class GitRepository {
|
class GitRepository {
|
||||||
|
static dumpHook(body) {
|
||||||
dumpHook(body) {
|
/* eslint-disable no-console */
|
||||||
console.log(body);
|
console.log(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GitRepository;
|
module.exports = GitRepository;
|
||||||
|
|||||||
@@ -1,54 +1,53 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
var PythonShell = require('python-shell');
|
const PythonShell = require('python-shell');
|
||||||
var async = require('async');
|
|
||||||
|
|
||||||
async function find(searchterm, callback) {
|
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 = {
|
PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback);
|
||||||
pythonPath: '/usr/bin/python3',
|
// PythonShell does not support return
|
||||||
// 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
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
async function callPythonAddMagnet(magnet, callback) {
|
async function callPythonAddMagnet(magnet, callback) {
|
||||||
var options = {
|
const options = {
|
||||||
pythonPath: '/usr/bin/python',
|
pythonPath: '/usr/bin/python',
|
||||||
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
||||||
args: [magnet]
|
args: [magnet],
|
||||||
}
|
};
|
||||||
|
|
||||||
PythonShell.run('../app/magnet.py', options, callback);
|
PythonShell.run('../app/magnet.py', options, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function SearchPiratebay(query) {
|
async function SearchPiratebay(query) {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => find(query, (err, results) => {
|
||||||
return find(query, function(err, results) {
|
if (err) {
|
||||||
if (err) {
|
/* eslint-disable no-console */
|
||||||
console.log('THERE WAS A FUCKING ERROR!')
|
console.log('THERE WAS A FUCKING ERROR!');
|
||||||
reject(Error('There was a error when searching for torrents'))
|
reject(Error('There was a error when searching for torrents'));
|
||||||
}
|
}
|
||||||
if (results) {
|
if (results) {
|
||||||
console.log('result', results);
|
/* eslint-disable no-console */
|
||||||
resolve(JSON.parse(results, null, '\t'));
|
console.log('result', results);
|
||||||
}
|
resolve(JSON.parse(results, null, '\t'));
|
||||||
})
|
}
|
||||||
})
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function AddMagnet(magnet) {
|
async function AddMagnet(magnet) {
|
||||||
return await new Promise((resolve) => {
|
return await new Promise(resolve => callPythonAddMagnet(magnet, (err, results) => {
|
||||||
return callPythonAddMagnet(magnet, function(err, results) {
|
if (err) {
|
||||||
if (err) {
|
/* eslint-disable no-console */
|
||||||
console.log(err)
|
console.log(err);
|
||||||
}
|
}
|
||||||
resolve({ success: true })
|
/* eslint-disable no-console */
|
||||||
})
|
console.log(results);
|
||||||
})
|
resolve({ success: true });
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { SearchPiratebay, AddMagnet }
|
module.exports = { SearchPiratebay, AddMagnet };
|
||||||
|
|||||||
@@ -1,39 +1,38 @@
|
|||||||
const establishedDatabase = require('src/database/database');
|
const establishedDatabase = require('src/database/database');
|
||||||
|
|
||||||
class SearchHistory {
|
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.
|
* Retrive a search queries for a user from the database.
|
||||||
* @param {User} user existing user
|
* @param {User} user existing user
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
read(user) {
|
read(user) {
|
||||||
return this.database.all(this.queries.read, user)
|
return this.database.all(this.queries.read, user)
|
||||||
.then(rows => rows.map(row => row.search_query));
|
.then(rows => rows.map(row => row.search_query));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new search entry in the database.
|
* Creates a new search entry in the database.
|
||||||
* @param {User} user a new user
|
* @param {User} user a new user
|
||||||
* @param {String} searchQuery the query the user searched for
|
* @param {String} searchQuery the query the user searched for
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
create(user, searchQuery) {
|
create(user, searchQuery) {
|
||||||
return this.database.run(this.queries.create, [searchQuery, user]).catch((error) => {
|
return this.database.run(this.queries.create, [searchQuery, user])
|
||||||
if (error.message.includes('FOREIGN')) {
|
.catch((error) => {
|
||||||
throw new Error('Could not create search history.');
|
if (error.message.includes('FOREIGN')) {
|
||||||
}
|
throw new Error('Could not create search history.');
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SearchHistory;
|
module.exports = SearchHistory;
|
||||||
|
|||||||
@@ -2,43 +2,43 @@ const assert = require('assert');
|
|||||||
const establishedDatabase = require('src/database/database');
|
const establishedDatabase = require('src/database/database');
|
||||||
|
|
||||||
class Cache {
|
class Cache {
|
||||||
constructor(database) {
|
constructor(database) {
|
||||||
this.database = database || establishedDatabase
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
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 ' +
|
'DATETIME(created_at, "+" || time_to_live || " seconds") as expires ' +
|
||||||
'FROM cache WHERE key = ? AND now < 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 (?, ?, ?)',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an unexpired cache entry by key.
|
* Retrieve an unexpired cache entry by key.
|
||||||
* @param {String} key of the cache entry
|
* @param {String} key of the cache entry
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
get(key) {
|
get(key) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.database.get(this.queries.read, [key]))
|
.then(() => this.database.get(this.queries.read, [key]))
|
||||||
.then((row) => {
|
.then((row) => {
|
||||||
assert(row, 'Could not find cache enrty with that key.');
|
assert(row, 'Could not find cache enrty with that key.');
|
||||||
return JSON.parse(row.value);
|
return JSON.parse(row.value);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert cache entry with key and value.
|
* Insert cache entry with key and value.
|
||||||
* @param {String} key of the cache entry
|
* @param {String} key of the cache entry
|
||||||
* @param {String} value of the cache entry
|
* @param {String} value of the cache entry
|
||||||
* @param {Number} timeToLive the number of seconds before entry expires
|
* @param {Number} timeToLive the number of seconds before entry expires
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
set(key, value, timeToLive = 172800) {
|
set(key, value, timeToLive = 172800) {
|
||||||
const json = JSON.stringify(value);
|
const json = JSON.stringify(value);
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.database.run(this.queries.create, [key, json, timeToLive]))
|
.then(() => this.database.run(this.queries.create, [key, json, timeToLive]))
|
||||||
.then(() => value);
|
.then(() => value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Cache;
|
module.exports = Cache;
|
||||||
|
|||||||
Reference in New Issue
Block a user