diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/videos/video-abuses.ts | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts index 901997bcb..5bbd1e3c6 100644 --- a/server/middlewares/validators/videos/video-abuses.ts +++ b/server/middlewares/validators/videos/video-abuses.ts | |||
@@ -1,19 +1,46 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { exists, isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { | 4 | import { |
5 | isAbuseVideoIsValid, | 5 | isAbuseVideoIsValid, |
6 | isVideoAbuseModerationCommentValid, | 6 | isVideoAbuseModerationCommentValid, |
7 | isVideoAbuseReasonValid, | 7 | isVideoAbuseReasonValid, |
8 | isVideoAbuseStateValid | 8 | isVideoAbuseStateValid, |
9 | isVideoAbusePredefinedReasonsValid, | ||
10 | isVideoAbusePredefinedReasonValid, | ||
11 | isVideoAbuseTimestampValid, | ||
12 | isVideoAbuseTimestampCoherent | ||
9 | } from '../../../helpers/custom-validators/video-abuses' | 13 | } from '../../../helpers/custom-validators/video-abuses' |
10 | import { logger } from '../../../helpers/logger' | 14 | import { logger } from '../../../helpers/logger' |
11 | import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' | 15 | import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' |
12 | import { areValidationErrors } from '../utils' | 16 | import { areValidationErrors } from '../utils' |
13 | 17 | ||
14 | const videoAbuseReportValidator = [ | 18 | const videoAbuseReportValidator = [ |
15 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 19 | param('videoId') |
16 | body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), | 20 | .custom(isIdOrUUIDValid) |
21 | .not() | ||
22 | .isEmpty() | ||
23 | .withMessage('Should have a valid videoId'), | ||
24 | body('reason') | ||
25 | .custom(isVideoAbuseReasonValid) | ||
26 | .withMessage('Should have a valid reason'), | ||
27 | body('predefinedReasons') | ||
28 | .optional() | ||
29 | .custom(isVideoAbusePredefinedReasonsValid) | ||
30 | .withMessage('Should have a valid list of predefined reasons'), | ||
31 | body('startAt') | ||
32 | .optional() | ||
33 | .customSanitizer(toIntOrNull) | ||
34 | .custom(isVideoAbuseTimestampValid) | ||
35 | .withMessage('Should have valid starting time value'), | ||
36 | body('endAt') | ||
37 | .optional() | ||
38 | .customSanitizer(toIntOrNull) | ||
39 | .custom(isVideoAbuseTimestampValid) | ||
40 | .withMessage('Should have valid ending time value') | ||
41 | .bail() | ||
42 | .custom(isVideoAbuseTimestampCoherent) | ||
43 | .withMessage('Should have a startAt timestamp beginning before endAt'), | ||
17 | 44 | ||
18 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 45 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
19 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) | 46 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) |
@@ -63,6 +90,10 @@ const videoAbuseListValidator = [ | |||
63 | query('id') | 90 | query('id') |
64 | .optional() | 91 | .optional() |
65 | .custom(isIdValid).withMessage('Should have a valid id'), | 92 | .custom(isIdValid).withMessage('Should have a valid id'), |
93 | query('predefinedReason') | ||
94 | .optional() | ||
95 | .custom(isVideoAbusePredefinedReasonValid) | ||
96 | .withMessage('Should have a valid predefinedReason'), | ||
66 | query('search') | 97 | query('search') |
67 | .optional() | 98 | .optional() |
68 | .custom(exists).withMessage('Should have a valid search'), | 99 | .custom(exists).withMessage('Should have a valid search'), |