1 import * as express from 'express'
2 import { body, param, query } from 'express-validator'
3 import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
4 import { logger } from '../../../helpers/logger'
5 import { areValidationErrors } from '../utils'
6 import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
7 import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares'
9 const videosBlacklistRemoveValidator = [
10 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
12 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
15 if (areValidationErrors(req, res)) return
16 if (!await doesVideoExist(req.params.videoId, res)) return
17 if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return
23 const videosBlacklistAddValidator = [
24 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
27 .customSanitizer(toBooleanOrNull)
28 .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
31 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
33 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
34 logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params })
36 if (areValidationErrors(req, res)) return
37 if (!await doesVideoExist(req.params.videoId, res)) return
39 const video = res.locals.videoAll
40 if (req.body.unfederate === true && video.remote === true) {
43 .send({ error: 'You cannot unfederate a remote video.' })
51 const videosBlacklistUpdateValidator = [
52 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
55 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
57 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
58 logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params })
60 if (areValidationErrors(req, res)) return
61 if (!await doesVideoExist(req.params.videoId, res)) return
62 if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return
68 const videosBlacklistFiltersValidator = [
71 .custom(isVideoBlacklistTypeValid).withMessage('Should have a valid video blacklist type attribute'),
75 .isEmpty().withMessage('Should have a valid search'),
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