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