diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-17 14:27:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-17 14:27:04 +0200 |
commit | 396f6f0140b0f76162e2378fd5a61e2f888673ed (patch) | |
tree | a5bd668bfc7dca7f311b9fc42ebb8bd01f462648 /server/middlewares/validators/videos/videos.ts | |
parent | 97eba003a9d0adcb0cab9190f566327b1417c7d3 (diff) | |
download | PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.tar.gz PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.tar.zst PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.zip |
Cleanup useless express validator messages
Diffstat (limited to 'server/middlewares/validators/videos/videos.ts')
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index c6d31f8f0..5e8e25a9c 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -69,7 +69,7 @@ const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([ | |||
69 | ), | 69 | ), |
70 | body('channelId') | 70 | body('channelId') |
71 | .customSanitizer(toIntOrNull) | 71 | .customSanitizer(toIntOrNull) |
72 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 72 | .custom(isIdValid), |
73 | 73 | ||
74 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 74 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
75 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) | 75 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) |
@@ -167,9 +167,7 @@ const videosAddResumableValidator = [ | |||
167 | */ | 167 | */ |
168 | const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ | 168 | const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ |
169 | body('filename') | 169 | body('filename') |
170 | .isString() | 170 | .exists(), |
171 | .exists() | ||
172 | .withMessage('Should have a valid filename'), | ||
173 | body('name') | 171 | body('name') |
174 | .trim() | 172 | .trim() |
175 | .custom(isVideoNameValid).withMessage( | 173 | .custom(isVideoNameValid).withMessage( |
@@ -177,7 +175,7 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ | |||
177 | ), | 175 | ), |
178 | body('channelId') | 176 | body('channelId') |
179 | .customSanitizer(toIntOrNull) | 177 | .customSanitizer(toIntOrNull) |
180 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 178 | .custom(isIdValid), |
181 | 179 | ||
182 | header('x-upload-content-length') | 180 | header('x-upload-content-length') |
183 | .isNumeric() | 181 | .isNumeric() |
@@ -230,7 +228,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ | |||
230 | body('channelId') | 228 | body('channelId') |
231 | .optional() | 229 | .optional() |
232 | .customSanitizer(toIntOrNull) | 230 | .customSanitizer(toIntOrNull) |
233 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 231 | .custom(isIdValid), |
234 | 232 | ||
235 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 233 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
236 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) | 234 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) |
@@ -341,8 +339,7 @@ const videosRemoveValidator = [ | |||
341 | const videosOverviewValidator = [ | 339 | const videosOverviewValidator = [ |
342 | query('page') | 340 | query('page') |
343 | .optional() | 341 | .optional() |
344 | .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }) | 342 | .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }), |
345 | .withMessage('Should have a valid pagination'), | ||
346 | 343 | ||
347 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 344 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
348 | if (areValidationErrors(req, res)) return | 345 | if (areValidationErrors(req, res)) return |
@@ -367,35 +364,35 @@ function getCommonVideoEditAttributes () { | |||
367 | body('category') | 364 | body('category') |
368 | .optional() | 365 | .optional() |
369 | .customSanitizer(toIntOrNull) | 366 | .customSanitizer(toIntOrNull) |
370 | .custom(isVideoCategoryValid).withMessage('Should have a valid category'), | 367 | .custom(isVideoCategoryValid), |
371 | body('licence') | 368 | body('licence') |
372 | .optional() | 369 | .optional() |
373 | .customSanitizer(toIntOrNull) | 370 | .customSanitizer(toIntOrNull) |
374 | .custom(isVideoLicenceValid).withMessage('Should have a valid licence'), | 371 | .custom(isVideoLicenceValid), |
375 | body('language') | 372 | body('language') |
376 | .optional() | 373 | .optional() |
377 | .customSanitizer(toValueOrNull) | 374 | .customSanitizer(toValueOrNull) |
378 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 375 | .custom(isVideoLanguageValid), |
379 | body('nsfw') | 376 | body('nsfw') |
380 | .optional() | 377 | .optional() |
381 | .customSanitizer(toBooleanOrNull) | 378 | .customSanitizer(toBooleanOrNull) |
382 | .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), | 379 | .custom(isBooleanValid).withMessage('Should have a valid nsfw boolean'), |
383 | body('waitTranscoding') | 380 | body('waitTranscoding') |
384 | .optional() | 381 | .optional() |
385 | .customSanitizer(toBooleanOrNull) | 382 | .customSanitizer(toBooleanOrNull) |
386 | .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), | 383 | .custom(isBooleanValid).withMessage('Should have a valid waitTranscoding boolean'), |
387 | body('privacy') | 384 | body('privacy') |
388 | .optional() | 385 | .optional() |
389 | .customSanitizer(toValueOrNull) | 386 | .customSanitizer(toValueOrNull) |
390 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), | 387 | .custom(isVideoPrivacyValid), |
391 | body('description') | 388 | body('description') |
392 | .optional() | 389 | .optional() |
393 | .customSanitizer(toValueOrNull) | 390 | .customSanitizer(toValueOrNull) |
394 | .custom(isVideoDescriptionValid).withMessage('Should have a valid description'), | 391 | .custom(isVideoDescriptionValid), |
395 | body('support') | 392 | body('support') |
396 | .optional() | 393 | .optional() |
397 | .customSanitizer(toValueOrNull) | 394 | .customSanitizer(toValueOrNull) |
398 | .custom(isVideoSupportValid).withMessage('Should have a valid support text'), | 395 | .custom(isVideoSupportValid), |
399 | body('tags') | 396 | body('tags') |
400 | .optional() | 397 | .optional() |
401 | .customSanitizer(toValueOrNull) | 398 | .customSanitizer(toValueOrNull) |
@@ -407,15 +404,15 @@ function getCommonVideoEditAttributes () { | |||
407 | body('commentsEnabled') | 404 | body('commentsEnabled') |
408 | .optional() | 405 | .optional() |
409 | .customSanitizer(toBooleanOrNull) | 406 | .customSanitizer(toBooleanOrNull) |
410 | .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), | 407 | .custom(isBooleanValid).withMessage('Should have commentsEnabled boolean'), |
411 | body('downloadEnabled') | 408 | body('downloadEnabled') |
412 | .optional() | 409 | .optional() |
413 | .customSanitizer(toBooleanOrNull) | 410 | .customSanitizer(toBooleanOrNull) |
414 | .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), | 411 | .custom(isBooleanValid).withMessage('Should have downloadEnabled boolean'), |
415 | body('originallyPublishedAt') | 412 | body('originallyPublishedAt') |
416 | .optional() | 413 | .optional() |
417 | .customSanitizer(toValueOrNull) | 414 | .customSanitizer(toValueOrNull) |
418 | .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), | 415 | .custom(isVideoOriginallyPublishedAtValid), |
419 | body('scheduleUpdate') | 416 | body('scheduleUpdate') |
420 | .optional() | 417 | .optional() |
421 | .customSanitizer(toValueOrNull), | 418 | .customSanitizer(toValueOrNull), |
@@ -425,7 +422,7 @@ function getCommonVideoEditAttributes () { | |||
425 | body('scheduleUpdate.privacy') | 422 | body('scheduleUpdate.privacy') |
426 | .optional() | 423 | .optional() |
427 | .customSanitizer(toIntOrNull) | 424 | .customSanitizer(toIntOrNull) |
428 | .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') | 425 | .custom(isScheduleVideoUpdatePrivacyValid) |
429 | ] as (ValidationChain | ExpressPromiseHandler)[] | 426 | ] as (ValidationChain | ExpressPromiseHandler)[] |
430 | } | 427 | } |
431 | 428 | ||
@@ -433,59 +430,59 @@ const commonVideosFiltersValidator = [ | |||
433 | query('categoryOneOf') | 430 | query('categoryOneOf') |
434 | .optional() | 431 | .optional() |
435 | .customSanitizer(toArray) | 432 | .customSanitizer(toArray) |
436 | .custom(isNumberArray).withMessage('Should have a valid one of category array'), | 433 | .custom(isNumberArray).withMessage('Should have a valid categoryOneOf array'), |
437 | query('licenceOneOf') | 434 | query('licenceOneOf') |
438 | .optional() | 435 | .optional() |
439 | .customSanitizer(toArray) | 436 | .customSanitizer(toArray) |
440 | .custom(isNumberArray).withMessage('Should have a valid one of licence array'), | 437 | .custom(isNumberArray).withMessage('Should have a valid licenceOneOf array'), |
441 | query('languageOneOf') | 438 | query('languageOneOf') |
442 | .optional() | 439 | .optional() |
443 | .customSanitizer(toArray) | 440 | .customSanitizer(toArray) |
444 | .custom(isStringArray).withMessage('Should have a valid one of language array'), | 441 | .custom(isStringArray).withMessage('Should have a valid languageOneOf array'), |
445 | query('privacyOneOf') | 442 | query('privacyOneOf') |
446 | .optional() | 443 | .optional() |
447 | .customSanitizer(toArray) | 444 | .customSanitizer(toArray) |
448 | .custom(isNumberArray).withMessage('Should have a valid one of privacy array'), | 445 | .custom(isNumberArray).withMessage('Should have a valid privacyOneOf array'), |
449 | query('tagsOneOf') | 446 | query('tagsOneOf') |
450 | .optional() | 447 | .optional() |
451 | .customSanitizer(toArray) | 448 | .customSanitizer(toArray) |
452 | .custom(isStringArray).withMessage('Should have a valid one of tags array'), | 449 | .custom(isStringArray).withMessage('Should have a valid tagsOneOf array'), |
453 | query('tagsAllOf') | 450 | query('tagsAllOf') |
454 | .optional() | 451 | .optional() |
455 | .customSanitizer(toArray) | 452 | .customSanitizer(toArray) |
456 | .custom(isStringArray).withMessage('Should have a valid all of tags array'), | 453 | .custom(isStringArray).withMessage('Should have a valid tagsAllOf array'), |
457 | query('nsfw') | 454 | query('nsfw') |
458 | .optional() | 455 | .optional() |
459 | .custom(isBooleanBothQueryValid).withMessage('Should have a valid NSFW attribute'), | 456 | .custom(isBooleanBothQueryValid), |
460 | query('isLive') | 457 | query('isLive') |
461 | .optional() | 458 | .optional() |
462 | .customSanitizer(toBooleanOrNull) | 459 | .customSanitizer(toBooleanOrNull) |
463 | .custom(isBooleanValid).withMessage('Should have a valid live boolean'), | 460 | .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'), |
464 | query('filter') | 461 | query('filter') |
465 | .optional() | 462 | .optional() |
466 | .custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'), | 463 | .custom(isVideoFilterValid), |
467 | query('include') | 464 | query('include') |
468 | .optional() | 465 | .optional() |
469 | .custom(isVideoIncludeValid).withMessage('Should have a valid include attribute'), | 466 | .custom(isVideoIncludeValid), |
470 | query('isLocal') | 467 | query('isLocal') |
471 | .optional() | 468 | .optional() |
472 | .customSanitizer(toBooleanOrNull) | 469 | .customSanitizer(toBooleanOrNull) |
473 | .custom(isBooleanValid).withMessage('Should have a valid local boolean'), | 470 | .custom(isBooleanValid).withMessage('Should have a valid isLocal boolean'), |
474 | query('hasHLSFiles') | 471 | query('hasHLSFiles') |
475 | .optional() | 472 | .optional() |
476 | .customSanitizer(toBooleanOrNull) | 473 | .customSanitizer(toBooleanOrNull) |
477 | .custom(isBooleanValid).withMessage('Should have a valid has hls boolean'), | 474 | .custom(isBooleanValid).withMessage('Should have a valid hasHLSFiles boolean'), |
478 | query('hasWebtorrentFiles') | 475 | query('hasWebtorrentFiles') |
479 | .optional() | 476 | .optional() |
480 | .customSanitizer(toBooleanOrNull) | 477 | .customSanitizer(toBooleanOrNull) |
481 | .custom(isBooleanValid).withMessage('Should have a valid has webtorrent boolean'), | 478 | .custom(isBooleanValid).withMessage('Should have a valid hasWebtorrentFiles boolean'), |
482 | query('skipCount') | 479 | query('skipCount') |
483 | .optional() | 480 | .optional() |
484 | .customSanitizer(toBooleanOrNull) | 481 | .customSanitizer(toBooleanOrNull) |
485 | .custom(isBooleanValid).withMessage('Should have a valid skip count boolean'), | 482 | .custom(isBooleanValid).withMessage('Should have a valid skipCount boolean'), |
486 | query('search') | 483 | query('search') |
487 | .optional() | 484 | .optional() |
488 | .custom(exists).withMessage('Should have a valid search'), | 485 | .custom(exists), |
489 | 486 | ||
490 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 487 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
491 | logger.debug('Checking commons video filters query', { parameters: req.query }) | 488 | logger.debug('Checking commons video filters query', { parameters: req.query }) |