aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/reqValidators/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/reqValidators/videos.js')
-rw-r--r--server/middlewares/reqValidators/videos.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/server/middlewares/reqValidators/videos.js b/server/middlewares/reqValidators/videos.js
index f31fd93a2..452fbc859 100644
--- a/server/middlewares/reqValidators/videos.js
+++ b/server/middlewares/reqValidators/videos.js
@@ -1,11 +1,13 @@
1'use strict' 1'use strict'
2 2
3const mongoose = require('mongoose')
4
3const checkErrors = require('./utils').checkErrors 5const checkErrors = require('./utils').checkErrors
4const constants = require('../../initializers/constants') 6const constants = require('../../initializers/constants')
5const customValidators = require('../../helpers/customValidators') 7const customValidators = require('../../helpers/customValidators')
6const logger = require('../../helpers/logger') 8const logger = require('../../helpers/logger')
7const videos = require('../../lib/videos') 9
8const Videos = require('../../models/videos') 10const Video = mongoose.model('Video')
9 11
10const reqValidatorsVideos = { 12const reqValidatorsVideos = {
11 videosAdd: videosAdd, 13 videosAdd: videosAdd,
@@ -26,7 +28,7 @@ function videosAdd (req, res, next) {
26 checkErrors(req, res, function () { 28 checkErrors(req, res, function () {
27 const videoFile = req.files.videofile[0] 29 const videoFile = req.files.videofile[0]
28 30
29 videos.getVideoDuration(videoFile.path, function (err, duration) { 31 Video.getDurationFromFile(videoFile.path, function (err, duration) {
30 if (err) { 32 if (err) {
31 return res.status(400).send('Cannot retrieve metadata of the file.') 33 return res.status(400).send('Cannot retrieve metadata of the file.')
32 } 34 }
@@ -47,14 +49,13 @@ function videosGet (req, res, next) {
47 logger.debug('Checking videosGet parameters', { parameters: req.params }) 49 logger.debug('Checking videosGet parameters', { parameters: req.params })
48 50
49 checkErrors(req, res, function () { 51 checkErrors(req, res, function () {
50 Videos.get(req.params.id, function (err, video) { 52 Video.load(req.params.id, function (err, video) {
51 if (err) { 53 if (err) {
52 logger.error('Error in videosGet request validator.', { error: err }) 54 logger.error('Error in videosGet request validator.', { error: err })
53 return res.sendStatus(500) 55 return res.sendStatus(500)
54 } 56 }
55 57
56 const state = videos.getVideoState(video) 58 if (!video) return res.status(404).send('Video not found')
57 if (state.exist === false) return res.status(404).send('Video not found')
58 59
59 next() 60 next()
60 }) 61 })
@@ -67,15 +68,14 @@ function videosRemove (req, res, next) {
67 logger.debug('Checking videosRemove parameters', { parameters: req.params }) 68 logger.debug('Checking videosRemove parameters', { parameters: req.params })
68 69
69 checkErrors(req, res, function () { 70 checkErrors(req, res, function () {
70 Videos.get(req.params.id, function (err, video) { 71 Video.load(req.params.id, function (err, video) {
71 if (err) { 72 if (err) {
72 logger.error('Error in videosRemove request validator.', { error: err }) 73 logger.error('Error in videosRemove request validator.', { error: err })
73 return res.sendStatus(500) 74 return res.sendStatus(500)
74 } 75 }
75 76
76 const state = videos.getVideoState(video) 77 if (!video) return res.status(404).send('Video not found')
77 if (state.exist === false) return res.status(404).send('Video not found') 78 else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod')
78 else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
79 79
80 next() 80 next()
81 }) 81 })