1 import * as express from 'express'
2 import 'express-validator'
4 import * as validator from 'validator'
5 import { CONSTRAINTS_FIELDS } from '../../initializers'
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 async function isVideoChannelExist (id: string, res: express.Response) {
20 let videoChannel: VideoChannelModel
21 if (validator.isInt(id)) {
22 videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
24 videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id)
29 .json({ error: 'Video channel not found' })
35 res.locals.videoChannel = videoChannel
39 // ---------------------------------------------------------------------------
42 isVideoChannelDescriptionValid,
43 isVideoChannelNameValid,