aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/remoteVideos.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-10 21:19:24 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-10 21:19:24 +0200
commitcbe2f7c34822b1bd3b1f8c691f79f0c29cf21f07 (patch)
treece678124210db8b03b2a523e3b92a14cc403eeee /server/controllers/api/v1/remoteVideos.js
parentf1dae018681936b556b2496b7f2d872c004cfda3 (diff)
downloadPeerTube-cbe2f7c34822b1bd3b1f8c691f79f0c29cf21f07.tar.gz
PeerTube-cbe2f7c34822b1bd3b1f8c691f79f0c29cf21f07.tar.zst
PeerTube-cbe2f7c34822b1bd3b1f8c691f79f0c29cf21f07.zip
Refractoring and add thumbnails support (without tests)
Diffstat (limited to 'server/controllers/api/v1/remoteVideos.js')
-rw-r--r--server/controllers/api/v1/remoteVideos.js32
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')
7const secureMiddleware = middleware.secure 7const secureMiddleware = middleware.secure
8const cacheMiddleware = middleware.cache 8const cacheMiddleware = middleware.cache
9const reqValidator = middleware.reqValidators.remote 9const reqValidator = middleware.reqValidators.remote
10const videos = require('../../../models/videos') 10const logger = require('../../../helpers/logger')
11const Videos = require('../../../models/videos')
12const videos = require('../../../lib/videos')
11 13
12const router = express.Router() 14const router = express.Router()
13 15
@@ -34,20 +36,34 @@ module.exports = router
34// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
35 37
36function addRemoteVideos (req, res, next) { 38function 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
44function removeRemoteVideo (req, res, next) { 50function 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}