1 import express from 'express'
2 import { body, query } from 'express-validator'
3 import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
4 import { isBooleanValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
5 import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
6 import { areValidationErrors, doesVideoBlacklistExist, doesVideoExist, isValidVideoIdParam } from '../shared'
8 const videosBlacklistRemoveValidator = [
9 isValidVideoIdParam('videoId'),
11 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 if (areValidationErrors(req, res)) return
13 if (!await doesVideoExist(req.params.videoId, res)) return
14 if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return
20 const videosBlacklistAddValidator = [
21 isValidVideoIdParam('videoId'),
25 .customSanitizer(toBooleanOrNull)
26 .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
29 .custom(isVideoBlacklistReasonValid),
31 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
32 if (areValidationErrors(req, res)) return
33 if (!await doesVideoExist(req.params.videoId, res)) return
35 const video = res.locals.videoAll
36 if (req.body.unfederate === true && video.remote === true) {
38 status: HttpStatusCode.CONFLICT_409,
39 message: 'You cannot unfederate a remote video.'
47 const videosBlacklistUpdateValidator = [
48 isValidVideoIdParam('videoId'),
52 .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
54 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
55 if (areValidationErrors(req, res)) return
56 if (!await doesVideoExist(req.params.videoId, res)) return
57 if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return
63 const videosBlacklistFiltersValidator = [
66 .customSanitizer(toIntOrNull)
67 .custom(isVideoBlacklistTypeValid).withMessage('Should have a valid video blacklist type attribute'),
71 .isEmpty().withMessage('Should have a valid search'),
73 (req: express.Request, res: express.Response, next: express.NextFunction) => {
74 if (areValidationErrors(req, res)) return
80 // ---------------------------------------------------------------------------
83 videosBlacklistAddValidator,
84 videosBlacklistRemoveValidator,
85 videosBlacklistUpdateValidator,
86 videosBlacklistFiltersValidator