diff options
Diffstat (limited to 'controllers/api/v1/remoteVideos.js')
-rw-r--r-- | controllers/api/v1/remoteVideos.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/controllers/api/v1/remoteVideos.js b/controllers/api/v1/remoteVideos.js new file mode 100644 index 000000000..d534d6792 --- /dev/null +++ b/controllers/api/v1/remoteVideos.js | |||
@@ -0,0 +1,33 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var express = require('express') | ||
5 | var router = express.Router() | ||
6 | var pluck = require('lodash-node/compat/collection/pluck') | ||
7 | |||
8 | var middleware = require('../../../middlewares') | ||
9 | var miscMiddleware = middleware.misc | ||
10 | var reqValidator = middleware.reqValidators.remote | ||
11 | var videos = require('../../../models/videos') | ||
12 | |||
13 | function addRemoteVideos (req, res, next) { | ||
14 | videos.addRemotes(req.body.data, function (err, videos) { | ||
15 | if (err) return next(err) | ||
16 | |||
17 | res.json(videos) | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | function removeRemoteVideo (req, res, next) { | ||
22 | videos.removeRemotes(req.body.signature.url, pluck(req.body.data, 'magnetUri'), function (err) { | ||
23 | if (err) return next(err) | ||
24 | |||
25 | res.sendStatus(204) | ||
26 | }) | ||
27 | } | ||
28 | |||
29 | router.post('/add', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosAdd, miscMiddleware.cache(false), addRemoteVideos) | ||
30 | router.post('/remove', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosRemove, miscMiddleware.cache(false), removeRemoteVideo) | ||
31 | |||
32 | module.exports = router | ||
33 | })() | ||