1 import * as express from 'express'
2 import { body, param } from 'express-validator/check'
3 import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
4 import { isVideoExist } from '../../../helpers/custom-validators/videos'
5 import { logger } from '../../../helpers/logger'
6 import { areValidationErrors } from '../utils'
7 import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'
8 import { VideoModel } from '../../../models/video/video'
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 isVideoExist(req.params.videoId, res)) return
18 if (!await isVideoBlacklistExist(res.locals.video.id, res)) return
24 const videosBlacklistAddValidator = [
25 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
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 isVideoExist(req.params.videoId, res)) return
40 const video: VideoModel = res.locals.video
41 if (req.body.unfederate === true && video.remote === true) {
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 isVideoExist(req.params.videoId, res)) return
63 if (!await isVideoBlacklistExist(res.locals.video.id, res)) return
69 // ---------------------------------------------------------------------------
72 videosBlacklistAddValidator,
73 videosBlacklistRemoveValidator,
74 videosBlacklistUpdateValidator