1 import * as express from 'express'
2 import { body, param } from 'express-validator'
3 import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
4 import { logger } from '../../../helpers/logger'
5 import { areValidationErrors } from '../utils'
7 isVideoAbuseModerationCommentValid,
8 isVideoAbuseReasonValid,
10 } from '../../../helpers/custom-validators/video-abuses'
11 import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares'
13 const videoAbuseReportValidator = [
14 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
15 body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'),
17 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
18 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
20 if (areValidationErrors(req, res)) return
21 if (!await doesVideoExist(req.params.videoId, res)) return
27 const videoAbuseGetValidator = [
28 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
29 param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'),
31 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
32 logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body })
34 if (areValidationErrors(req, res)) return
35 if (!await doesVideoExist(req.params.videoId, res)) return
36 if (!await doesVideoAbuseExist(req.params.id, res.locals.videoAll.id, 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 doesVideoExist(req.params.videoId, res)) return
57 if (!await doesVideoAbuseExist(req.params.id, res.locals.videoAll.id, res)) return
63 // ---------------------------------------------------------------------------
66 videoAbuseReportValidator,
67 videoAbuseGetValidator,
68 videoAbuseUpdateValidator