]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/videos/video-blacklist.ts
Cleanup invalid rates/comments/shares
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-blacklist.ts
CommitLineData
35bf0c83 1import * as express from 'express'
26b7305a 2import { body, param } from 'express-validator/check'
5abb9fbb 3import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
0f6acda1 4import { doesVideoExist } from '../../../helpers/custom-validators/videos'
6e46de09
C
5import { logger } from '../../../helpers/logger'
6import { areValidationErrors } from '../utils'
0f6acda1 7import { doesVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'
35bf0c83
C
8
9const videosBlacklistRemoveValidator = [
72c7248b 10 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
35bf0c83 11
a2431b7d 12 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
35bf0c83
C
13 logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
14
a2431b7d 15 if (areValidationErrors(req, res)) return
0f6acda1
C
16 if (!await doesVideoExist(req.params.videoId, res)) return
17 if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return
a2431b7d
C
18
19 return next()
35bf0c83
C
20 }
21]
22
23const videosBlacklistAddValidator = [
72c7248b 24 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
5abb9fbb
C
25 body('unfederate')
26 .optional()
27 .toBoolean()
28 .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
26b7305a
C
29 body('reason')
30 .optional()
31 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
35bf0c83 32
a2431b7d 33 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
26b7305a 34 logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params })
35bf0c83 35
a2431b7d 36 if (areValidationErrors(req, res)) return
0f6acda1 37 if (!await doesVideoExist(req.params.videoId, res)) return
a2431b7d 38
dae86118 39 const video = res.locals.video
5abb9fbb
C
40 if (req.body.unfederate === true && video.remote === true) {
41 return res
42 .status(409)
43 .send({ error: 'You cannot unfederate a remote video.' })
44 .end()
45 }
46
a2431b7d 47 return next()
35bf0c83
C
48 }
49]
50
26b7305a
C
51const videosBlacklistUpdateValidator = [
52 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
53 body('reason')
54 .optional()
55 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
35bf0c83 56
26b7305a
C
57 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
58 logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params })
35bf0c83 59
26b7305a 60 if (areValidationErrors(req, res)) return
0f6acda1
C
61 if (!await doesVideoExist(req.params.videoId, res)) return
62 if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return
a2431b7d 63
26b7305a 64 return next()
35bf0c83 65 }
26b7305a 66]
35bf0c83 67
26b7305a 68// ---------------------------------------------------------------------------
35bf0c83 69
26b7305a
C
70export {
71 videosBlacklistAddValidator,
72 videosBlacklistRemoveValidator,
73 videosBlacklistUpdateValidator
35bf0c83 74}