1 import * as express from 'express'
2 import { body, param, query } from 'express-validator'
3 import { exists, isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
6 isVideoAbuseModerationCommentValid,
7 isVideoAbuseReasonValid,
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'
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'),
18 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
19 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
21 if (areValidationErrors(req, res)) return
22 if (!await doesVideoExist(req.params.videoId, res)) return
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'),
32 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
33 logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body })
35 if (areValidationErrors(req, res)) return
36 if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return
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'),
47 .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'),
48 body('moderationComment')
50 .custom(isVideoAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'),
52 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
53 logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body })
55 if (areValidationErrors(req, res)) return
56 if (!await doesVideoAbuseExist(req.params.id, req.params.videoId, res)) return
62 const videoAbuseListValidator = [
65 .custom(isIdValid).withMessage('Should have a valid id'),
68 .custom(exists).withMessage('Should have a valid search'),
71 .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'),
74 .custom(isAbuseVideoIsValid).withMessage('Should have a valid "video is" attribute'),
75 query('searchReporter')
77 .custom(exists).withMessage('Should have a valid reporter search'),
78 query('searchReportee')
80 .custom(exists).withMessage('Should have a valid reportee search'),
83 .custom(exists).withMessage('Should have a valid video search'),
84 query('searchVideoChannel')
86 .custom(exists).withMessage('Should have a valid video channel search'),
88 (req: express.Request, res: express.Response, next: express.NextFunction) => {
89 logger.debug('Checking videoAbuseListValidator parameters', { parameters: req.body })
91 if (areValidationErrors(req, res)) return
97 // ---------------------------------------------------------------------------
100 videoAbuseListValidator,
101 videoAbuseReportValidator,
102 videoAbuseGetValidator,
103 videoAbuseUpdateValidator