diff options
Diffstat (limited to 'server/middlewares/reqValidators/videos.js')
-rw-r--r-- | server/middlewares/reqValidators/videos.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/server/middlewares/reqValidators/videos.js b/server/middlewares/reqValidators/videos.js index 10b6d39c6..3618e4716 100644 --- a/server/middlewares/reqValidators/videos.js +++ b/server/middlewares/reqValidators/videos.js | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | const checkErrors = require('./utils').checkErrors | 3 | const checkErrors = require('./utils').checkErrors |
4 | const constants = require('../../initializers/constants') | 4 | const constants = require('../../initializers/constants') |
5 | const customValidators = require('../../helpers/customValidators') | ||
5 | const logger = require('../../helpers/logger') | 6 | const logger = require('../../helpers/logger') |
6 | const videos = require('../../lib/videos') | 7 | const videos = require('../../lib/videos') |
7 | const Videos = require('../../models/videos') | 8 | const Videos = require('../../models/videos') |
@@ -16,8 +17,9 @@ const reqValidatorsVideos = { | |||
16 | function videosAdd (req, res, next) { | 17 | function videosAdd (req, res, next) { |
17 | req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty() | 18 | req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty() |
18 | req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) | 19 | req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) |
19 | req.checkBody('name', 'Should have a name').isLength(1, 50) | 20 | req.checkBody('name', 'Should have a valid name').isVideoNameValid() |
20 | req.checkBody('description', 'Should have a description').isLength(1, 250) | 21 | req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() |
22 | req.checkBody('tags', 'Should have correct tags').isVideoTagsValid() | ||
21 | 23 | ||
22 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) | 24 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) |
23 | 25 | ||
@@ -29,7 +31,7 @@ function videosAdd (req, res, next) { | |||
29 | return res.status(400).send('Cannot retrieve metadata of the file.') | 31 | return res.status(400).send('Cannot retrieve metadata of the file.') |
30 | } | 32 | } |
31 | 33 | ||
32 | if (duration > constants.MAXIMUM_VIDEO_DURATION) { | 34 | if (!customValidators.isVideoDurationValid(duration)) { |
33 | return res.status(400).send('Duration of the video file is too big (max: ' + constants.MAXIMUM_VIDEO_DURATION + 's).') | 35 | return res.status(400).send('Duration of the video file is too big (max: ' + constants.MAXIMUM_VIDEO_DURATION + 's).') |
34 | } | 36 | } |
35 | 37 | ||
@@ -48,7 +50,7 @@ function videosGet (req, res, next) { | |||
48 | Videos.get(req.params.id, function (err, video) { | 50 | Videos.get(req.params.id, function (err, video) { |
49 | if (err) { | 51 | if (err) { |
50 | logger.error('Error in videosGet request validator.', { error: err }) | 52 | logger.error('Error in videosGet request validator.', { error: err }) |
51 | res.sendStatus(500) | 53 | return res.sendStatus(500) |
52 | } | 54 | } |
53 | 55 | ||
54 | const state = videos.getVideoState(video) | 56 | const state = videos.getVideoState(video) |
@@ -68,7 +70,7 @@ function videosRemove (req, res, next) { | |||
68 | Videos.get(req.params.id, function (err, video) { | 70 | Videos.get(req.params.id, function (err, video) { |
69 | if (err) { | 71 | if (err) { |
70 | logger.error('Error in videosRemove request validator.', { error: err }) | 72 | logger.error('Error in videosRemove request validator.', { error: err }) |
71 | res.sendStatus(500) | 73 | return res.sendStatus(500) |
72 | } | 74 | } |
73 | 75 | ||
74 | const state = videos.getVideoState(video) | 76 | const state = videos.getVideoState(video) |
@@ -82,7 +84,7 @@ function videosRemove (req, res, next) { | |||
82 | 84 | ||
83 | function videosSearch (req, res, next) { | 85 | function videosSearch (req, res, next) { |
84 | const searchableColumns = constants.SEARCHABLE_COLUMNS.VIDEOS | 86 | const searchableColumns = constants.SEARCHABLE_COLUMNS.VIDEOS |
85 | req.checkParams('value', 'Should have a name').notEmpty() | 87 | req.checkParams('value', 'Should have a valid search').notEmpty() |
86 | req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns) | 88 | req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns) |
87 | 89 | ||
88 | logger.debug('Checking videosSearch parameters', { parameters: req.params }) | 90 | logger.debug('Checking videosSearch parameters', { parameters: req.params }) |