]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos.ts
Make some fields optional when uploading a video
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos.ts
index 3cbf98312bb0a71c5658e76abb1c5d70f907647d..10625e41d450a16f3b9a2b64188a39e7a51ab588 100644 (file)
@@ -6,7 +6,6 @@ import {
   isVideoAbuseReasonValid,
   isVideoCategoryValid,
   isVideoDescriptionValid,
-  isVideoDurationValid,
   isVideoExist,
   isVideoFile,
   isVideoLanguageValid,
@@ -19,7 +18,7 @@ import {
 } from '../../helpers/custom-validators/videos'
 import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
 import { logger } from '../../helpers/logger'
-import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers'
+import { CONSTRAINTS_FIELDS } from '../../initializers'
 import { database as db } from '../../initializers/database'
 import { UserInstance } from '../../models/account/user-interface'
 import { VideoInstance } from '../../models/video/video-interface'
@@ -32,11 +31,11 @@ const videosAddValidator = [
     + CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ')
   ),
   body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
-  body('category').custom(isVideoCategoryValid).withMessage('Should have a valid category'),
-  body('licence').custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
+  body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'),
+  body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
   body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'),
   body('nsfw').custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'),
-  body('description').custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
+  body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
   body('channelId').custom(isIdValid).withMessage('Should have correct video channel id'),
   body('privacy').custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
   body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'),
@@ -82,14 +81,6 @@ const videosAddValidator = [
       return
     }
 
-    if (!isVideoDurationValid('' + duration)) {
-      return res.status(400)
-                .json({
-                  error: 'Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).'
-                })
-                .end()
-    }
-
     videoFile['duration'] = duration
 
     return next()
@@ -181,8 +172,7 @@ const videosRemoveValidator = [
 ]
 
 const videosSearchValidator = [
-  param('value').not().isEmpty().withMessage('Should have a valid search'),
-  query('field').optional().isIn(SEARCHABLE_COLUMNS.VIDEOS).withMessage('Should have correct searchable column'),
+  query('search').not().isEmpty().withMessage('Should have a valid search'),
 
   (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking videosSearch parameters', { parameters: req.params })
@@ -231,7 +221,7 @@ const videosShareValidator = [
     if (areValidationErrors(req, res)) return
     if (!await isVideoExist(req.params.id, res)) return
 
-    const share = await db.VideoShare.load(req.params.accountId, res.locals.video.id)
+    const share = await db.VideoShare.load(req.params.accountId, res.locals.video.id, undefined)
     if (!share) {
       return res.status(404)
         .end()