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