]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos.js
Server: add nsfw attribute
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos.js
index 4fe6dcd8b3e81cfbae3c5f7f47ca176d2f6419ec..095fc382b61c984cc4af677131dff50c46f0870b 100644 (file)
@@ -13,16 +13,19 @@ const validatorsVideos = {
   videosRemove,
   videosSearch,
 
-  videoAbuseReport
+  videoAbuseReport,
+
+  videoRate
 }
 
 function videosAdd (req, res, next) {
-  req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty()
-  // TODO: move to constants and function
-  req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
+  req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
   req.checkBody('name', 'Should have a valid name').isVideoNameValid()
+  req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
+  req.checkBody('licence', 'Should have a valid licence').isVideoLicenceValid()
+  req.checkBody('nsfw', 'Should have a valid NSFW attribute').isVideoNSFWValid()
   req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
-  req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
+  req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
 
   logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
 
@@ -47,6 +50,9 @@ function videosAdd (req, res, next) {
 function videosUpdate (req, res, next) {
   req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
   req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
+  req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid()
+  req.checkBody('licence', 'Should have a valid licence').optional().isVideoLicenceValid()
+  req.checkBody('nsfw', 'Should have a valid NSFW attribute').optional().isVideoNSFWValid()
   req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid()
   req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
 
@@ -121,6 +127,17 @@ function videoAbuseReport (req, res, next) {
   })
 }
 
+function videoRate (req, res, next) {
+  req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
+  req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid()
+
+  logger.debug('Checking videoRate parameters', { parameters: req.body })
+
+  checkErrors(req, res, function () {
+    checkVideoExists(req.params.id, res, next)
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 module.exports = validatorsVideos