]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos.js
Server: split check params tests
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos.js
index 1b306d1cf038644f09f77adcacb37c35e14f9f13..35d6979e5ecd483daf72cb9302454a2f439e14ab 100644 (file)
@@ -200,7 +200,7 @@ function addVideo (req, res, next) {
 }
 
 function updateVideo (req, res, next) {
-  let videoInstance = res.locals.video
+  const videoInstance = res.locals.video
   const videoInfosToUpdate = req.body
 
   waterfall([
@@ -229,8 +229,6 @@ function updateVideo (req, res, next) {
 
       // Add tags association
       videoInstance.save(options).asCallback(function (err) {
-        if (err) return callback(err)
-
         return callback(err, t, tagInstances)
       })
     },
@@ -277,15 +275,8 @@ function updateVideo (req, res, next) {
 }
 
 function getVideo (req, res, next) {
-  db.Video.loadAndPopulateAuthorAndPodAndTags(req.params.id, function (err, video) {
-    if (err) return next(err)
-
-    if (!video) {
-      return res.type('json').status(204).end()
-    }
-
-    res.json(video.toFormatedJSON())
-  })
+  const videoInstance = res.locals.video
+  res.json(videoInstance.toFormatedJSON())
 }
 
 function listVideos (req, res, next) {
@@ -297,20 +288,9 @@ function listVideos (req, res, next) {
 }
 
 function removeVideo (req, res, next) {
-  const videoId = req.params.id
-
-  waterfall([
-    function loadVideo (callback) {
-      db.Video.load(videoId, function (err, video) {
-        return callback(err, video)
-      })
-    },
+  const videoInstance = res.locals.video
 
-    function deleteVideo (video, callback) {
-      // Informations to other pods will be sent by the afterDestroy video hook
-      video.destroy().asCallback(callback)
-    }
-  ], function andFinally (err) {
+  videoInstance.destroy().asCallback(function (err) {
     if (err) {
       logger.error('Errors when removed the video.', { error: err })
       return next(err)