diff options
Diffstat (limited to 'server/controllers/api/v1/remoteVideos.js')
-rw-r--r-- | server/controllers/api/v1/remoteVideos.js | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/server/controllers/api/v1/remoteVideos.js b/server/controllers/api/v1/remoteVideos.js index 5e9e71fdd..8ff212b7f 100644 --- a/server/controllers/api/v1/remoteVideos.js +++ b/server/controllers/api/v1/remoteVideos.js | |||
@@ -7,7 +7,9 @@ const middleware = require('../../../middlewares') | |||
7 | const secureMiddleware = middleware.secure | 7 | const secureMiddleware = middleware.secure |
8 | const cacheMiddleware = middleware.cache | 8 | const cacheMiddleware = middleware.cache |
9 | const reqValidator = middleware.reqValidators.remote | 9 | const reqValidator = middleware.reqValidators.remote |
10 | const videos = require('../../../models/videos') | 10 | const logger = require('../../../helpers/logger') |
11 | const Videos = require('../../../models/videos') | ||
12 | const videos = require('../../../lib/videos') | ||
11 | 13 | ||
12 | const router = express.Router() | 14 | const router = express.Router() |
13 | 15 | ||
@@ -34,20 +36,34 @@ module.exports = router | |||
34 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |
35 | 37 | ||
36 | function addRemoteVideos (req, res, next) { | 38 | function addRemoteVideos (req, res, next) { |
37 | videos.addRemotes(req.body.data, function (err, videos) { | 39 | const videos_to_create = req.body.data |
38 | if (err) return next(err) | 40 | videos.createRemoteVideos(videos_to_create, function (err, remote_videos) { |
41 | if (err) { | ||
42 | logger.error('Cannot create remote videos.', { error: err }) | ||
43 | return next(err) | ||
44 | } | ||
39 | 45 | ||
40 | res.json(videos) | 46 | res.type('json').status(201).end() |
41 | }) | 47 | }) |
42 | } | 48 | } |
43 | 49 | ||
44 | function removeRemoteVideo (req, res, next) { | 50 | function removeRemoteVideo (req, res, next) { |
45 | const url = req.body.signature.url | 51 | const fromUrl = req.body.signature.url |
46 | const magnetUris = map(req.body.data, 'magnetUri') | 52 | const magnetUris = map(req.body.data, 'magnetUri') |
47 | 53 | ||
48 | videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) { | 54 | Videos.listFromUrlAndMagnets(fromUrl, magnetUris, function (err, videos_list) { |
49 | if (err) return next(err) | 55 | if (err) { |
56 | logger.error('Cannot list videos from url and magnets.', { error: err }) | ||
57 | return next(err) | ||
58 | } | ||
50 | 59 | ||
51 | res.type('json').status(204).end() | 60 | videos.removeRemoteVideos(videos_list, function (err) { |
61 | if (err) { | ||
62 | logger.error('Cannot remove remote videos.', { error: err }) | ||
63 | return next(err) | ||
64 | } | ||
65 | |||
66 | res.type('json').status(204).end() | ||
67 | }) | ||
52 | }) | 68 | }) |
53 | } | 69 | } |