diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/videos.js | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index e5c52a87b..35d6979e5 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js | |||
@@ -200,7 +200,7 @@ function addVideo (req, res, next) { | |||
200 | } | 200 | } |
201 | 201 | ||
202 | function updateVideo (req, res, next) { | 202 | function updateVideo (req, res, next) { |
203 | let videoInstance = res.locals.video | 203 | const videoInstance = res.locals.video |
204 | const videoInfosToUpdate = req.body | 204 | const videoInfosToUpdate = req.body |
205 | 205 | ||
206 | waterfall([ | 206 | waterfall([ |
@@ -275,15 +275,8 @@ function updateVideo (req, res, next) { | |||
275 | } | 275 | } |
276 | 276 | ||
277 | function getVideo (req, res, next) { | 277 | function getVideo (req, res, next) { |
278 | db.Video.loadAndPopulateAuthorAndPodAndTags(req.params.id, function (err, video) { | 278 | const videoInstance = res.locals.video |
279 | if (err) return next(err) | 279 | res.json(videoInstance.toFormatedJSON()) |
280 | |||
281 | if (!video) { | ||
282 | return res.type('json').status(204).end() | ||
283 | } | ||
284 | |||
285 | res.json(video.toFormatedJSON()) | ||
286 | }) | ||
287 | } | 280 | } |
288 | 281 | ||
289 | function listVideos (req, res, next) { | 282 | function listVideos (req, res, next) { |
@@ -295,20 +288,9 @@ function listVideos (req, res, next) { | |||
295 | } | 288 | } |
296 | 289 | ||
297 | function removeVideo (req, res, next) { | 290 | function removeVideo (req, res, next) { |
298 | const videoId = req.params.id | 291 | const videoInstance = res.locals.video |
299 | 292 | ||
300 | waterfall([ | 293 | videoInstance.destroy().asCallback(function (err) { |
301 | function loadVideo (callback) { | ||
302 | db.Video.load(videoId, function (err, video) { | ||
303 | return callback(err, video) | ||
304 | }) | ||
305 | }, | ||
306 | |||
307 | function deleteVideo (video, callback) { | ||
308 | // Informations to other pods will be sent by the afterDestroy video hook | ||
309 | video.destroy().asCallback(callback) | ||
310 | } | ||
311 | ], function andFinally (err) { | ||
312 | if (err) { | 294 | if (err) { |
313 | logger.error('Errors when removed the video.', { error: err }) | 295 | logger.error('Errors when removed the video.', { error: err }) |
314 | return next(err) | 296 | return next(err) |