Merge pull request #48 from KevinMidboe/api_add-magnet

Api add magnet
This commit is contained in:
2017-10-21 15:39:15 +02:00
committed by GitHub
3 changed files with 48 additions and 5 deletions

View File

@@ -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 }
async function AddMagnet(magnet) {
return await new Promise((resolve) => {
return callPythonAddMagnet(magnet, function(err, results) {
resolve({ success: true })
})
})
}
module.exports = { SearchPiratebay, AddMagnet }

View File

@@ -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

View File

@@ -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;