]>
Commit | Line | Data |
---|---|---|
268eebed | 1 | import * as express from 'express' |
feb34f6b | 2 | import { body, param, query } from 'express-validator' |
1ebddadd | 3 | import { exists, isIdOrUUIDValid, isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
268eebed | 4 | import { |
feb34f6b | 5 | isAbuseVideoIsValid, |
268eebed C |
6 | isVideoAbuseModerationCommentValid, |
7 | isVideoAbuseReasonValid, | |
1ebddadd RK |
8 | isVideoAbuseStateValid, |
9 | isVideoAbusePredefinedReasonsValid, | |
10 | isVideoAbusePredefinedReasonValid, | |
11 | isVideoAbuseTimestampValid, | |
12 | isVideoAbuseTimestampCoherent | |
6e46de09 | 13 | } from '../../../helpers/custom-validators/video-abuses' |
feb34f6b | 14 | import { logger } from '../../../helpers/logger' |
3e753302 | 15 | import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' |
feb34f6b | 16 | import { areValidationErrors } from '../utils' |
268eebed C |
17 | |
18 | const videoAbuseReportValidator = [ | |
1ebddadd RK |
19 | param('videoId') |
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'), | |
268eebed C |
44 | |
45 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
46 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) | |
47 | ||
48 | if (areValidationErrors(req, res)) return | |
0f6acda1 | 49 | if (!await doesVideoExist(req.params.videoId, res)) return |
268eebed C |
50 | |
51 | return next() | |
52 | } | |
53 | ] | |
54 | ||
55 | const videoAbuseGetValidator = [ | |
56 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | |
57 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), | |
58 | ||
59 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
60 | logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body }) | |
61 | ||
62 | if (areValidationErrors(req, res)) return | |
68d19a0a | 63 | if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return |
268eebed C |
64 | |
65 | return next() | |
66 | } | |
67 | ] | |
68 | ||
69 | const videoAbuseUpdateValidator = [ | |
70 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | |
71 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), | |
72 | body('state') | |
73 | .optional() | |
74 | .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'), | |
75 | body('moderationComment') | |
76 | .optional() | |
77 | .custom(isVideoAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'), | |
78 | ||
79 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
80 | logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body }) | |
81 | ||
82 | if (areValidationErrors(req, res)) return | |
68d19a0a | 83 | if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return |
268eebed C |
84 | |
85 | return next() | |
86 | } | |
87 | ] | |
88 | ||
feb34f6b C |
89 | const videoAbuseListValidator = [ |
90 | query('id') | |
91 | .optional() | |
92 | .custom(isIdValid).withMessage('Should have a valid id'), | |
1ebddadd RK |
93 | query('predefinedReason') |
94 | .optional() | |
95 | .custom(isVideoAbusePredefinedReasonValid) | |
96 | .withMessage('Should have a valid predefinedReason'), | |
feb34f6b C |
97 | query('search') |
98 | .optional() | |
99 | .custom(exists).withMessage('Should have a valid search'), | |
100 | query('state') | |
101 | .optional() | |
102 | .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'), | |
103 | query('videoIs') | |
104 | .optional() | |
105 | .custom(isAbuseVideoIsValid).withMessage('Should have a valid "video is" attribute'), | |
106 | query('searchReporter') | |
107 | .optional() | |
108 | .custom(exists).withMessage('Should have a valid reporter search'), | |
109 | query('searchReportee') | |
110 | .optional() | |
111 | .custom(exists).withMessage('Should have a valid reportee search'), | |
112 | query('searchVideo') | |
113 | .optional() | |
114 | .custom(exists).withMessage('Should have a valid video search'), | |
115 | query('searchVideoChannel') | |
116 | .optional() | |
117 | .custom(exists).withMessage('Should have a valid video channel search'), | |
118 | ||
119 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
120 | logger.debug('Checking videoAbuseListValidator parameters', { parameters: req.body }) | |
121 | ||
122 | if (areValidationErrors(req, res)) return | |
123 | ||
124 | return next() | |
125 | } | |
126 | ] | |
127 | ||
268eebed C |
128 | // --------------------------------------------------------------------------- |
129 | ||
130 | export { | |
feb34f6b | 131 | videoAbuseListValidator, |
268eebed C |
132 | videoAbuseReportValidator, |
133 | videoAbuseGetValidator, | |
134 | videoAbuseUpdateValidator | |
135 | } |