1 import * as express from 'express'
2 import 'express-validator'
3 import { body, param } from 'express-validator/check'
4 import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5 import { logger } from '../../../helpers/logger'
6 import { areValidationErrors } from '../utils'
8 isVideoAbuseModerationCommentValid,
9 isVideoAbuseReasonValid,
10 isVideoAbuseStateValid
11 } from '../../../helpers/custom-validators/video-abuses'
12 import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares'
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 doesVideoExist(req.params.videoId, res)) return
37 if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return
43 const videoAbuseUpdateValidator = [
44 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
45 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
48 .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'),
49 body('moderationComment')
51 .custom(isVideoAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'),
53 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
54 logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body })
56 if (areValidationErrors(req, res)) return
57 if (!await doesVideoExist(req.params.videoId, res)) return
58 if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return
64 // ---------------------------------------------------------------------------
67 videoAbuseReportValidator,
68 videoAbuseGetValidator,
69 videoAbuseUpdateValidator