]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
improve api param message for video names and tags
authorRigel Kent <sendmemail@rigelk.eu>
Mon, 31 May 2021 18:46:22 +0000 (20:46 +0200)
committerRigel Kent <sendmemail@rigelk.eu>
Mon, 31 May 2021 18:47:59 +0000 (20:47 +0200)
closes #4026

server/middlewares/validators/videos/video-imports.ts
server/middlewares/validators/videos/video-live.ts
server/middlewares/validators/videos/videos.ts

index d0643ff26e8935648913643ef5c0b5a9330a25f7..a5e3ffbcd8a00b714c08f0f32ad6de0cb427c211 100644 (file)
@@ -33,7 +33,9 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
     ),
   body('name')
     .optional()
-    .custom(isVideoNameValid).withMessage('Should have a valid name'),
+    .custom(isVideoNameValid).withMessage(
+      `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long`
+    ),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body })
index 3a73e12725b1b13fd5b684d712d6a04c36875f99..ec4c7f32f4624de8beba7762c6cf1efe87163e6c 100644 (file)
@@ -14,6 +14,7 @@ import { VideoModel } from '@server/models/video/video'
 import { Hooks } from '@server/lib/plugins/hooks'
 import { isLocalLiveVideoAccepted } from '@server/lib/moderation'
 import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
+import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
 
 const videoLiveGetValidator = [
   param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
@@ -43,7 +44,9 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
     .custom(isIdValid).withMessage('Should have correct video channel id'),
 
   body('name')
-    .custom(isVideoNameValid).withMessage('Should have a valid name'),
+    .custom(isVideoNameValid).withMessage(
+      `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long`
+    ),
 
   body('saveReplay')
     .optional()
index dce02df18adcd46ea6c6f5cfca167ba045b65923..8864be2692674826baad9e6d8df4dae3969379ec 100644 (file)
@@ -65,8 +65,9 @@ const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([
     .withMessage('Should have a file'),
   body('name')
     .trim()
-    .custom(isVideoNameValid)
-    .withMessage('Should have a valid name'),
+    .custom(isVideoNameValid).withMessage(
+      `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long`
+    ),
   body('channelId')
     .customSanitizer(toIntOrNull)
     .custom(isIdValid).withMessage('Should have correct video channel id'),
@@ -146,8 +147,9 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([
     .withMessage('Should have a valid filename'),
   body('name')
     .trim()
-    .custom(isVideoNameValid)
-    .withMessage('Should have a valid name'),
+    .custom(isVideoNameValid).withMessage(
+      `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long`
+    ),
   body('channelId')
     .customSanitizer(toIntOrNull)
     .custom(isIdValid).withMessage('Should have correct video channel id'),
@@ -196,7 +198,9 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([
   body('name')
     .optional()
     .trim()
-    .custom(isVideoNameValid).withMessage('Should have a valid name'),
+    .custom(isVideoNameValid).withMessage(
+      `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long`
+    ),
   body('channelId')
     .optional()
     .customSanitizer(toIntOrNull)
@@ -455,7 +459,11 @@ function getCommonVideoEditAttributes () {
     body('tags')
       .optional()
       .customSanitizer(toValueOrNull)
-      .custom(isVideoTagsValid).withMessage('Should have correct tags'),
+      .custom(isVideoTagsValid)
+      .withMessage(
+        `Should have an array of up to ${CONSTRAINTS_FIELDS.VIDEOS.TAGS.max} tags between ` +
+        `${CONSTRAINTS_FIELDS.VIDEOS.TAG.min} and ${CONSTRAINTS_FIELDS.VIDEOS.TAG.max} characters each`
+      ),
     body('commentsEnabled')
       .optional()
       .customSanitizer(toBooleanOrNull)