Linted all pirate, git, tmdb and searchHistory scripts.
This commit is contained in:
@@ -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;
|
||||
module.exports = GitRepository;
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user