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 | |
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')
17 files changed, 138 insertions, 122 deletions
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 = [ | |||
29 | .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), | 29 | .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), |
30 | body('reason') | 30 | body('reason') |
31 | .optional() | 31 | .optional() |
32 | .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'), | 32 | .custom(isVideoBlacklistReasonValid), |
33 | 33 | ||
34 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 34 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
35 | logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) | 35 | 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 = [ | |||
18 | isValidVideoIdParam('videoId'), | 18 | isValidVideoIdParam('videoId'), |
19 | 19 | ||
20 | param('captionLanguage') | 20 | param('captionLanguage') |
21 | .custom(isVideoCaptionLanguageValid).not().isEmpty().withMessage('Should have a valid caption language'), | 21 | .custom(isVideoCaptionLanguageValid).not().isEmpty(), |
22 | 22 | ||
23 | body('captionfile') | 23 | body('captionfile') |
24 | .custom((_, { req }) => isVideoCaptionFile(req.files, 'captionfile')) | 24 | .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, | |||
20 | } | 20 | } |
21 | 21 | ||
22 | export const videoChannelSyncValidator = [ | 22 | export const videoChannelSyncValidator = [ |
23 | body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), | 23 | body('externalChannelUrl') |
24 | body('videoChannelId').isInt().withMessage('Should have a valid video channel id'), | 24 | .custom(isUrlValid), |
25 | |||
26 | body('videoChannelId') | ||
27 | .isInt(), | ||
25 | 28 | ||
26 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 29 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
27 | logger.debug('Checking videoChannelSync parameters', { parameters: req.body }) | 30 | 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 | |||
19 | import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' | 19 | import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' |
20 | 20 | ||
21 | export const videoChannelsAddValidator = [ | 21 | export const videoChannelsAddValidator = [ |
22 | body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), | 22 | body('name') |
23 | body('displayName').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), | 23 | .custom(isVideoChannelUsernameValid), |
24 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), | 24 | body('displayName') |
25 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), | 25 | .custom(isVideoChannelDisplayNameValid), |
26 | body('description') | ||
27 | .optional() | ||
28 | .custom(isVideoChannelDescriptionValid), | ||
29 | body('support') | ||
30 | .optional() | ||
31 | .custom(isVideoChannelSupportValid), | ||
26 | 32 | ||
27 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 33 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
28 | logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) | 34 | logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) |
@@ -49,16 +55,18 @@ export const videoChannelsAddValidator = [ | |||
49 | ] | 55 | ] |
50 | 56 | ||
51 | export const videoChannelsUpdateValidator = [ | 57 | export const videoChannelsUpdateValidator = [ |
52 | param('nameWithHost').exists().withMessage('Should have an video channel name with host'), | 58 | param('nameWithHost') |
59 | .exists(), | ||
60 | |||
53 | body('displayName') | 61 | body('displayName') |
54 | .optional() | 62 | .optional() |
55 | .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), | 63 | .custom(isVideoChannelDisplayNameValid), |
56 | body('description') | 64 | body('description') |
57 | .optional() | 65 | .optional() |
58 | .custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), | 66 | .custom(isVideoChannelDescriptionValid), |
59 | body('support') | 67 | body('support') |
60 | .optional() | 68 | .optional() |
61 | .custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), | 69 | .custom(isVideoChannelSupportValid), |
62 | body('bulkVideosSupportUpdate') | 70 | body('bulkVideosSupportUpdate') |
63 | .optional() | 71 | .optional() |
64 | .custom(isBooleanValid).withMessage('Should have a valid bulkVideosSupportUpdate boolean field'), | 72 | .custom(isBooleanValid).withMessage('Should have a valid bulkVideosSupportUpdate boolean field'), |
@@ -83,7 +91,8 @@ export const videoChannelsRemoveValidator = [ | |||
83 | ] | 91 | ] |
84 | 92 | ||
85 | export const videoChannelsNameWithHostValidator = [ | 93 | export const videoChannelsNameWithHostValidator = [ |
86 | param('nameWithHost').exists().withMessage('Should have an video channel name with host'), | 94 | param('nameWithHost') |
95 | .exists(), | ||
87 | 96 | ||
88 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 97 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
89 | logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params }) | 98 | logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params }) |
@@ -124,7 +133,7 @@ export const videoChannelStatsValidator = [ | |||
124 | query('withStats') | 133 | query('withStats') |
125 | .optional() | 134 | .optional() |
126 | .customSanitizer(toBooleanOrNull) | 135 | .customSanitizer(toBooleanOrNull) |
127 | .custom(isBooleanValid).withMessage('Should have a valid stats flag'), | 136 | .custom(isBooleanValid).withMessage('Should have a valid stats flag boolean'), |
128 | 137 | ||
129 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 138 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
130 | if (areValidationErrors(req, res)) return | 139 | if (areValidationErrors(req, res)) return |
@@ -133,7 +142,9 @@ export const videoChannelStatsValidator = [ | |||
133 | ] | 142 | ] |
134 | 143 | ||
135 | export const videoChannelsListValidator = [ | 144 | export const videoChannelsListValidator = [ |
136 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | 145 | query('search') |
146 | .optional() | ||
147 | .not().isEmpty(), | ||
137 | 148 | ||
138 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 149 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
139 | logger.debug('Checking video channels search query', { parameters: req.query }) | 150 | logger.debug('Checking video channels search query', { parameters: req.query }) |
@@ -145,11 +156,12 @@ export const videoChannelsListValidator = [ | |||
145 | ] | 156 | ] |
146 | 157 | ||
147 | export const videoChannelImportVideosValidator = [ | 158 | export const videoChannelImportVideosValidator = [ |
148 | body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), | 159 | body('externalChannelUrl') |
160 | .custom(isUrlValid), | ||
149 | 161 | ||
150 | body('videoChannelSyncId') | 162 | body('videoChannelSyncId') |
151 | .optional() | 163 | .optional() |
152 | .custom(isIdValid).withMessage('Should have a valid channel sync id'), | 164 | .custom(isIdValid), |
153 | 165 | ||
154 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 166 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
155 | logger.debug('Checking videoChannelImport parameters', { parameters: req.body }) | 167 | 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 { | |||
19 | 19 | ||
20 | const listVideoCommentsValidator = [ | 20 | const listVideoCommentsValidator = [ |
21 | query('isLocal') | 21 | query('isLocal') |
22 | .optional() | 22 | .optional() |
23 | .customSanitizer(toBooleanOrNull) | 23 | .customSanitizer(toBooleanOrNull) |
24 | .custom(isBooleanValid) | 24 | .custom(isBooleanValid) |
25 | .withMessage('Should have a valid is local boolean'), | 25 | .withMessage('Should have a valid isLocal boolean'), |
26 | 26 | ||
27 | query('onLocalVideo') | 27 | query('onLocalVideo') |
28 | .optional() | 28 | .optional() |
29 | .customSanitizer(toBooleanOrNull) | 29 | .customSanitizer(toBooleanOrNull) |
30 | .custom(isBooleanValid) | 30 | .custom(isBooleanValid) |
31 | .withMessage('Should have a valid is on local video boolean'), | 31 | .withMessage('Should have a valid onLocalVideo boolean'), |
32 | 32 | ||
33 | query('search') | 33 | query('search') |
34 | .optional() | 34 | .optional() |
35 | .custom(exists).withMessage('Should have a valid search'), | 35 | .custom(exists), |
36 | 36 | ||
37 | query('searchAccount') | 37 | query('searchAccount') |
38 | .optional() | 38 | .optional() |
39 | .custom(exists).withMessage('Should have a valid account search'), | 39 | .custom(exists), |
40 | 40 | ||
41 | query('searchVideo') | 41 | query('searchVideo') |
42 | .optional() | 42 | .optional() |
43 | .custom(exists).withMessage('Should have a valid video search'), | 43 | .custom(exists), |
44 | 44 | ||
45 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 45 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
46 | logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query }) | 46 | logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query }) |
@@ -70,7 +70,7 @@ const listVideoThreadCommentsValidator = [ | |||
70 | isValidVideoIdParam('videoId'), | 70 | isValidVideoIdParam('videoId'), |
71 | 71 | ||
72 | param('threadId') | 72 | param('threadId') |
73 | .custom(isIdValid).not().isEmpty().withMessage('Should have a valid threadId'), | 73 | .custom(isIdValid), |
74 | 74 | ||
75 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 75 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
76 | logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params }) | 76 | logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params }) |
@@ -89,7 +89,7 @@ const addVideoCommentThreadValidator = [ | |||
89 | isValidVideoIdParam('videoId'), | 89 | isValidVideoIdParam('videoId'), |
90 | 90 | ||
91 | body('text') | 91 | body('text') |
92 | .custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), | 92 | .custom(isValidVideoCommentText), |
93 | 93 | ||
94 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 94 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
95 | logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body }) | 95 | logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body }) |
@@ -109,9 +109,9 @@ const addVideoCommentThreadValidator = [ | |||
109 | const addVideoCommentReplyValidator = [ | 109 | const addVideoCommentReplyValidator = [ |
110 | isValidVideoIdParam('videoId'), | 110 | isValidVideoIdParam('videoId'), |
111 | 111 | ||
112 | param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), | 112 | param('commentId').custom(isIdValid), |
113 | 113 | ||
114 | body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), | 114 | body('text').custom(isValidVideoCommentText), |
115 | 115 | ||
116 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 116 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
117 | logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body }) | 117 | logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body }) |
@@ -133,7 +133,7 @@ const videoCommentGetValidator = [ | |||
133 | isValidVideoIdParam('videoId'), | 133 | isValidVideoIdParam('videoId'), |
134 | 134 | ||
135 | param('commentId') | 135 | param('commentId') |
136 | .custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), | 136 | .custom(isIdValid), |
137 | 137 | ||
138 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 138 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
139 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) | 139 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) |
@@ -149,7 +149,8 @@ const videoCommentGetValidator = [ | |||
149 | const removeVideoCommentValidator = [ | 149 | const removeVideoCommentValidator = [ |
150 | isValidVideoIdParam('videoId'), | 150 | isValidVideoIdParam('videoId'), |
151 | 151 | ||
152 | param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), | 152 | param('commentId') |
153 | .custom(isIdValid), | ||
153 | 154 | ||
154 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 155 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
155 | logger.debug('Checking removeVideoCommentValidator parameters.', { parameters: req.params }) | 156 | 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 = [ | |||
41 | isValidVideoIdParam('id'), | 41 | isValidVideoIdParam('id'), |
42 | 42 | ||
43 | param('videoFileId') | 43 | param('videoFileId') |
44 | .custom(isIdValid).withMessage('Should have a valid file id'), | 44 | .custom(isIdValid), |
45 | 45 | ||
46 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 46 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
47 | logger.debug('Checking videoFilesDeleteWebTorrentFile parameters', { parameters: req.params }) | 47 | logger.debug('Checking videoFilesDeleteWebTorrentFile parameters', { parameters: req.params }) |
@@ -109,7 +109,7 @@ const videoFilesDeleteHLSFileValidator = [ | |||
109 | isValidVideoIdParam('id'), | 109 | isValidVideoIdParam('id'), |
110 | 110 | ||
111 | param('videoFileId') | 111 | param('videoFileId') |
112 | .custom(isIdValid).withMessage('Should have a valid file id'), | 112 | .custom(isIdValid), |
113 | 113 | ||
114 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 114 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
115 | logger.debug('Checking videoFilesDeleteHLSFile parameters', { parameters: req.params }) | 115 | 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' | |||
19 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | 19 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ |
20 | body('channelId') | 20 | body('channelId') |
21 | .customSanitizer(toIntOrNull) | 21 | .customSanitizer(toIntOrNull) |
22 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 22 | .custom(isIdValid), |
23 | body('targetUrl') | 23 | body('targetUrl') |
24 | .optional() | 24 | .optional() |
25 | .custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), | 25 | .custom(isVideoImportTargetUrlValid), |
26 | body('magnetUri') | 26 | body('magnetUri') |
27 | .optional() | 27 | .optional() |
28 | .custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'), | 28 | .custom(isVideoMagnetUriValid), |
29 | body('torrentfile') | 29 | body('torrentfile') |
30 | .custom((value, { req }) => isVideoImportTorrentFile(req.files)) | 30 | .custom((value, { req }) => isVideoImportTorrentFile(req.files)) |
31 | .withMessage( | 31 | .withMessage( |
@@ -95,7 +95,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | |||
95 | const getMyVideoImportsValidator = [ | 95 | const getMyVideoImportsValidator = [ |
96 | query('videoChannelSyncId') | 96 | query('videoChannelSyncId') |
97 | .optional() | 97 | .optional() |
98 | .custom(isIdValid).withMessage('Should have correct videoChannelSync id'), | 98 | .custom(isIdValid), |
99 | 99 | ||
100 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 100 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
101 | logger.debug('Checking getMyVideoImportsValidator parameters', { parameters: req.params }) | 101 | logger.debug('Checking getMyVideoImportsValidator parameters', { parameters: req.params }) |
@@ -108,7 +108,7 @@ const getMyVideoImportsValidator = [ | |||
108 | 108 | ||
109 | const videoImportDeleteValidator = [ | 109 | const videoImportDeleteValidator = [ |
110 | param('id') | 110 | param('id') |
111 | .custom(isIdValid).withMessage('Should have correct import id'), | 111 | .custom(isIdValid), |
112 | 112 | ||
113 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 113 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
114 | logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.params }) | 114 | logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.params }) |
@@ -131,7 +131,7 @@ const videoImportDeleteValidator = [ | |||
131 | 131 | ||
132 | const videoImportCancelValidator = [ | 132 | const videoImportCancelValidator = [ |
133 | param('id') | 133 | param('id') |
134 | .custom(isIdValid).withMessage('Should have correct import id'), | 134 | .custom(isIdValid), |
135 | 135 | ||
136 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 136 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
137 | logger.debug('Checking videoImportCancelValidator parameters', { parameters: req.params }) | 137 | 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 = [ | |||
56 | const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ | 56 | const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ |
57 | body('channelId') | 57 | body('channelId') |
58 | .customSanitizer(toIntOrNull) | 58 | .customSanitizer(toIntOrNull) |
59 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 59 | .custom(isIdValid), |
60 | 60 | ||
61 | body('name') | 61 | body('name') |
62 | .custom(isVideoNameValid).withMessage( | 62 | .custom(isVideoNameValid).withMessage( |
@@ -66,18 +66,17 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ | |||
66 | body('saveReplay') | 66 | body('saveReplay') |
67 | .optional() | 67 | .optional() |
68 | .customSanitizer(toBooleanOrNull) | 68 | .customSanitizer(toBooleanOrNull) |
69 | .custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'), | 69 | .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'), |
70 | 70 | ||
71 | body('permanentLive') | 71 | body('permanentLive') |
72 | .optional() | 72 | .optional() |
73 | .customSanitizer(toBooleanOrNull) | 73 | .customSanitizer(toBooleanOrNull) |
74 | .custom(isBooleanValid).withMessage('Should have a valid permanentLive attribute'), | 74 | .custom(isBooleanValid).withMessage('Should have a valid permanentLive boolean'), |
75 | 75 | ||
76 | body('latencyMode') | 76 | body('latencyMode') |
77 | .optional() | 77 | .optional() |
78 | .customSanitizer(toIntOrNull) | 78 | .customSanitizer(toIntOrNull) |
79 | .custom(isLiveLatencyModeValid) | 79 | .custom(isLiveLatencyModeValid), |
80 | .withMessage('Should have a valid latency mode attribute'), | ||
81 | 80 | ||
82 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 81 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
83 | logger.debug('Checking videoLiveAddValidator parameters', { parameters: req.body }) | 82 | logger.debug('Checking videoLiveAddValidator parameters', { parameters: req.body }) |
@@ -156,13 +155,12 @@ const videoLiveUpdateValidator = [ | |||
156 | body('saveReplay') | 155 | body('saveReplay') |
157 | .optional() | 156 | .optional() |
158 | .customSanitizer(toBooleanOrNull) | 157 | .customSanitizer(toBooleanOrNull) |
159 | .custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'), | 158 | .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'), |
160 | 159 | ||
161 | body('latencyMode') | 160 | body('latencyMode') |
162 | .optional() | 161 | .optional() |
163 | .customSanitizer(toIntOrNull) | 162 | .customSanitizer(toIntOrNull) |
164 | .custom(isLiveLatencyModeValid) | 163 | .custom(isLiveLatencyModeValid), |
165 | .withMessage('Should have a valid latency mode attribute'), | ||
166 | 164 | ||
167 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 165 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
168 | logger.debug('Checking videoLiveUpdateValidator parameters', { parameters: req.body }) | 166 | 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 = [ | |||
41 | 41 | ||
42 | const videosTerminateChangeOwnershipValidator = [ | 42 | const videosTerminateChangeOwnershipValidator = [ |
43 | param('id') | 43 | param('id') |
44 | .custom(isIdValid).withMessage('Should have a valid id'), | 44 | .custom(isIdValid), |
45 | 45 | ||
46 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 46 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
47 | logger.debug('Checking changeOwnership parameters', { parameters: req.params }) | 47 | 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 { | |||
45 | 45 | ||
46 | const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ | 46 | const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ |
47 | body('displayName') | 47 | body('displayName') |
48 | .custom(isVideoPlaylistNameValid).withMessage('Should have a valid display name'), | 48 | .custom(isVideoPlaylistNameValid), |
49 | 49 | ||
50 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 50 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
51 | logger.debug('Checking videoPlaylistsAddValidator parameters', { parameters: req.body }) | 51 | logger.debug('Checking videoPlaylistsAddValidator parameters', { parameters: req.body }) |
@@ -73,7 +73,7 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([ | |||
73 | 73 | ||
74 | body('displayName') | 74 | body('displayName') |
75 | .optional() | 75 | .optional() |
76 | .custom(isVideoPlaylistNameValid).withMessage('Should have a valid display name'), | 76 | .custom(isVideoPlaylistNameValid), |
77 | 77 | ||
78 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 78 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
79 | logger.debug('Checking videoPlaylistsUpdateValidator parameters', { parameters: req.body }) | 79 | logger.debug('Checking videoPlaylistsUpdateValidator parameters', { parameters: req.body }) |
@@ -184,7 +184,9 @@ const videoPlaylistsGetValidator = (fetchType: VideoPlaylistFetchType) => { | |||
184 | } | 184 | } |
185 | 185 | ||
186 | const videoPlaylistsSearchValidator = [ | 186 | const videoPlaylistsSearchValidator = [ |
187 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | 187 | query('search') |
188 | .optional() | ||
189 | .not().isEmpty(), | ||
188 | 190 | ||
189 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 191 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
190 | logger.debug('Checking videoPlaylists search query', { parameters: req.query }) | 192 | logger.debug('Checking videoPlaylists search query', { parameters: req.query }) |
@@ -200,13 +202,13 @@ const videoPlaylistsAddVideoValidator = [ | |||
200 | 202 | ||
201 | body('videoId') | 203 | body('videoId') |
202 | .customSanitizer(toCompleteUUID) | 204 | .customSanitizer(toCompleteUUID) |
203 | .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), | 205 | .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid/short uuid'), |
204 | body('startTimestamp') | 206 | body('startTimestamp') |
205 | .optional() | 207 | .optional() |
206 | .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'), | 208 | .custom(isVideoPlaylistTimestampValid), |
207 | body('stopTimestamp') | 209 | body('stopTimestamp') |
208 | .optional() | 210 | .optional() |
209 | .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'), | 211 | .custom(isVideoPlaylistTimestampValid), |
210 | 212 | ||
211 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 213 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
212 | logger.debug('Checking videoPlaylistsAddVideoValidator parameters', { parameters: req.params }) | 214 | logger.debug('Checking videoPlaylistsAddVideoValidator parameters', { parameters: req.params }) |
@@ -230,13 +232,13 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [ | |||
230 | isValidPlaylistIdParam('playlistId'), | 232 | isValidPlaylistIdParam('playlistId'), |
231 | param('playlistElementId') | 233 | param('playlistElementId') |
232 | .customSanitizer(toCompleteUUID) | 234 | .customSanitizer(toCompleteUUID) |
233 | .custom(isIdValid).withMessage('Should have an element id/uuid'), | 235 | .custom(isIdValid).withMessage('Should have an element id/uuid/short uuid'), |
234 | body('startTimestamp') | 236 | body('startTimestamp') |
235 | .optional() | 237 | .optional() |
236 | .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'), | 238 | .custom(isVideoPlaylistTimestampValid), |
237 | body('stopTimestamp') | 239 | body('stopTimestamp') |
238 | .optional() | 240 | .optional() |
239 | .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'), | 241 | .custom(isVideoPlaylistTimestampValid), |
240 | 242 | ||
241 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 243 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
242 | logger.debug('Checking videoPlaylistsRemoveVideoValidator parameters', { parameters: req.params }) | 244 | logger.debug('Checking videoPlaylistsRemoveVideoValidator parameters', { parameters: req.params }) |
@@ -266,7 +268,7 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [ | |||
266 | const videoPlaylistElementAPGetValidator = [ | 268 | const videoPlaylistElementAPGetValidator = [ |
267 | isValidPlaylistIdParam('playlistId'), | 269 | isValidPlaylistIdParam('playlistId'), |
268 | param('playlistElementId') | 270 | param('playlistElementId') |
269 | .custom(isIdValid).withMessage('Should have an playlist element id'), | 271 | .custom(isIdValid), |
270 | 272 | ||
271 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 273 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
272 | logger.debug('Checking videoPlaylistElementAPGetValidator parameters', { parameters: req.params }) | 274 | logger.debug('Checking videoPlaylistElementAPGetValidator parameters', { parameters: req.params }) |
@@ -300,13 +302,14 @@ const videoPlaylistElementAPGetValidator = [ | |||
300 | 302 | ||
301 | const videoPlaylistsReorderVideosValidator = [ | 303 | const videoPlaylistsReorderVideosValidator = [ |
302 | isValidPlaylistIdParam('playlistId'), | 304 | isValidPlaylistIdParam('playlistId'), |
305 | |||
303 | body('startPosition') | 306 | body('startPosition') |
304 | .isInt({ min: 1 }).withMessage('Should have a valid start position'), | 307 | .isInt({ min: 1 }), |
305 | body('insertAfterPosition') | 308 | body('insertAfterPosition') |
306 | .isInt({ min: 0 }).withMessage('Should have a valid insert after position'), | 309 | .isInt({ min: 0 }), |
307 | body('reorderLength') | 310 | body('reorderLength') |
308 | .optional() | 311 | .optional() |
309 | .isInt({ min: 1 }).withMessage('Should have a valid range length'), | 312 | .isInt({ min: 1 }), |
310 | 313 | ||
311 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 314 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
312 | logger.debug('Checking videoPlaylistsReorderVideosValidator parameters', { parameters: req.params }) | 315 | logger.debug('Checking videoPlaylistsReorderVideosValidator parameters', { parameters: req.params }) |
@@ -340,7 +343,7 @@ const videoPlaylistsReorderVideosValidator = [ | |||
340 | const commonVideoPlaylistFiltersValidator = [ | 343 | const commonVideoPlaylistFiltersValidator = [ |
341 | query('playlistType') | 344 | query('playlistType') |
342 | .optional() | 345 | .optional() |
343 | .custom(isVideoPlaylistTypeValid).withMessage('Should have a valid playlist type'), | 346 | .custom(isVideoPlaylistTypeValid), |
344 | 347 | ||
345 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 348 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
346 | logger.debug('Checking commonVideoPlaylistFiltersValidator parameters', { parameters: req.params }) | 349 | logger.debug('Checking commonVideoPlaylistFiltersValidator parameters', { parameters: req.params }) |
@@ -399,11 +402,11 @@ function getCommonPlaylistEditAttributes () { | |||
399 | body('description') | 402 | body('description') |
400 | .optional() | 403 | .optional() |
401 | .customSanitizer(toValueOrNull) | 404 | .customSanitizer(toValueOrNull) |
402 | .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), | 405 | .custom(isVideoPlaylistDescriptionValid), |
403 | body('privacy') | 406 | body('privacy') |
404 | .optional() | 407 | .optional() |
405 | .customSanitizer(toIntOrNull) | 408 | .customSanitizer(toIntOrNull) |
406 | .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), | 409 | .custom(isVideoPlaylistPrivacyValid), |
407 | body('videoChannelId') | 410 | body('videoChannelId') |
408 | .optional() | 411 | .optional() |
409 | .customSanitizer(toIntOrNull) | 412 | .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 | |||
13 | const videoUpdateRateValidator = [ | 13 | const videoUpdateRateValidator = [ |
14 | isValidVideoIdParam('id'), | 14 | isValidVideoIdParam('id'), |
15 | 15 | ||
16 | body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), | 16 | body('rating') |
17 | .custom(isVideoRatingTypeValid), | ||
17 | 18 | ||
18 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 19 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
19 | logger.debug('Checking videoRate parameters', { parameters: req.body }) | 20 | logger.debug('Checking videoRate parameters', { parameters: req.body }) |
@@ -29,8 +30,10 @@ const videoUpdateRateValidator = [ | |||
29 | 30 | ||
30 | const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { | 31 | const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { |
31 | return [ | 32 | return [ |
32 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), | 33 | param('name') |
33 | param('videoId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid videoId'), | 34 | .custom(isAccountNameValid), |
35 | param('videoId') | ||
36 | .custom(isIdValid), | ||
34 | 37 | ||
35 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 38 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
36 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) | 39 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) |
@@ -53,7 +56,9 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { | |||
53 | } | 56 | } |
54 | 57 | ||
55 | const videoRatingValidator = [ | 58 | const videoRatingValidator = [ |
56 | query('rating').optional().custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), | 59 | query('rating') |
60 | .optional() | ||
61 | .custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), | ||
57 | 62 | ||
58 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 63 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
59 | logger.debug('Checking rating parameter', { parameters: req.params }) | 64 | 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 = [ | |||
10 | isValidVideoIdParam('id'), | 10 | isValidVideoIdParam('id'), |
11 | 11 | ||
12 | param('actorId') | 12 | param('actorId') |
13 | .custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'), | 13 | .custom(isIdValid), |
14 | 14 | ||
15 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 15 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
16 | logger.debug('Checking videoShare parameters', { parameters: req.params }) | 16 | 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 = [ | |||
12 | 12 | ||
13 | query('startDate') | 13 | query('startDate') |
14 | .optional() | 14 | .optional() |
15 | .custom(isDateValid) | 15 | .custom(isDateValid), |
16 | .withMessage('Should have a valid start date'), | ||
17 | 16 | ||
18 | query('endDate') | 17 | query('endDate') |
19 | .optional() | 18 | .optional() |
20 | .custom(isDateValid) | 19 | .custom(isDateValid), |
21 | .withMessage('Should have a valid end date'), | ||
22 | 20 | ||
23 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 21 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
24 | logger.debug('Checking videoOverallStatsValidator parameters', { parameters: req.body }) | 22 | logger.debug('Checking videoOverallStatsValidator parameters', { parameters: req.body }) |
@@ -54,18 +52,15 @@ const videoTimeserieStatsValidator = [ | |||
54 | isValidVideoIdParam('videoId'), | 52 | isValidVideoIdParam('videoId'), |
55 | 53 | ||
56 | param('metric') | 54 | param('metric') |
57 | .custom(isValidStatTimeserieMetric) | 55 | .custom(isValidStatTimeserieMetric), |
58 | .withMessage('Should have a valid timeserie metric'), | ||
59 | 56 | ||
60 | query('startDate') | 57 | query('startDate') |
61 | .optional() | 58 | .optional() |
62 | .custom(isDateValid) | 59 | .custom(isDateValid), |
63 | .withMessage('Should have a valid start date'), | ||
64 | 60 | ||
65 | query('endDate') | 61 | query('endDate') |
66 | .optional() | 62 | .optional() |
67 | .custom(isDateValid) | 63 | .custom(isDateValid), |
68 | .withMessage('Should have a valid end date'), | ||
69 | 64 | ||
70 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 65 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
71 | logger.debug('Checking videoTimeserieStatsValidator parameters', { parameters: req.body }) | 66 | 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' | |||
16 | import { areValidationErrors, checkUserCanManageVideo, checkUserQuota, doesVideoExist } from '../shared' | 16 | import { areValidationErrors, checkUserCanManageVideo, checkUserQuota, doesVideoExist } from '../shared' |
17 | 17 | ||
18 | const videoStudioAddEditionValidator = [ | 18 | const videoStudioAddEditionValidator = [ |
19 | param('videoId').custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), | 19 | param('videoId') |
20 | .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid/short uuid'), | ||
20 | 21 | ||
21 | body('tasks').custom(isValidStudioTasksArray).withMessage('Should have a valid array of tasks'), | 22 | body('tasks') |
23 | .custom(isValidStudioTasksArray).withMessage('Should have a valid array of tasks'), | ||
22 | 24 | ||
23 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 25 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
24 | logger.debug('Checking videoStudioAddEditionValidator parameters.', { parameters: req.params, body: req.body, files: req.files }) | 26 | 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 = [ | |||
11 | isValidVideoIdParam('videoId'), | 11 | isValidVideoIdParam('videoId'), |
12 | 12 | ||
13 | body('transcodingType') | 13 | body('transcodingType') |
14 | .custom(isValidCreateTranscodingType).withMessage('Should have a valid transcoding type'), | 14 | .custom(isValidCreateTranscodingType), |
15 | 15 | ||
16 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 16 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
17 | logger.debug('Checking createTranscodingValidator parameters', { parameters: req.body }) | 17 | 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' | |||
10 | 10 | ||
11 | const getVideoLocalViewerValidator = [ | 11 | const getVideoLocalViewerValidator = [ |
12 | param('localViewerId') | 12 | param('localViewerId') |
13 | .custom(isIdValid).withMessage('Should have a valid local viewer id'), | 13 | .custom(isIdValid), |
14 | 14 | ||
15 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 15 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
16 | logger.debug('Checking getVideoLocalViewerValidator parameters', { parameters: req.params }) | 16 | logger.debug('Checking getVideoLocalViewerValidator parameters', { parameters: req.params }) |
@@ -37,7 +37,7 @@ const videoViewValidator = [ | |||
37 | body('currentTime') | 37 | body('currentTime') |
38 | .optional() // TODO: remove optional in a few versions, introduced in 4.2 | 38 | .optional() // TODO: remove optional in a few versions, introduced in 4.2 |
39 | .customSanitizer(toIntOrNull) | 39 | .customSanitizer(toIntOrNull) |
40 | .custom(isIntOrNull).withMessage('Should have correct current time'), | 40 | .custom(isIntOrNull), |
41 | 41 | ||
42 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 42 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
43 | logger.debug('Checking videoView parameters', { parameters: req.body }) | 43 | 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([ | |||
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 }) |