]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/videos/video-abuses.ts
Add server plugin filter hooks for import with torrent and url (#2621)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-abuses.ts
1 import * as express from 'express'
2 import { body, param, query } from 'express-validator'
3 import { exists, isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
4 import {
5 isAbuseVideoIsValid,
6 isVideoAbuseModerationCommentValid,
7 isVideoAbuseReasonValid,
8 isVideoAbuseStateValid
9 } from '../../../helpers/custom-validators/video-abuses'
10 import { logger } from '../../../helpers/logger'
11 import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares'
12 import { areValidationErrors } from '../utils'
13
14 const 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
22 if (!await doesVideoExist(req.params.videoId, res)) return
23
24 return next()
25 }
26 ]
27
28 const 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
36 if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return
37
38 return next()
39 }
40 ]
41
42 const 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
56 if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return
57
58 return next()
59 }
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
97 // ---------------------------------------------------------------------------
98
99 export {
100 videoAbuseListValidator,
101 videoAbuseReportValidator,
102 videoAbuseGetValidator,
103 videoAbuseUpdateValidator
104 }