]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/videos/video-abuses.ts
Use video abuse filters on client side
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-abuses.ts
CommitLineData
268eebed 1import * as express from 'express'
feb34f6b
C
2import { body, param, query } from 'express-validator'
3import { exists, isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
268eebed 4import {
feb34f6b 5 isAbuseVideoIsValid,
268eebed
C
6 isVideoAbuseModerationCommentValid,
7 isVideoAbuseReasonValid,
8 isVideoAbuseStateValid
6e46de09 9} from '../../../helpers/custom-validators/video-abuses'
feb34f6b 10import { logger } from '../../../helpers/logger'
3e753302 11import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares'
feb34f6b 12import { areValidationErrors } from '../utils'
268eebed
C
13
14const videoAbuseReportValidator = [
15 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
16 body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'),
17
18 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
19 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
20
21 if (areValidationErrors(req, res)) return
0f6acda1 22 if (!await doesVideoExist(req.params.videoId, res)) return
268eebed
C
23
24 return next()
25 }
26]
27
28const videoAbuseGetValidator = [
29 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
30 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
31
32 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
33 logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body })
34
35 if (areValidationErrors(req, res)) return
68d19a0a 36 if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return
268eebed
C
37
38 return next()
39 }
40]
41
42const videoAbuseUpdateValidator = [
43 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
44 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
45 body('state')
46 .optional()
47 .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'),
48 body('moderationComment')
49 .optional()
50 .custom(isVideoAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'),
51
52 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
53 logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body })
54
55 if (areValidationErrors(req, res)) return
68d19a0a 56 if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return
268eebed
C
57
58 return next()
59 }
60]
61
feb34f6b
C
62const 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
268eebed
C
97// ---------------------------------------------------------------------------
98
99export {
feb34f6b 100 videoAbuseListValidator,
268eebed
C
101 videoAbuseReportValidator,
102 videoAbuseGetValidator,
103 videoAbuseUpdateValidator
104}