diff options
author | Chocobozzz <me@florianbigard.com> | 2020-05-06 17:39:07 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-07 08:33:34 +0200 |
commit | feb34f6b6b991046aab6a10df747b48fa4da07a7 (patch) | |
tree | 02bb7277d45be166ba48caef2ee73bf89dbe1258 /server/middlewares/validators | |
parent | d170c5c580abf6f90d7bf144e2417e248ce2ecf4 (diff) | |
download | PeerTube-feb34f6b6b991046aab6a10df747b48fa4da07a7.tar.gz PeerTube-feb34f6b6b991046aab6a10df747b48fa4da07a7.tar.zst PeerTube-feb34f6b6b991046aab6a10df747b48fa4da07a7.zip |
Use video abuse filters on client side
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/videos/video-abuses.ts | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts index 7c316fe13..901997bcb 100644 --- a/server/middlewares/validators/videos/video-abuses.ts +++ b/server/middlewares/validators/videos/video-abuses.ts | |||
@@ -1,14 +1,15 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 3 | import { exists, isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { areValidationErrors } from '../utils' | ||
6 | import { | 4 | import { |
5 | isAbuseVideoIsValid, | ||
7 | isVideoAbuseModerationCommentValid, | 6 | isVideoAbuseModerationCommentValid, |
8 | isVideoAbuseReasonValid, | 7 | isVideoAbuseReasonValid, |
9 | isVideoAbuseStateValid | 8 | isVideoAbuseStateValid |
10 | } from '../../../helpers/custom-validators/video-abuses' | 9 | } from '../../../helpers/custom-validators/video-abuses' |
10 | import { logger } from '../../../helpers/logger' | ||
11 | import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' | 11 | import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' |
12 | import { areValidationErrors } from '../utils' | ||
12 | 13 | ||
13 | const videoAbuseReportValidator = [ | 14 | const videoAbuseReportValidator = [ |
14 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 15 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
@@ -58,9 +59,45 @@ const videoAbuseUpdateValidator = [ | |||
58 | } | 59 | } |
59 | ] | 60 | ] |
60 | 61 | ||
62 | const videoAbuseListValidator = [ | ||
63 | query('id') | ||
64 | .optional() | ||
65 | .custom(isIdValid).withMessage('Should have a valid id'), | ||
66 | query('search') | ||
67 | .optional() | ||
68 | .custom(exists).withMessage('Should have a valid search'), | ||
69 | query('state') | ||
70 | .optional() | ||
71 | .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'), | ||
72 | query('videoIs') | ||
73 | .optional() | ||
74 | .custom(isAbuseVideoIsValid).withMessage('Should have a valid "video is" attribute'), | ||
75 | query('searchReporter') | ||
76 | .optional() | ||
77 | .custom(exists).withMessage('Should have a valid reporter search'), | ||
78 | query('searchReportee') | ||
79 | .optional() | ||
80 | .custom(exists).withMessage('Should have a valid reportee search'), | ||
81 | query('searchVideo') | ||
82 | .optional() | ||
83 | .custom(exists).withMessage('Should have a valid video search'), | ||
84 | query('searchVideoChannel') | ||
85 | .optional() | ||
86 | .custom(exists).withMessage('Should have a valid video channel search'), | ||
87 | |||
88 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
89 | logger.debug('Checking videoAbuseListValidator parameters', { parameters: req.body }) | ||
90 | |||
91 | if (areValidationErrors(req, res)) return | ||
92 | |||
93 | return next() | ||
94 | } | ||
95 | ] | ||
96 | |||
61 | // --------------------------------------------------------------------------- | 97 | // --------------------------------------------------------------------------- |
62 | 98 | ||
63 | export { | 99 | export { |
100 | videoAbuseListValidator, | ||
64 | videoAbuseReportValidator, | 101 | videoAbuseReportValidator, |
65 | videoAbuseGetValidator, | 102 | videoAbuseGetValidator, |
66 | videoAbuseUpdateValidator | 103 | videoAbuseUpdateValidator |