aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/abuse.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-17 14:27:04 +0200
committerChocobozzz <me@florianbigard.com>2022-08-17 14:27:04 +0200
commit396f6f0140b0f76162e2378fd5a61e2f888673ed (patch)
treea5bd668bfc7dca7f311b9fc42ebb8bd01f462648 /server/middlewares/validators/abuse.ts
parent97eba003a9d0adcb0cab9190f566327b1417c7d3 (diff)
downloadPeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.tar.gz
PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.tar.zst
PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.zip
Cleanup useless express validator messages
Diffstat (limited to 'server/middlewares/validators/abuse.ts')
-rw-r--r--server/middlewares/validators/abuse.ts66
1 files changed, 31 insertions, 35 deletions
diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts
index 22f66c8cf..e4aa1a839 100644
--- a/server/middlewares/validators/abuse.ts
+++ b/server/middlewares/validators/abuse.ts
@@ -22,41 +22,34 @@ import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdE
22const abuseReportValidator = [ 22const abuseReportValidator = [
23 body('account.id') 23 body('account.id')
24 .optional() 24 .optional()
25 .custom(isIdValid) 25 .custom(isIdValid),
26 .withMessage('Should have a valid accountId'),
27 26
28 body('video.id') 27 body('video.id')
29 .optional() 28 .optional()
30 .customSanitizer(toCompleteUUID) 29 .customSanitizer(toCompleteUUID)
31 .custom(isIdOrUUIDValid) 30 .custom(isIdOrUUIDValid),
32 .withMessage('Should have a valid videoId'),
33 body('video.startAt') 31 body('video.startAt')
34 .optional() 32 .optional()
35 .customSanitizer(toIntOrNull) 33 .customSanitizer(toIntOrNull)
36 .custom(isAbuseTimestampValid) 34 .custom(isAbuseTimestampValid),
37 .withMessage('Should have valid starting time value'),
38 body('video.endAt') 35 body('video.endAt')
39 .optional() 36 .optional()
40 .customSanitizer(toIntOrNull) 37 .customSanitizer(toIntOrNull)
41 .custom(isAbuseTimestampValid) 38 .custom(isAbuseTimestampValid)
42 .withMessage('Should have valid ending time value')
43 .bail() 39 .bail()
44 .custom(isAbuseTimestampCoherent) 40 .custom(isAbuseTimestampCoherent)
45 .withMessage('Should have a startAt timestamp beginning before endAt'), 41 .withMessage('Should have a startAt timestamp beginning before endAt'),
46 42
47 body('comment.id') 43 body('comment.id')
48 .optional() 44 .optional()
49 .custom(isIdValid) 45 .custom(isIdValid),
50 .withMessage('Should have a valid commentId'),
51 46
52 body('reason') 47 body('reason')
53 .custom(isAbuseReasonValid) 48 .custom(isAbuseReasonValid),
54 .withMessage('Should have a valid reason'),
55 49
56 body('predefinedReasons') 50 body('predefinedReasons')
57 .optional() 51 .optional()
58 .custom(areAbusePredefinedReasonsValid) 52 .custom(areAbusePredefinedReasonsValid),
59 .withMessage('Should have a valid list of predefined reasons'),
60 53
61 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 54 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
62 logger.debug('Checking abuseReport parameters', { parameters: req.body }) 55 logger.debug('Checking abuseReport parameters', { parameters: req.body })
@@ -79,7 +72,8 @@ const abuseReportValidator = [
79] 72]
80 73
81const abuseGetValidator = [ 74const abuseGetValidator = [
82 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), 75 param('id')
76 .custom(isIdValid),
83 77
84 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 78 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
85 logger.debug('Checking abuseGetValidator parameters', { parameters: req.body }) 79 logger.debug('Checking abuseGetValidator parameters', { parameters: req.body })
@@ -92,14 +86,15 @@ const abuseGetValidator = [
92] 86]
93 87
94const abuseUpdateValidator = [ 88const abuseUpdateValidator = [
95 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), 89 param('id')
90 .custom(isIdValid),
96 91
97 body('state') 92 body('state')
98 .optional() 93 .optional()
99 .custom(isAbuseStateValid).withMessage('Should have a valid abuse state'), 94 .custom(isAbuseStateValid),
100 body('moderationComment') 95 body('moderationComment')
101 .optional() 96 .optional()
102 .custom(isAbuseModerationCommentValid).withMessage('Should have a valid moderation comment'), 97 .custom(isAbuseModerationCommentValid),
103 98
104 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 99 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
105 logger.debug('Checking abuseUpdateValidator parameters', { parameters: req.body }) 100 logger.debug('Checking abuseUpdateValidator parameters', { parameters: req.body })
@@ -114,36 +109,34 @@ const abuseUpdateValidator = [
114const abuseListForAdminsValidator = [ 109const abuseListForAdminsValidator = [
115 query('id') 110 query('id')
116 .optional() 111 .optional()
117 .custom(isIdValid).withMessage('Should have a valid id'), 112 .custom(isIdValid),
118 query('filter') 113 query('filter')
119 .optional() 114 .optional()
120 .custom(isAbuseFilterValid) 115 .custom(isAbuseFilterValid),
121 .withMessage('Should have a valid filter'),
122 query('predefinedReason') 116 query('predefinedReason')
123 .optional() 117 .optional()
124 .custom(isAbusePredefinedReasonValid) 118 .custom(isAbusePredefinedReasonValid),
125 .withMessage('Should have a valid predefinedReason'),
126 query('search') 119 query('search')
127 .optional() 120 .optional()
128 .custom(exists).withMessage('Should have a valid search'), 121 .custom(exists),
129 query('state') 122 query('state')
130 .optional() 123 .optional()
131 .custom(isAbuseStateValid).withMessage('Should have a valid abuse state'), 124 .custom(isAbuseStateValid),
132 query('videoIs') 125 query('videoIs')
133 .optional() 126 .optional()
134 .custom(isAbuseVideoIsValid).withMessage('Should have a valid "video is" attribute'), 127 .custom(isAbuseVideoIsValid),
135 query('searchReporter') 128 query('searchReporter')
136 .optional() 129 .optional()
137 .custom(exists).withMessage('Should have a valid reporter search'), 130 .custom(exists),
138 query('searchReportee') 131 query('searchReportee')
139 .optional() 132 .optional()
140 .custom(exists).withMessage('Should have a valid reportee search'), 133 .custom(exists),
141 query('searchVideo') 134 query('searchVideo')
142 .optional() 135 .optional()
143 .custom(exists).withMessage('Should have a valid video search'), 136 .custom(exists),
144 query('searchVideoChannel') 137 query('searchVideoChannel')
145 .optional() 138 .optional()
146 .custom(exists).withMessage('Should have a valid video channel search'), 139 .custom(exists),
147 140
148 (req: express.Request, res: express.Response, next: express.NextFunction) => { 141 (req: express.Request, res: express.Response, next: express.NextFunction) => {
149 logger.debug('Checking abuseListForAdminsValidator parameters', { parameters: req.body }) 142 logger.debug('Checking abuseListForAdminsValidator parameters', { parameters: req.body })
@@ -157,15 +150,15 @@ const abuseListForAdminsValidator = [
157const abuseListForUserValidator = [ 150const abuseListForUserValidator = [
158 query('id') 151 query('id')
159 .optional() 152 .optional()
160 .custom(isIdValid).withMessage('Should have a valid id'), 153 .custom(isIdValid),
161 154
162 query('search') 155 query('search')
163 .optional() 156 .optional()
164 .custom(exists).withMessage('Should have a valid search'), 157 .custom(exists),
165 158
166 query('state') 159 query('state')
167 .optional() 160 .optional()
168 .custom(isAbuseStateValid).withMessage('Should have a valid abuse state'), 161 .custom(isAbuseStateValid),
169 162
170 (req: express.Request, res: express.Response, next: express.NextFunction) => { 163 (req: express.Request, res: express.Response, next: express.NextFunction) => {
171 logger.debug('Checking abuseListForUserValidator parameters', { parameters: req.body }) 164 logger.debug('Checking abuseListForUserValidator parameters', { parameters: req.body })
@@ -177,7 +170,8 @@ const abuseListForUserValidator = [
177] 170]
178 171
179const getAbuseValidator = [ 172const getAbuseValidator = [
180 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), 173 param('id')
174 .custom(isIdValid),
181 175
182 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 176 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
183 logger.debug('Checking getAbuseValidator parameters', { parameters: req.body }) 177 logger.debug('Checking getAbuseValidator parameters', { parameters: req.body })
@@ -216,7 +210,8 @@ const checkAbuseValidForMessagesValidator = [
216] 210]
217 211
218const addAbuseMessageValidator = [ 212const addAbuseMessageValidator = [
219 body('message').custom(isAbuseMessageValid).not().isEmpty().withMessage('Should have a valid abuse message'), 213 body('message')
214 .custom(isAbuseMessageValid),
220 215
221 (req: express.Request, res: express.Response, next: express.NextFunction) => { 216 (req: express.Request, res: express.Response, next: express.NextFunction) => {
222 logger.debug('Checking addAbuseMessageValidator parameters', { parameters: req.body }) 217 logger.debug('Checking addAbuseMessageValidator parameters', { parameters: req.body })
@@ -228,7 +223,8 @@ const addAbuseMessageValidator = [
228] 223]
229 224
230const deleteAbuseMessageValidator = [ 225const deleteAbuseMessageValidator = [
231 param('messageId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid message id'), 226 param('messageId')
227 .custom(isIdValid),
232 228
233 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 229 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
234 logger.debug('Checking deleteAbuseMessageValidator parameters', { parameters: req.body }) 230 logger.debug('Checking deleteAbuseMessageValidator parameters', { parameters: req.body })