2018-08-13 16:57:13 +02:00
|
|
|
import { Response } from 'express'
|
|
|
|
import * as validator from 'validator'
|
2019-04-02 11:26:47 +02:00
|
|
|
import { exists } from './misc'
|
2019-04-11 14:26:41 +02:00
|
|
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
2018-08-13 16:57:13 +02:00
|
|
|
import { VideoBlacklistModel } from '../../models/video/video-blacklist'
|
2019-04-02 11:26:47 +02:00
|
|
|
import { VideoBlacklistType } from '../../../shared/models/videos'
|
2018-08-13 16:57:13 +02:00
|
|
|
|
|
|
|
const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST
|
|
|
|
|
|
|
|
function isVideoBlacklistReasonValid (value: string) {
|
|
|
|
return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
|
|
|
|
}
|
|
|
|
|
2019-03-19 09:26:50 +01:00
|
|
|
async function doesVideoBlacklistExist (videoId: number, res: Response) {
|
2018-08-13 16:57:13 +02:00
|
|
|
const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
|
|
|
|
|
|
|
|
if (videoBlacklist === null) {
|
|
|
|
res.status(404)
|
|
|
|
.json({ error: 'Blacklisted video not found' })
|
|
|
|
.end()
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoBlacklist = videoBlacklist
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:26:47 +02:00
|
|
|
function isVideoBlacklistTypeValid (value: any) {
|
|
|
|
return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:57:13 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isVideoBlacklistReasonValid,
|
2019-04-02 11:26:47 +02:00
|
|
|
isVideoBlacklistTypeValid,
|
2019-03-19 09:26:50 +01:00
|
|
|
doesVideoBlacklistExist
|
2018-08-13 16:57:13 +02:00
|
|
|
}
|