aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/reqValidators/videos.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/server/middlewares/reqValidators/videos.js b/server/middlewares/reqValidators/videos.js
index 4e5f4391f..b0a6d0360 100644
--- a/server/middlewares/reqValidators/videos.js
+++ b/server/middlewares/reqValidators/videos.js
@@ -2,6 +2,7 @@
2 2
3var checkErrors = require('./utils').checkErrors 3var checkErrors = require('./utils').checkErrors
4var logger = require('../../helpers/logger') 4var logger = require('../../helpers/logger')
5var videos = require('../../lib/videos')
5var Videos = require('../../models/videos') 6var Videos = require('../../models/videos')
6 7
7var reqValidatorsVideos = { 8var reqValidatorsVideos = {
@@ -28,15 +29,17 @@ function videosGet (req, res, next) {
28 logger.debug('Checking videosGet parameters', { parameters: req.params }) 29 logger.debug('Checking videosGet parameters', { parameters: req.params })
29 30
30 checkErrors(req, res, function () { 31 checkErrors(req, res, function () {
31 Videos.getVideoState(req.params.id, function (err, state) { 32 Videos.get(req.params.id, function (err, video) {
32 if (err) { 33 if (err) {
33 logger.error('Error in videosGet request validator.', { error: err }) 34 logger.error('Error in videosGet request validator.', { error: err })
34 res.sendStatus(500) 35 res.sendStatus(500)
35 } 36 }
36 37
37 if (state.exist === false) return res.status(404).send('Video not found') 38 videos.getVideoState(video, function (state) {
39 if (state.exist === false) return res.status(404).send('Video not found')
38 40
39 next() 41 next()
42 })
40 }) 43 })
41 }) 44 })
42} 45}
@@ -47,16 +50,18 @@ function videosRemove (req, res, next) {
47 logger.debug('Checking videosRemove parameters', { parameters: req.params }) 50 logger.debug('Checking videosRemove parameters', { parameters: req.params })
48 51
49 checkErrors(req, res, function () { 52 checkErrors(req, res, function () {
50 Videos.getVideoState(req.params.id, function (err, state) { 53 Videos.get(req.params.id, function (err, video) {
51 if (err) { 54 if (err) {
52 logger.error('Error in videosRemove request validator.', { error: err }) 55 logger.error('Error in videosRemove request validator.', { error: err })
53 res.sendStatus(500) 56 res.sendStatus(500)
54 } 57 }
55 58
56 if (state.exist === false) return res.status(404).send('Video not found') 59 videos.getVideoState(video, function (state) {
57 else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod') 60 if (state.exist === false) return res.status(404).send('Video not found')
61 else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
58 62
59 next() 63 next()
64 })
60 }) 65 })
61 }) 66 })
62} 67}