]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/validators/videos/video-abuses.ts
Fix pt_PT and el_GR translations
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-abuses.ts
... / ...
CommitLineData
1import * as express from 'express'
2import 'express-validator'
3import { body, param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { logger } from '../../../helpers/logger'
6import { areValidationErrors } from '../utils'
7import {
8 isVideoAbuseModerationCommentValid,
9 isVideoAbuseReasonValid,
10 isVideoAbuseStateValid
11} from '../../../helpers/custom-validators/video-abuses'
12import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares'
13
14const 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'),
17
18 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
19 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
20
21 if (areValidationErrors(req, res)) return
22 if (!await doesVideoExist(req.params.videoId, res)) return
23
24 return next()
25 }
26]
27
28const 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'),
31
32 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
33 logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body })
34
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
38
39 return next()
40 }
41]
42
43const 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'),
46 body('state')
47 .optional()
48 .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'),
49 body('moderationComment')
50 .optional()
51 .custom(isVideoAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'),
52
53 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
54 logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body })
55
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
59
60 return next()
61 }
62]
63
64// ---------------------------------------------------------------------------
65
66export {
67 videoAbuseReportValidator,
68 videoAbuseGetValidator,
69 videoAbuseUpdateValidator
70}