diff options
Diffstat (limited to 'server/controllers/api/v1/remoteVideos.js')
-rw-r--r-- | server/controllers/api/v1/remoteVideos.js | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/server/controllers/api/v1/remoteVideos.js b/server/controllers/api/v1/remoteVideos.js deleted file mode 100644 index 2f41c0411..000000000 --- a/server/controllers/api/v1/remoteVideos.js +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const express = require('express') | ||
4 | const map = require('lodash/map') | ||
5 | |||
6 | const middlewares = require('../../../middlewares') | ||
7 | const secureMiddleware = middlewares.secure | ||
8 | const reqValidator = middlewares.reqValidators.remote | ||
9 | const logger = require('../../../helpers/logger') | ||
10 | const Videos = require('../../../models/videos') | ||
11 | const videos = require('../../../lib/videos') | ||
12 | |||
13 | const router = express.Router() | ||
14 | |||
15 | router.post('/add', | ||
16 | reqValidator.secureRequest, | ||
17 | secureMiddleware.decryptBody, | ||
18 | reqValidator.remoteVideosAdd, | ||
19 | addRemoteVideos | ||
20 | ) | ||
21 | |||
22 | router.post('/remove', | ||
23 | reqValidator.secureRequest, | ||
24 | secureMiddleware.decryptBody, | ||
25 | reqValidator.remoteVideosRemove, | ||
26 | removeRemoteVideo | ||
27 | ) | ||
28 | |||
29 | // --------------------------------------------------------------------------- | ||
30 | |||
31 | module.exports = router | ||
32 | |||
33 | // --------------------------------------------------------------------------- | ||
34 | |||
35 | function addRemoteVideos (req, res, next) { | ||
36 | const videosToCreate = req.body.data | ||
37 | videos.createRemoteVideos(videosToCreate, function (err, remoteVideos) { | ||
38 | if (err) { | ||
39 | logger.error('Cannot create remote videos.', { error: err }) | ||
40 | return next(err) | ||
41 | } | ||
42 | |||
43 | res.type('json').status(201).end() | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | function removeRemoteVideo (req, res, next) { | ||
48 | const fromUrl = req.body.signature.url | ||
49 | const magnetUris = map(req.body.data, 'magnetUri') | ||
50 | |||
51 | Videos.listFromUrlAndMagnets(fromUrl, magnetUris, function (err, videosList) { | ||
52 | if (err) { | ||
53 | logger.error('Cannot list videos from url and magnets.', { error: err }) | ||
54 | return next(err) | ||
55 | } | ||
56 | |||
57 | videos.removeRemoteVideos(videosList, function (err) { | ||
58 | if (err) { | ||
59 | logger.error('Cannot remove remote videos.', { error: err }) | ||
60 | return next(err) | ||
61 | } | ||
62 | |||
63 | res.type('json').status(204).end() | ||
64 | }) | ||
65 | }) | ||
66 | } | ||