2019-08-15 09:53:26 +00:00
|
|
|
import * as express from 'express'
|
2021-04-06 15:01:35 +00:00
|
|
|
import { MChannelBannerAccountDefault } from '@server/types/models'
|
2020-12-07 13:32:36 +00:00
|
|
|
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
2021-04-06 15:01:35 +00:00
|
|
|
import { VideoChannelModel } from '../../models/video/video-channel'
|
2019-07-23 08:40:39 +00:00
|
|
|
|
2021-05-28 08:21:39 +00:00
|
|
|
async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
|
2019-08-15 09:53:26 +00:00
|
|
|
const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
|
2019-07-23 08:40:39 +00:00
|
|
|
|
2021-05-28 08:21:39 +00:00
|
|
|
return processVideoChannelExist(videoChannel, res)
|
2019-08-15 09:53:26 +00:00
|
|
|
}
|
2019-07-23 08:40:39 +00:00
|
|
|
|
2021-05-28 08:21:39 +00:00
|
|
|
async function doesVideoChannelIdExist (id: number, res: express.Response) {
|
2019-08-15 09:53:26 +00:00
|
|
|
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
|
2019-07-23 08:40:39 +00:00
|
|
|
|
2021-05-28 08:21:39 +00:00
|
|
|
return processVideoChannelExist(videoChannel, res)
|
2019-08-15 09:53:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 08:21:39 +00:00
|
|
|
async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
|
2019-08-15 09:53:26 +00:00
|
|
|
const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
|
|
|
|
|
2021-05-28 08:21:39 +00:00
|
|
|
return processVideoChannelExist(videoChannel, res)
|
2019-07-23 08:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2019-08-15 09:53:26 +00:00
|
|
|
doesLocalVideoChannelNameExist,
|
|
|
|
doesVideoChannelIdExist,
|
|
|
|
doesVideoChannelNameWithHostExist
|
|
|
|
}
|
|
|
|
|
2021-05-28 08:21:39 +00:00
|
|
|
function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) {
|
2019-08-15 09:53:26 +00:00
|
|
|
if (!videoChannel) {
|
2021-05-31 23:36:53 +00:00
|
|
|
res.fail({
|
|
|
|
status: HttpStatusCode.NOT_FOUND_404,
|
|
|
|
message: 'Video channel not found'
|
|
|
|
})
|
2019-08-15 09:53:26 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoChannel = videoChannel
|
|
|
|
return true
|
2019-07-23 08:40:39 +00:00
|
|
|
}
|