]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/reqValidators/videos.js
Add tags support to server
[github/Chocobozzz/PeerTube.git] / server / middlewares / reqValidators / videos.js
index d444c9f0abd8b11dba3f308d2727dfc953595ead..3618e47160bf9f6397de4532aa2155f4ff04b56c 100644 (file)
@@ -2,6 +2,7 @@
 
 const checkErrors = require('./utils').checkErrors
 const constants = require('../../initializers/constants')
+const customValidators = require('../../helpers/customValidators')
 const logger = require('../../helpers/logger')
 const videos = require('../../lib/videos')
 const Videos = require('../../models/videos')
@@ -16,8 +17,9 @@ const reqValidatorsVideos = {
 function videosAdd (req, res, next) {
   req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty()
   req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
-  req.checkBody('name', 'Should have a name').isLength(1, 50)
-  req.checkBody('description', 'Should have a description').isLength(1, 250)
+  req.checkBody('name', 'Should have a valid name').isVideoNameValid()
+  req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
+  req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
 
   logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
 
@@ -29,8 +31,8 @@ function videosAdd (req, res, next) {
         return res.status(400).send('Cannot retrieve metadata of the file.')
       }
 
-      if (duration > constants.MAXIMUM_VIDEO_DURATION) {
-        return res.status(400).send('Duration of the video file is too big (' + constants.MAXIMUM_VIDEO_DURATION + ').')
+      if (!customValidators.isVideoDurationValid(duration)) {
+        return res.status(400).send('Duration of the video file is too big (max: ' + constants.MAXIMUM_VIDEO_DURATION + 's).')
       }
 
       videoFile.duration = duration
@@ -48,7 +50,7 @@ function videosGet (req, res, next) {
     Videos.get(req.params.id, function (err, video) {
       if (err) {
         logger.error('Error in videosGet request validator.', { error: err })
-        res.sendStatus(500)
+        return res.sendStatus(500)
       }
 
       const state = videos.getVideoState(video)
@@ -68,7 +70,7 @@ function videosRemove (req, res, next) {
     Videos.get(req.params.id, function (err, video) {
       if (err) {
         logger.error('Error in videosRemove request validator.', { error: err })
-        res.sendStatus(500)
+        return res.sendStatus(500)
       }
 
       const state = videos.getVideoState(video)
@@ -82,7 +84,7 @@ function videosRemove (req, res, next) {
 
 function videosSearch (req, res, next) {
   const searchableColumns = constants.SEARCHABLE_COLUMNS.VIDEOS
-  req.checkParams('value', 'Should have a name').notEmpty()
+  req.checkParams('value', 'Should have a valid search').notEmpty()
   req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns)
 
   logger.debug('Checking videosSearch parameters', { parameters: req.params })