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