1 import { Response } from 'express'
2 import * as validator from 'validator'
3 import { exists } from './misc'
4 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5 import { VideoBlacklistModel } from '../../models/video/video-blacklist'
6 import { VideoBlacklistType } from '../../../shared/models/videos'
8 const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST
10 function isVideoBlacklistReasonValid (value: string) {
11 return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
14 async function doesVideoBlacklistExist (videoId: number, res: Response) {
15 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
17 if (videoBlacklist === null) {
19 .json({ error: 'Blacklisted video not found' })
25 res.locals.videoBlacklist = videoBlacklist
29 function isVideoBlacklistTypeValid (value: any) {
30 return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
33 // ---------------------------------------------------------------------------
36 isVideoBlacklistReasonValid,
37 isVideoBlacklistTypeValid,
38 doesVideoBlacklistExist