1 import * as express from 'express'
2 import { body, param, query } from 'express-validator/check'
3 import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
4 import { doesVideoExist } from '../../../helpers/custom-validators/videos'
5 import { logger } from '../../../helpers/logger'
6 import { areValidationErrors } from '../utils'
8 doesVideoBlacklistExist,
9 isVideoBlacklistReasonValid,
10 isVideoBlacklistTypeValid
11 } from '../../../helpers/custom-validators/video-blacklist'
13 const videosBlacklistRemoveValidator = [
14 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
16 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
17 logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
19 if (areValidationErrors(req, res)) return
20 if (!await doesVideoExist(req.params.videoId, res)) return
21 if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return
27 const videosBlacklistAddValidator = [
28 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
32 .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
35 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
37 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
38 logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params })
40 if (areValidationErrors(req, res)) return
41 if (!await doesVideoExist(req.params.videoId, res)) return
43 const video = res.locals.video
44 if (req.body.unfederate === true && video.remote === true) {
47 .send({ error: 'You cannot unfederate a remote video.' })
55 const videosBlacklistUpdateValidator = [
56 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
59 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
61 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
62 logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params })
64 if (areValidationErrors(req, res)) return
65 if (!await doesVideoExist(req.params.videoId, res)) return
66 if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return
72 const videosBlacklistFiltersValidator = [
75 .custom(isVideoBlacklistTypeValid).withMessage('Should have a valid video blacklist type attribute'),
77 (req: express.Request, res: express.Response, next: express.NextFunction) => {
78 logger.debug('Checking videos blacklist filters query', { parameters: req.query })
80 if (areValidationErrors(req, res)) return
86 // ---------------------------------------------------------------------------
89 videosBlacklistAddValidator,
90 videosBlacklistRemoveValidator,
91 videosBlacklistUpdateValidator,
92 videosBlacklistFiltersValidator