aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/videos.js')
-rw-r--r--server/middlewares/validators/videos.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js
index 3e2af06fb..76e943e77 100644
--- a/server/middlewares/validators/videos.js
+++ b/server/middlewares/validators/videos.js
@@ -4,20 +4,21 @@ const mongoose = require('mongoose')
4 4
5const checkErrors = require('./utils').checkErrors 5const checkErrors = require('./utils').checkErrors
6const constants = require('../../initializers/constants') 6const constants = require('../../initializers/constants')
7const customValidators = require('../../helpers/custom-validators') 7const customVideosValidators = require('../../helpers/custom-validators').videos
8const logger = require('../../helpers/logger') 8const logger = require('../../helpers/logger')
9 9
10const Video = mongoose.model('Video') 10const Video = mongoose.model('Video')
11 11
12const validatorsVideos = { 12const validatorsVideos = {
13 videosAdd: videosAdd, 13 videosAdd,
14 videosGet: videosGet, 14 videosGet,
15 videosRemove: videosRemove, 15 videosRemove,
16 videosSearch: videosSearch 16 videosSearch
17} 17}
18 18
19function videosAdd (req, res, next) { 19function videosAdd (req, res, next) {
20 req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty() 20 req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty()
21 // TODO: move to constants and function
21 req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) 22 req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
22 req.checkBody('name', 'Should have a valid name').isVideoNameValid() 23 req.checkBody('name', 'Should have a valid name').isVideoNameValid()
23 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() 24 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
@@ -33,8 +34,8 @@ function videosAdd (req, res, next) {
33 return res.status(400).send('Cannot retrieve metadata of the file.') 34 return res.status(400).send('Cannot retrieve metadata of the file.')
34 } 35 }
35 36
36 if (!customValidators.isVideoDurationValid(duration)) { 37 if (!customVideosValidators.isVideoDurationValid(duration)) {
37 return res.status(400).send('Duration of the video file is too big (max: ' + constants.VIDEOS_CONSTRAINTS_FIELDS.DURATION.max + 's).') 38 return res.status(400).send('Duration of the video file is too big (max: ' + constants.CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).')
38 } 39 }
39 40
40 videoFile.duration = duration 41 videoFile.duration = duration
@@ -76,6 +77,7 @@ function videosRemove (req, res, next) {
76 77
77 if (!video) return res.status(404).send('Video not found') 78 if (!video) 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') 79 else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod')
80 else if (video.author !== res.locals.oauth.token.user.username) return res.status(403).send('Cannot remove video of another user')
79 81
80 next() 82 next()
81 }) 83 })