2019-08-15 11:53:26 +02:00
|
|
|
import * as express from 'express'
|
|
|
|
import { VideoChannelModel } from '../../models/video/video-channel'
|
2020-06-18 10:45:25 +02:00
|
|
|
import { MChannelAccountDefault } from '@server/types/models'
|
2020-12-07 14:32:36 +01:00
|
|
|
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
2019-07-23 10:40:39 +02:00
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
|
|
|
|
const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
|
2019-07-23 10:40:39 +02:00
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
return processVideoChannelExist(videoChannel, res)
|
|
|
|
}
|
2019-07-23 10:40:39 +02:00
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
async function doesVideoChannelIdExist (id: number, res: express.Response) {
|
|
|
|
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
|
2019-07-23 10:40:39 +02:00
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
return processVideoChannelExist(videoChannel, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
|
|
|
|
const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
|
|
|
|
|
|
|
|
return processVideoChannelExist(videoChannel, res)
|
2019-07-23 10:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2019-08-15 11:53:26 +02:00
|
|
|
doesLocalVideoChannelNameExist,
|
|
|
|
doesVideoChannelIdExist,
|
|
|
|
doesVideoChannelNameWithHostExist
|
|
|
|
}
|
|
|
|
|
2019-08-20 13:52:49 +02:00
|
|
|
function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) {
|
2019-08-15 11:53:26 +02:00
|
|
|
if (!videoChannel) {
|
2020-12-07 14:32:36 +01:00
|
|
|
res.status(HttpStatusCode.NOT_FOUND_404)
|
2019-08-15 11:53:26 +02:00
|
|
|
.json({ error: 'Video channel not found' })
|
|
|
|
.end()
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoChannel = videoChannel
|
|
|
|
return true
|
2019-07-23 10:40:39 +02:00
|
|
|
}
|