1 import * as express from 'express'
2 import 'express-validator'
4 import * as validator from 'validator'
5 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
6 import { VideoChannelModel } from '../../models/video/video-channel'
7 import { exists } from './misc'
9 const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
11 function isVideoChannelDescriptionValid (value: string) {
12 return value === null || validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.DESCRIPTION)
15 function isVideoChannelNameValid (value: string) {
16 return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME)
19 function isVideoChannelSupportValid (value: string) {
20 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
23 async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
24 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
26 return processVideoChannelExist(videoChannel, res)
29 async function doesVideoChannelIdExist (id: number, res: express.Response) {
30 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
32 return processVideoChannelExist(videoChannel, res)
35 async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
36 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
38 return processVideoChannelExist(videoChannel, res)
41 // ---------------------------------------------------------------------------
44 doesVideoChannelNameWithHostExist,
45 doesLocalVideoChannelNameExist,
46 isVideoChannelDescriptionValid,
47 isVideoChannelNameValid,
48 isVideoChannelSupportValid,
49 doesVideoChannelIdExist
52 function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {
59 res.locals.videoChannel = videoChannel