diff options
Diffstat (limited to 'controllers/api/v1/remoteVideos.js')
-rw-r--r-- | controllers/api/v1/remoteVideos.js | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/controllers/api/v1/remoteVideos.js b/controllers/api/v1/remoteVideos.js index 58bb5f3cb..475a874cf 100644 --- a/controllers/api/v1/remoteVideos.js +++ b/controllers/api/v1/remoteVideos.js | |||
@@ -1,55 +1,53 @@ | |||
1 | ;(function () { | 1 | 'use strict' |
2 | 'use strict' | ||
3 | 2 | ||
4 | var express = require('express') | 3 | var express = require('express') |
5 | var pluck = require('lodash-node/compat/collection/pluck') | 4 | var pluck = require('lodash-node/compat/collection/pluck') |
6 | 5 | ||
7 | var middleware = require('../../../middlewares') | 6 | var middleware = require('../../../middlewares') |
8 | var secureMiddleware = middleware.secure | 7 | var secureMiddleware = middleware.secure |
9 | var cacheMiddleware = middleware.cache | 8 | var cacheMiddleware = middleware.cache |
10 | var reqValidator = middleware.reqValidators.remote | 9 | var reqValidator = middleware.reqValidators.remote |
11 | var videos = require('../../../models/videos') | 10 | var videos = require('../../../models/videos') |
12 | 11 | ||
13 | var router = express.Router() | 12 | var router = express.Router() |
14 | 13 | ||
15 | router.post('/add', | 14 | router.post('/add', |
16 | reqValidator.secureRequest, | 15 | reqValidator.secureRequest, |
17 | secureMiddleware.decryptBody, | 16 | secureMiddleware.decryptBody, |
18 | reqValidator.remoteVideosAdd, | 17 | reqValidator.remoteVideosAdd, |
19 | cacheMiddleware.cache(false), | 18 | cacheMiddleware.cache(false), |
20 | addRemoteVideos | 19 | addRemoteVideos |
21 | ) | 20 | ) |
22 | 21 | ||
23 | router.post('/remove', | 22 | router.post('/remove', |
24 | reqValidator.secureRequest, | 23 | reqValidator.secureRequest, |
25 | secureMiddleware.decryptBody, | 24 | secureMiddleware.decryptBody, |
26 | reqValidator.remoteVideosRemove, | 25 | reqValidator.remoteVideosRemove, |
27 | cacheMiddleware.cache(false), | 26 | cacheMiddleware.cache(false), |
28 | removeRemoteVideo | 27 | removeRemoteVideo |
29 | ) | 28 | ) |
30 | 29 | ||
31 | // --------------------------------------------------------------------------- | 30 | // --------------------------------------------------------------------------- |
32 | 31 | ||
33 | module.exports = router | 32 | module.exports = router |
34 | 33 | ||
35 | // --------------------------------------------------------------------------- | 34 | // --------------------------------------------------------------------------- |
36 | 35 | ||
37 | function addRemoteVideos (req, res, next) { | 36 | function addRemoteVideos (req, res, next) { |
38 | videos.addRemotes(req.body.data, function (err, videos) { | 37 | videos.addRemotes(req.body.data, function (err, videos) { |
39 | if (err) return next(err) | 38 | if (err) return next(err) |
40 | 39 | ||
41 | res.json(videos) | 40 | res.json(videos) |
42 | }) | 41 | }) |
43 | } | 42 | } |
44 | 43 | ||
45 | function removeRemoteVideo (req, res, next) { | 44 | function removeRemoteVideo (req, res, next) { |
46 | var url = req.body.signature.url | 45 | var url = req.body.signature.url |
47 | var magnetUris = pluck(req.body.data, 'magnetUri') | 46 | var magnetUris = pluck(req.body.data, 'magnetUri') |
48 | 47 | ||
49 | videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) { | 48 | videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) { |
50 | if (err) return next(err) | 49 | if (err) return next(err) |
51 | 50 | ||
52 | res.sendStatus(204) | 51 | res.sendStatus(204) |
53 | }) | 52 | }) |
54 | } | 53 | } |
55 | })() | ||