1 import * as express from 'express'
2 import { body, param, query } from 'express-validator'
3 import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
4 import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
5 import { logger } from '../../../helpers/logger'
6 import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares'
7 import { areValidationErrors } from '../utils'
8 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10 const videosBlacklistRemoveValidator = [
11 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
13 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
14 logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
16 if (areValidationErrors(req, res)) return
17 if (!await doesVideoExist(req.params.videoId, res)) return
18 if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return
24 const videosBlacklistAddValidator = [
25 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
28 .customSanitizer(toBooleanOrNull)
29 .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
32 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
34 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
35 logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params })
37 if (areValidationErrors(req, res)) return
38 if (!await doesVideoExist(req.params.videoId, res)) return
40 const video = res.locals.videoAll
41 if (req.body.unfederate === true && video.remote === true) {
43 .status(HttpStatusCode.CONFLICT_409)
44 .send({ error: 'You cannot unfederate a remote video.' })
52 const videosBlacklistUpdateValidator = [
53 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
56 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
58 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
59 logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params })
61 if (areValidationErrors(req, res)) return
62 if (!await doesVideoExist(req.params.videoId, res)) return
63 if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return
69 const videosBlacklistFiltersValidator = [
72 .customSanitizer(toIntOrNull)
73 .custom(isVideoBlacklistTypeValid).withMessage('Should have a valid video blacklist type attribute'),
77 .isEmpty().withMessage('Should have a valid search'),
79 (req: express.Request, res: express.Response, next: express.NextFunction) => {
80 logger.debug('Checking videos blacklist filters query', { parameters: req.query })
82 if (areValidationErrors(req, res)) return
88 // ---------------------------------------------------------------------------
91 videosBlacklistAddValidator,
92 videosBlacklistRemoveValidator,
93 videosBlacklistUpdateValidator,
94 videosBlacklistFiltersValidator