]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/custom-validators/video-blacklist.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / video-blacklist.ts
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'
7
8 const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST
9
10 function isVideoBlacklistReasonValid (value: string) {
11 return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
12 }
13
14 async function doesVideoBlacklistExist (videoId: number, res: Response) {
15 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
16
17 if (videoBlacklist === null) {
18 res.status(404)
19 .json({ error: 'Blacklisted video not found' })
20 .end()
21
22 return false
23 }
24
25 res.locals.videoBlacklist = videoBlacklist
26 return true
27 }
28
29 function isVideoBlacklistTypeValid (value: any) {
30 return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
31 }
32
33 // ---------------------------------------------------------------------------
34
35 export {
36 isVideoBlacklistReasonValid,
37 isVideoBlacklistTypeValid,
38 doesVideoBlacklistExist
39 }