]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/reqValidators/videos.js
Use const/let now we use node 4.2
[github/Chocobozzz/PeerTube.git] / server / middlewares / reqValidators / videos.js
index 4e5f4391fe44e645d69bdf2f7ea9766a33fac9d6..4057e72cd3a75996243b974740bf011386226170 100644 (file)
@@ -1,10 +1,11 @@
 'use strict'
 
-var checkErrors = require('./utils').checkErrors
-var logger = require('../../helpers/logger')
-var Videos = require('../../models/videos')
+const checkErrors = require('./utils').checkErrors
+const logger = require('../../helpers/logger')
+const videos = require('../../lib/videos')
+const Videos = require('../../models/videos')
 
-var reqValidatorsVideos = {
+const reqValidatorsVideos = {
   videosAdd: videosAdd,
   videosGet: videosGet,
   videosRemove: videosRemove,
@@ -28,15 +29,17 @@ function videosGet (req, res, next) {
   logger.debug('Checking videosGet parameters', { parameters: req.params })
 
   checkErrors(req, res, function () {
-    Videos.getVideoState(req.params.id, function (err, state) {
+    Videos.get(req.params.id, function (err, video) {
       if (err) {
         logger.error('Error in videosGet request validator.', { error: err })
         res.sendStatus(500)
       }
 
-      if (state.exist === false) return res.status(404).send('Video not found')
+      videos.getVideoState(video, function (state) {
+        if (state.exist === false) return res.status(404).send('Video not found')
 
-      next()
+        next()
+      })
     })
   })
 }
@@ -47,16 +50,18 @@ function videosRemove (req, res, next) {
   logger.debug('Checking videosRemove parameters', { parameters: req.params })
 
   checkErrors(req, res, function () {
-    Videos.getVideoState(req.params.id, function (err, state) {
+    Videos.get(req.params.id, function (err, video) {
       if (err) {
         logger.error('Error in videosRemove request validator.', { error: err })
         res.sendStatus(500)
       }
 
-      if (state.exist === false) return res.status(404).send('Video not found')
-      else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
+      videos.getVideoState(video, function (state) {
+        if (state.exist === false) return res.status(404).send('Video not found')
+        else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
 
-      next()
+        next()
+      })
     })
   })
 }