1 import * as express from 'express'
2 import { VideoChannelModel } from '../../models/video/video-channel'
3 import { MChannelAccountDefault } from '@server/types/models'
4 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
6 async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
7 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
9 return processVideoChannelExist(videoChannel, res)
12 async function doesVideoChannelIdExist (id: number, res: express.Response) {
13 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
15 return processVideoChannelExist(videoChannel, res)
18 async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
19 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
21 return processVideoChannelExist(videoChannel, res)
24 // ---------------------------------------------------------------------------
27 doesLocalVideoChannelNameExist,
28 doesVideoChannelIdExist,
29 doesVideoChannelNameWithHostExist
32 function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) {
34 res.status(HttpStatusCode.NOT_FOUND_404)
35 .json({ error: 'Video channel not found' })
41 res.locals.videoChannel = videoChannel