diff --git a/seasoned_api/src/pirate/pirateRepository.js b/seasoned_api/src/pirate/pirateRepository.js index f8455a7..1b3333f 100644 --- a/seasoned_api/src/pirate/pirateRepository.js +++ b/seasoned_api/src/pirate/pirateRepository.js @@ -1,13 +1,13 @@ const assert = require('assert'); var PythonShell = require('python-shell'); var async = require('async'); +var PythonShell = require('python-shell'); async function find(searchterm, callback) { - var PythonShell = require('python-shell'); var options = { - // pythonPath: '/usr/bin/python3', - pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3', + pythonPath: '/usr/bin/python3', + // pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3', args: [searchterm] } @@ -15,6 +15,17 @@ async function find(searchterm, callback) { // PythonShell does not support return }; + +async function callPythonAddMagnet(magnet, callback) { + var options = { + pythonPath: '/usr/bin/python3', + // pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3', + args: ['"'+magnet+'"'] + } + + PythonShell.run('../app/magnet.py', options, callback); +} + async function SearchPiratebay(query) { return await new Promise((resolve) => { return find(query, function(err, results) { @@ -23,4 +34,12 @@ async function SearchPiratebay(query) { }) } -module.exports = { SearchPiratebay } \ No newline at end of file +async function AddMagnet(magnet) { + return await new Promise((resolve) => { + return callPythonAddMagnet(magnet, function(err, results) { + resolve({ success: true }) + }) + }) +} + +module.exports = { SearchPiratebay, AddMagnet } \ No newline at end of file diff --git a/seasoned_api/src/webserver/app.js b/seasoned_api/src/webserver/app.js index 9b63fee..cf3b93a 100644 --- a/seasoned_api/src/webserver/app.js +++ b/seasoned_api/src/webserver/app.js @@ -74,7 +74,8 @@ router.get('/v1/plex/requests/all', mustBeAuthenticated, require('./controllers/ router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js')); // TODO ADD AUTHENTICATION -router.get('/v1/pirate/search', require('./controllers/pirate/searchTheBay.js')); +router.get('/v1/pirate/search', mustBeAuthenticated, require('./controllers/pirate/searchTheBay.js')); +router.post('/v1/pirate/add', mustBeAuthenticated, require('./controllers/pirate/addMagnet.js')); /** * TMDB diff --git a/seasoned_api/src/webserver/controllers/pirate/addMagnet.js b/seasoned_api/src/webserver/controllers/pirate/addMagnet.js new file mode 100644 index 0000000..66d7e74 --- /dev/null +++ b/seasoned_api/src/webserver/controllers/pirate/addMagnet.js @@ -0,0 +1,23 @@ + +/* +* @Author: KevinMidboe +* @Date: 2017-10-21 09:54:31 +* @Last Modified by: KevinMidboe +* @Last Modified time: 2017-10-21 15:32:43 +*/ + +const PirateRepository = require('src/pirate/pirateRepository'); + +function updateRequested(req, res) { + const magnet = req.body.magnet; + + PirateRepository.AddMagnet(magnet) + .then((result) => { + res.send(result); + }) + .catch((error) => { + res.status(401).send({ success: false, error: error.message }); + }); +} + +module.exports = updateRequested;