diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-05-31 20:46:22 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2021-05-31 20:47:59 +0200 |
commit | 7dab0bd698ba1d78995b58325d0dd78257278582 (patch) | |
tree | 063c71c1f1e7a0766f915acdde6c393977358aef /server/middlewares/validators | |
parent | 70330f63236a3200829f2ba76c10cca88326b858 (diff) | |
download | PeerTube-7dab0bd698ba1d78995b58325d0dd78257278582.tar.gz PeerTube-7dab0bd698ba1d78995b58325d0dd78257278582.tar.zst PeerTube-7dab0bd698ba1d78995b58325d0dd78257278582.zip |
improve api param message for video names and tags
closes #4026
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/videos/video-imports.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-live.ts | 5 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 20 |
3 files changed, 21 insertions, 8 deletions
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index d0643ff26..a5e3ffbcd 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -33,7 +33,9 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | |||
33 | ), | 33 | ), |
34 | body('name') | 34 | body('name') |
35 | .optional() | 35 | .optional() |
36 | .custom(isVideoNameValid).withMessage('Should have a valid name'), | 36 | .custom(isVideoNameValid).withMessage( |
37 | `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long` | ||
38 | ), | ||
37 | 39 | ||
38 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 40 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
39 | logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body }) | 41 | logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body }) |
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts index 3a73e1272..ec4c7f32f 100644 --- a/server/middlewares/validators/videos/video-live.ts +++ b/server/middlewares/validators/videos/video-live.ts | |||
@@ -14,6 +14,7 @@ import { VideoModel } from '@server/models/video/video' | |||
14 | import { Hooks } from '@server/lib/plugins/hooks' | 14 | import { Hooks } from '@server/lib/plugins/hooks' |
15 | import { isLocalLiveVideoAccepted } from '@server/lib/moderation' | 15 | import { isLocalLiveVideoAccepted } from '@server/lib/moderation' |
16 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 16 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
17 | import { CONSTRAINTS_FIELDS } from '@server/initializers/constants' | ||
17 | 18 | ||
18 | const videoLiveGetValidator = [ | 19 | const videoLiveGetValidator = [ |
19 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 20 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
@@ -43,7 +44,9 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ | |||
43 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 44 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
44 | 45 | ||
45 | body('name') | 46 | body('name') |
46 | .custom(isVideoNameValid).withMessage('Should have a valid name'), | 47 | .custom(isVideoNameValid).withMessage( |
48 | `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long` | ||
49 | ), | ||
47 | 50 | ||
48 | body('saveReplay') | 51 | body('saveReplay') |
49 | .optional() | 52 | .optional() |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index dce02df18..8864be269 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -65,8 +65,9 @@ const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([ | |||
65 | .withMessage('Should have a file'), | 65 | .withMessage('Should have a file'), |
66 | body('name') | 66 | body('name') |
67 | .trim() | 67 | .trim() |
68 | .custom(isVideoNameValid) | 68 | .custom(isVideoNameValid).withMessage( |
69 | .withMessage('Should have a valid name'), | 69 | `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long` |
70 | ), | ||
70 | body('channelId') | 71 | body('channelId') |
71 | .customSanitizer(toIntOrNull) | 72 | .customSanitizer(toIntOrNull) |
72 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 73 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
@@ -146,8 +147,9 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ | |||
146 | .withMessage('Should have a valid filename'), | 147 | .withMessage('Should have a valid filename'), |
147 | body('name') | 148 | body('name') |
148 | .trim() | 149 | .trim() |
149 | .custom(isVideoNameValid) | 150 | .custom(isVideoNameValid).withMessage( |
150 | .withMessage('Should have a valid name'), | 151 | `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long` |
152 | ), | ||
151 | body('channelId') | 153 | body('channelId') |
152 | .customSanitizer(toIntOrNull) | 154 | .customSanitizer(toIntOrNull) |
153 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 155 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
@@ -196,7 +198,9 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ | |||
196 | body('name') | 198 | body('name') |
197 | .optional() | 199 | .optional() |
198 | .trim() | 200 | .trim() |
199 | .custom(isVideoNameValid).withMessage('Should have a valid name'), | 201 | .custom(isVideoNameValid).withMessage( |
202 | `Should have a video name between ${CONSTRAINTS_FIELDS.VIDEOS.NAME.min} and ${CONSTRAINTS_FIELDS.VIDEOS.NAME.max} characters long` | ||
203 | ), | ||
200 | body('channelId') | 204 | body('channelId') |
201 | .optional() | 205 | .optional() |
202 | .customSanitizer(toIntOrNull) | 206 | .customSanitizer(toIntOrNull) |
@@ -455,7 +459,11 @@ function getCommonVideoEditAttributes () { | |||
455 | body('tags') | 459 | body('tags') |
456 | .optional() | 460 | .optional() |
457 | .customSanitizer(toValueOrNull) | 461 | .customSanitizer(toValueOrNull) |
458 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), | 462 | .custom(isVideoTagsValid) |
463 | .withMessage( | ||
464 | `Should have an array of up to ${CONSTRAINTS_FIELDS.VIDEOS.TAGS.max} tags between ` + | ||
465 | `${CONSTRAINTS_FIELDS.VIDEOS.TAG.min} and ${CONSTRAINTS_FIELDS.VIDEOS.TAG.max} characters each` | ||
466 | ), | ||
459 | body('commentsEnabled') | 467 | body('commentsEnabled') |
460 | .optional() | 468 | .optional() |
461 | .customSanitizer(toBooleanOrNull) | 469 | .customSanitizer(toBooleanOrNull) |