From 396f6f0140b0f76162e2378fd5a61e2f888673ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 17 Aug 2022 14:27:04 +0200 Subject: Cleanup useless express validator messages --- .../validators/videos/video-blacklist.ts | 2 +- .../validators/videos/video-captions.ts | 2 +- .../validators/videos/video-channel-sync.ts | 7 ++- .../validators/videos/video-channels.ts | 38 +++++++----- .../validators/videos/video-comments.ts | 35 +++++------ .../middlewares/validators/videos/video-files.ts | 4 +- .../middlewares/validators/videos/video-imports.ts | 12 ++-- server/middlewares/validators/videos/video-live.ts | 14 ++--- .../validators/videos/video-ownership-changes.ts | 2 +- .../validators/videos/video-playlists.ts | 35 +++++------ .../middlewares/validators/videos/video-rates.ts | 13 +++-- .../middlewares/validators/videos/video-shares.ts | 2 +- .../middlewares/validators/videos/video-stats.ts | 15 ++--- .../middlewares/validators/videos/video-studio.ts | 6 +- .../validators/videos/video-transcoding.ts | 2 +- server/middlewares/validators/videos/video-view.ts | 4 +- server/middlewares/validators/videos/videos.ts | 67 +++++++++++----------- 17 files changed, 138 insertions(+), 122 deletions(-) (limited to 'server/middlewares/validators/videos') diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index de11e69f2..f065f101c 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts @@ -29,7 +29,7 @@ const videosBlacklistAddValidator = [ .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), body('reason') .optional() - .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'), + .custom(isVideoBlacklistReasonValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts index dfb8fefc5..fd6dd151a 100644 --- a/server/middlewares/validators/videos/video-captions.ts +++ b/server/middlewares/validators/videos/video-captions.ts @@ -18,7 +18,7 @@ const addVideoCaptionValidator = [ isValidVideoIdParam('videoId'), param('captionLanguage') - .custom(isVideoCaptionLanguageValid).not().isEmpty().withMessage('Should have a valid caption language'), + .custom(isVideoCaptionLanguageValid).not().isEmpty(), body('captionfile') .custom((_, { req }) => isVideoCaptionFile(req.files, 'captionfile')) diff --git a/server/middlewares/validators/videos/video-channel-sync.ts b/server/middlewares/validators/videos/video-channel-sync.ts index 081f09bba..18d8d74d2 100644 --- a/server/middlewares/validators/videos/video-channel-sync.ts +++ b/server/middlewares/validators/videos/video-channel-sync.ts @@ -20,8 +20,11 @@ export const ensureSyncIsEnabled = (req: express.Request, res: express.Response, } export const videoChannelSyncValidator = [ - body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), - body('videoChannelId').isInt().withMessage('Should have a valid video channel id'), + body('externalChannelUrl') + .custom(isUrlValid), + + body('videoChannelId') + .isInt(), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoChannelSync parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index d53c777fa..ad1415691 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -19,10 +19,16 @@ import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' export const videoChannelsAddValidator = [ - body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), - body('displayName').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), - body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), - body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), + body('name') + .custom(isVideoChannelUsernameValid), + body('displayName') + .custom(isVideoChannelDisplayNameValid), + body('description') + .optional() + .custom(isVideoChannelDescriptionValid), + body('support') + .optional() + .custom(isVideoChannelSupportValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) @@ -49,16 +55,18 @@ export const videoChannelsAddValidator = [ ] export const videoChannelsUpdateValidator = [ - param('nameWithHost').exists().withMessage('Should have an video channel name with host'), + param('nameWithHost') + .exists(), + body('displayName') .optional() - .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), + .custom(isVideoChannelDisplayNameValid), body('description') .optional() - .custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), + .custom(isVideoChannelDescriptionValid), body('support') .optional() - .custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), + .custom(isVideoChannelSupportValid), body('bulkVideosSupportUpdate') .optional() .custom(isBooleanValid).withMessage('Should have a valid bulkVideosSupportUpdate boolean field'), @@ -83,7 +91,8 @@ export const videoChannelsRemoveValidator = [ ] export const videoChannelsNameWithHostValidator = [ - param('nameWithHost').exists().withMessage('Should have an video channel name with host'), + param('nameWithHost') + .exists(), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params }) @@ -124,7 +133,7 @@ export const videoChannelStatsValidator = [ query('withStats') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid stats flag'), + .custom(isBooleanValid).withMessage('Should have a valid stats flag boolean'), (req: express.Request, res: express.Response, next: express.NextFunction) => { if (areValidationErrors(req, res)) return @@ -133,7 +142,9 @@ export const videoChannelStatsValidator = [ ] export const videoChannelsListValidator = [ - query('search').optional().not().isEmpty().withMessage('Should have a valid search'), + query('search') + .optional() + .not().isEmpty(), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking video channels search query', { parameters: req.query }) @@ -145,11 +156,12 @@ export const videoChannelsListValidator = [ ] export const videoChannelImportVideosValidator = [ - body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), + body('externalChannelUrl') + .custom(isUrlValid), body('videoChannelSyncId') .optional() - .custom(isIdValid).withMessage('Should have a valid channel sync id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoChannelImport parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 68f41e50e..b2a39617b 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts @@ -19,28 +19,28 @@ import { const listVideoCommentsValidator = [ query('isLocal') - .optional() - .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid) - .withMessage('Should have a valid is local boolean'), + .optional() + .customSanitizer(toBooleanOrNull) + .custom(isBooleanValid) + .withMessage('Should have a valid isLocal boolean'), query('onLocalVideo') - .optional() - .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid) - .withMessage('Should have a valid is on local video boolean'), + .optional() + .customSanitizer(toBooleanOrNull) + .custom(isBooleanValid) + .withMessage('Should have a valid onLocalVideo boolean'), query('search') .optional() - .custom(exists).withMessage('Should have a valid search'), + .custom(exists), query('searchAccount') .optional() - .custom(exists).withMessage('Should have a valid account search'), + .custom(exists), query('searchVideo') .optional() - .custom(exists).withMessage('Should have a valid video search'), + .custom(exists), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query }) @@ -70,7 +70,7 @@ const listVideoThreadCommentsValidator = [ isValidVideoIdParam('videoId'), param('threadId') - .custom(isIdValid).not().isEmpty().withMessage('Should have a valid threadId'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params }) @@ -89,7 +89,7 @@ const addVideoCommentThreadValidator = [ isValidVideoIdParam('videoId'), body('text') - .custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), + .custom(isValidVideoCommentText), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body }) @@ -109,9 +109,9 @@ const addVideoCommentThreadValidator = [ const addVideoCommentReplyValidator = [ isValidVideoIdParam('videoId'), - param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), + param('commentId').custom(isIdValid), - body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), + body('text').custom(isValidVideoCommentText), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body }) @@ -133,7 +133,7 @@ const videoCommentGetValidator = [ isValidVideoIdParam('videoId'), param('commentId') - .custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) @@ -149,7 +149,8 @@ const videoCommentGetValidator = [ const removeVideoCommentValidator = [ isValidVideoIdParam('videoId'), - param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), + param('commentId') + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking removeVideoCommentValidator parameters.', { parameters: req.params }) diff --git a/server/middlewares/validators/videos/video-files.ts b/server/middlewares/validators/videos/video-files.ts index b3db3f4f7..b44c997e3 100644 --- a/server/middlewares/validators/videos/video-files.ts +++ b/server/middlewares/validators/videos/video-files.ts @@ -41,7 +41,7 @@ const videoFilesDeleteWebTorrentFileValidator = [ isValidVideoIdParam('id'), param('videoFileId') - .custom(isIdValid).withMessage('Should have a valid file id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoFilesDeleteWebTorrentFile parameters', { parameters: req.params }) @@ -109,7 +109,7 @@ const videoFilesDeleteHLSFileValidator = [ isValidVideoIdParam('id'), param('videoFileId') - .custom(isIdValid).withMessage('Should have a valid file id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoFilesDeleteHLSFile parameters', { parameters: req.params }) diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 3115acb21..0ab9e6e6f 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts @@ -19,13 +19,13 @@ import { getCommonVideoEditAttributes } from './videos' const videoImportAddValidator = getCommonVideoEditAttributes().concat([ body('channelId') .customSanitizer(toIntOrNull) - .custom(isIdValid).withMessage('Should have correct video channel id'), + .custom(isIdValid), body('targetUrl') .optional() - .custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), + .custom(isVideoImportTargetUrlValid), body('magnetUri') .optional() - .custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'), + .custom(isVideoMagnetUriValid), body('torrentfile') .custom((value, { req }) => isVideoImportTorrentFile(req.files)) .withMessage( @@ -95,7 +95,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ const getMyVideoImportsValidator = [ query('videoChannelSyncId') .optional() - .custom(isIdValid).withMessage('Should have correct videoChannelSync id'), + .custom(isIdValid), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking getMyVideoImportsValidator parameters', { parameters: req.params }) @@ -108,7 +108,7 @@ const getMyVideoImportsValidator = [ const videoImportDeleteValidator = [ param('id') - .custom(isIdValid).withMessage('Should have correct import id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.params }) @@ -131,7 +131,7 @@ const videoImportDeleteValidator = [ const videoImportCancelValidator = [ param('id') - .custom(isIdValid).withMessage('Should have correct import id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoImportCancelValidator parameters', { parameters: req.params }) diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts index 777b57e9a..a330d70a1 100644 --- a/server/middlewares/validators/videos/video-live.ts +++ b/server/middlewares/validators/videos/video-live.ts @@ -56,7 +56,7 @@ const videoLiveGetValidator = [ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ body('channelId') .customSanitizer(toIntOrNull) - .custom(isIdValid).withMessage('Should have correct video channel id'), + .custom(isIdValid), body('name') .custom(isVideoNameValid).withMessage( @@ -66,18 +66,17 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ body('saveReplay') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'), + .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'), body('permanentLive') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid permanentLive attribute'), + .custom(isBooleanValid).withMessage('Should have a valid permanentLive boolean'), body('latencyMode') .optional() .customSanitizer(toIntOrNull) - .custom(isLiveLatencyModeValid) - .withMessage('Should have a valid latency mode attribute'), + .custom(isLiveLatencyModeValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoLiveAddValidator parameters', { parameters: req.body }) @@ -156,13 +155,12 @@ const videoLiveUpdateValidator = [ body('saveReplay') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'), + .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'), body('latencyMode') .optional() .customSanitizer(toIntOrNull) - .custom(isLiveLatencyModeValid) - .withMessage('Should have a valid latency mode attribute'), + .custom(isLiveLatencyModeValid), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoLiveUpdateValidator parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/videos/video-ownership-changes.ts b/server/middlewares/validators/videos/video-ownership-changes.ts index 6dcdc05f5..e73196f5b 100644 --- a/server/middlewares/validators/videos/video-ownership-changes.ts +++ b/server/middlewares/validators/videos/video-ownership-changes.ts @@ -41,7 +41,7 @@ const videosChangeOwnershipValidator = [ const videosTerminateChangeOwnershipValidator = [ param('id') - .custom(isIdValid).withMessage('Should have a valid id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking changeOwnership parameters', { parameters: req.params }) diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index d514ae0ad..42e6646f9 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts @@ -45,7 +45,7 @@ import { const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ body('displayName') - .custom(isVideoPlaylistNameValid).withMessage('Should have a valid display name'), + .custom(isVideoPlaylistNameValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylistsAddValidator parameters', { parameters: req.body }) @@ -73,7 +73,7 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([ body('displayName') .optional() - .custom(isVideoPlaylistNameValid).withMessage('Should have a valid display name'), + .custom(isVideoPlaylistNameValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylistsUpdateValidator parameters', { parameters: req.body }) @@ -184,7 +184,9 @@ const videoPlaylistsGetValidator = (fetchType: VideoPlaylistFetchType) => { } const videoPlaylistsSearchValidator = [ - query('search').optional().not().isEmpty().withMessage('Should have a valid search'), + query('search') + .optional() + .not().isEmpty(), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylists search query', { parameters: req.query }) @@ -200,13 +202,13 @@ const videoPlaylistsAddVideoValidator = [ body('videoId') .customSanitizer(toCompleteUUID) - .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), + .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid/short uuid'), body('startTimestamp') .optional() - .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'), + .custom(isVideoPlaylistTimestampValid), body('stopTimestamp') .optional() - .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'), + .custom(isVideoPlaylistTimestampValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylistsAddVideoValidator parameters', { parameters: req.params }) @@ -230,13 +232,13 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [ isValidPlaylistIdParam('playlistId'), param('playlistElementId') .customSanitizer(toCompleteUUID) - .custom(isIdValid).withMessage('Should have an element id/uuid'), + .custom(isIdValid).withMessage('Should have an element id/uuid/short uuid'), body('startTimestamp') .optional() - .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'), + .custom(isVideoPlaylistTimestampValid), body('stopTimestamp') .optional() - .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'), + .custom(isVideoPlaylistTimestampValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylistsRemoveVideoValidator parameters', { parameters: req.params }) @@ -266,7 +268,7 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [ const videoPlaylistElementAPGetValidator = [ isValidPlaylistIdParam('playlistId'), param('playlistElementId') - .custom(isIdValid).withMessage('Should have an playlist element id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylistElementAPGetValidator parameters', { parameters: req.params }) @@ -300,13 +302,14 @@ const videoPlaylistElementAPGetValidator = [ const videoPlaylistsReorderVideosValidator = [ isValidPlaylistIdParam('playlistId'), + body('startPosition') - .isInt({ min: 1 }).withMessage('Should have a valid start position'), + .isInt({ min: 1 }), body('insertAfterPosition') - .isInt({ min: 0 }).withMessage('Should have a valid insert after position'), + .isInt({ min: 0 }), body('reorderLength') .optional() - .isInt({ min: 1 }).withMessage('Should have a valid range length'), + .isInt({ min: 1 }), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylistsReorderVideosValidator parameters', { parameters: req.params }) @@ -340,7 +343,7 @@ const videoPlaylistsReorderVideosValidator = [ const commonVideoPlaylistFiltersValidator = [ query('playlistType') .optional() - .custom(isVideoPlaylistTypeValid).withMessage('Should have a valid playlist type'), + .custom(isVideoPlaylistTypeValid), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking commonVideoPlaylistFiltersValidator parameters', { parameters: req.params }) @@ -399,11 +402,11 @@ function getCommonPlaylistEditAttributes () { body('description') .optional() .customSanitizer(toValueOrNull) - .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), + .custom(isVideoPlaylistDescriptionValid), body('privacy') .optional() .customSanitizer(toIntOrNull) - .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), + .custom(isVideoPlaylistPrivacyValid), body('videoChannelId') .optional() .customSanitizer(toIntOrNull) diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 8b8eeedb6..0c02baafb 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts @@ -13,7 +13,8 @@ import { areValidationErrors, checkCanSeeVideo, doesVideoExist, isValidVideoIdPa const videoUpdateRateValidator = [ isValidVideoIdParam('id'), - body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), + body('rating') + .custom(isVideoRatingTypeValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoRate parameters', { parameters: req.body }) @@ -29,8 +30,10 @@ const videoUpdateRateValidator = [ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { return [ - param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), - param('videoId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid videoId'), + param('name') + .custom(isAccountNameValid), + param('videoId') + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) @@ -53,7 +56,9 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { } const videoRatingValidator = [ - query('rating').optional().custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), + query('rating') + .optional() + .custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking rating parameter', { parameters: req.params }) diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index 0f04032bb..40337dcf1 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts @@ -10,7 +10,7 @@ const videosShareValidator = [ isValidVideoIdParam('id'), param('actorId') - .custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoShare parameters', { parameters: req.params }) diff --git a/server/middlewares/validators/videos/video-stats.ts b/server/middlewares/validators/videos/video-stats.ts index f17fbcc09..ddbf2a564 100644 --- a/server/middlewares/validators/videos/video-stats.ts +++ b/server/middlewares/validators/videos/video-stats.ts @@ -12,13 +12,11 @@ const videoOverallStatsValidator = [ query('startDate') .optional() - .custom(isDateValid) - .withMessage('Should have a valid start date'), + .custom(isDateValid), query('endDate') .optional() - .custom(isDateValid) - .withMessage('Should have a valid end date'), + .custom(isDateValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoOverallStatsValidator parameters', { parameters: req.body }) @@ -54,18 +52,15 @@ const videoTimeserieStatsValidator = [ isValidVideoIdParam('videoId'), param('metric') - .custom(isValidStatTimeserieMetric) - .withMessage('Should have a valid timeserie metric'), + .custom(isValidStatTimeserieMetric), query('startDate') .optional() - .custom(isDateValid) - .withMessage('Should have a valid start date'), + .custom(isDateValid), query('endDate') .optional() - .custom(isDateValid) - .withMessage('Should have a valid end date'), + .custom(isDateValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoTimeserieStatsValidator parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/videos/video-studio.ts b/server/middlewares/validators/videos/video-studio.ts index af7fe2283..d07e150ae 100644 --- a/server/middlewares/validators/videos/video-studio.ts +++ b/server/middlewares/validators/videos/video-studio.ts @@ -16,9 +16,11 @@ import { logger } from '../../../helpers/logger' import { areValidationErrors, checkUserCanManageVideo, checkUserQuota, doesVideoExist } from '../shared' const videoStudioAddEditionValidator = [ - param('videoId').custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), + param('videoId') + .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid/short uuid'), - body('tasks').custom(isValidStudioTasksArray).withMessage('Should have a valid array of tasks'), + body('tasks') + .custom(isValidStudioTasksArray).withMessage('Should have a valid array of tasks'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoStudioAddEditionValidator parameters.', { parameters: req.params, body: req.body, files: req.files }) diff --git a/server/middlewares/validators/videos/video-transcoding.ts b/server/middlewares/validators/videos/video-transcoding.ts index da6638f4d..36b9799e6 100644 --- a/server/middlewares/validators/videos/video-transcoding.ts +++ b/server/middlewares/validators/videos/video-transcoding.ts @@ -11,7 +11,7 @@ const createTranscodingValidator = [ isValidVideoIdParam('videoId'), body('transcodingType') - .custom(isValidCreateTranscodingType).withMessage('Should have a valid transcoding type'), + .custom(isValidCreateTranscodingType), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking createTranscodingValidator parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/videos/video-view.ts b/server/middlewares/validators/videos/video-view.ts index 2edcd140f..4927c04ad 100644 --- a/server/middlewares/validators/videos/video-view.ts +++ b/server/middlewares/validators/videos/video-view.ts @@ -10,7 +10,7 @@ import { getCachedVideoDuration } from '@server/lib/video' const getVideoLocalViewerValidator = [ param('localViewerId') - .custom(isIdValid).withMessage('Should have a valid local viewer id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking getVideoLocalViewerValidator parameters', { parameters: req.params }) @@ -37,7 +37,7 @@ const videoViewValidator = [ body('currentTime') .optional() // TODO: remove optional in a few versions, introduced in 4.2 .customSanitizer(toIntOrNull) - .custom(isIntOrNull).withMessage('Should have correct current time'), + .custom(isIntOrNull), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoView parameters', { parameters: req.body }) 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([ ), body('channelId') .customSanitizer(toIntOrNull) - .custom(isIdValid).withMessage('Should have correct video channel id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) @@ -167,9 +167,7 @@ const videosAddResumableValidator = [ */ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ body('filename') - .isString() - .exists() - .withMessage('Should have a valid filename'), + .exists(), body('name') .trim() .custom(isVideoNameValid).withMessage( @@ -177,7 +175,7 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ ), body('channelId') .customSanitizer(toIntOrNull) - .custom(isIdValid).withMessage('Should have correct video channel id'), + .custom(isIdValid), header('x-upload-content-length') .isNumeric() @@ -230,7 +228,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ body('channelId') .optional() .customSanitizer(toIntOrNull) - .custom(isIdValid).withMessage('Should have correct video channel id'), + .custom(isIdValid), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videosUpdate parameters', { parameters: req.body }) @@ -341,8 +339,7 @@ const videosRemoveValidator = [ const videosOverviewValidator = [ query('page') .optional() - .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }) - .withMessage('Should have a valid pagination'), + .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }), (req: express.Request, res: express.Response, next: express.NextFunction) => { if (areValidationErrors(req, res)) return @@ -367,35 +364,35 @@ function getCommonVideoEditAttributes () { body('category') .optional() .customSanitizer(toIntOrNull) - .custom(isVideoCategoryValid).withMessage('Should have a valid category'), + .custom(isVideoCategoryValid), body('licence') .optional() .customSanitizer(toIntOrNull) - .custom(isVideoLicenceValid).withMessage('Should have a valid licence'), + .custom(isVideoLicenceValid), body('language') .optional() .customSanitizer(toValueOrNull) - .custom(isVideoLanguageValid).withMessage('Should have a valid language'), + .custom(isVideoLanguageValid), body('nsfw') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), + .custom(isBooleanValid).withMessage('Should have a valid nsfw boolean'), body('waitTranscoding') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), + .custom(isBooleanValid).withMessage('Should have a valid waitTranscoding boolean'), body('privacy') .optional() .customSanitizer(toValueOrNull) - .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), + .custom(isVideoPrivacyValid), body('description') .optional() .customSanitizer(toValueOrNull) - .custom(isVideoDescriptionValid).withMessage('Should have a valid description'), + .custom(isVideoDescriptionValid), body('support') .optional() .customSanitizer(toValueOrNull) - .custom(isVideoSupportValid).withMessage('Should have a valid support text'), + .custom(isVideoSupportValid), body('tags') .optional() .customSanitizer(toValueOrNull) @@ -407,15 +404,15 @@ function getCommonVideoEditAttributes () { body('commentsEnabled') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), + .custom(isBooleanValid).withMessage('Should have commentsEnabled boolean'), body('downloadEnabled') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), + .custom(isBooleanValid).withMessage('Should have downloadEnabled boolean'), body('originallyPublishedAt') .optional() .customSanitizer(toValueOrNull) - .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), + .custom(isVideoOriginallyPublishedAtValid), body('scheduleUpdate') .optional() .customSanitizer(toValueOrNull), @@ -425,7 +422,7 @@ function getCommonVideoEditAttributes () { body('scheduleUpdate.privacy') .optional() .customSanitizer(toIntOrNull) - .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') + .custom(isScheduleVideoUpdatePrivacyValid) ] as (ValidationChain | ExpressPromiseHandler)[] } @@ -433,59 +430,59 @@ const commonVideosFiltersValidator = [ query('categoryOneOf') .optional() .customSanitizer(toArray) - .custom(isNumberArray).withMessage('Should have a valid one of category array'), + .custom(isNumberArray).withMessage('Should have a valid categoryOneOf array'), query('licenceOneOf') .optional() .customSanitizer(toArray) - .custom(isNumberArray).withMessage('Should have a valid one of licence array'), + .custom(isNumberArray).withMessage('Should have a valid licenceOneOf array'), query('languageOneOf') .optional() .customSanitizer(toArray) - .custom(isStringArray).withMessage('Should have a valid one of language array'), + .custom(isStringArray).withMessage('Should have a valid languageOneOf array'), query('privacyOneOf') .optional() .customSanitizer(toArray) - .custom(isNumberArray).withMessage('Should have a valid one of privacy array'), + .custom(isNumberArray).withMessage('Should have a valid privacyOneOf array'), query('tagsOneOf') .optional() .customSanitizer(toArray) - .custom(isStringArray).withMessage('Should have a valid one of tags array'), + .custom(isStringArray).withMessage('Should have a valid tagsOneOf array'), query('tagsAllOf') .optional() .customSanitizer(toArray) - .custom(isStringArray).withMessage('Should have a valid all of tags array'), + .custom(isStringArray).withMessage('Should have a valid tagsAllOf array'), query('nsfw') .optional() - .custom(isBooleanBothQueryValid).withMessage('Should have a valid NSFW attribute'), + .custom(isBooleanBothQueryValid), query('isLive') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid live boolean'), + .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'), query('filter') .optional() - .custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'), + .custom(isVideoFilterValid), query('include') .optional() - .custom(isVideoIncludeValid).withMessage('Should have a valid include attribute'), + .custom(isVideoIncludeValid), query('isLocal') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid local boolean'), + .custom(isBooleanValid).withMessage('Should have a valid isLocal boolean'), query('hasHLSFiles') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid has hls boolean'), + .custom(isBooleanValid).withMessage('Should have a valid hasHLSFiles boolean'), query('hasWebtorrentFiles') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid has webtorrent boolean'), + .custom(isBooleanValid).withMessage('Should have a valid hasWebtorrentFiles boolean'), query('skipCount') .optional() .customSanitizer(toBooleanOrNull) - .custom(isBooleanValid).withMessage('Should have a valid skip count boolean'), + .custom(isBooleanValid).withMessage('Should have a valid skipCount boolean'), query('search') .optional() - .custom(exists).withMessage('Should have a valid search'), + .custom(exists), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking commons video filters query', { parameters: req.query }) -- cgit v1.2.3