2021-08-27 08:32:44 -04:00
|
|
|
import express from 'express'
|
2021-06-03 11:33:44 -04:00
|
|
|
import { VideoChannelModel } from '@server/models/video/video-channel'
|
2021-04-06 11:01:35 -04:00
|
|
|
import { MChannelBannerAccountDefault } from '@server/types/models'
|
2021-07-16 04:42:24 -04:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2019-07-23 04:40:39 -04:00
|
|
|
|
2021-05-28 04:21:39 -04:00
|
|
|
async function doesVideoChannelIdExist (id: number, res: express.Response) {
|
2019-08-15 05:53:26 -04:00
|
|
|
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
|
2019-07-23 04:40:39 -04:00
|
|
|
|
2021-05-28 04:21:39 -04:00
|
|
|
return processVideoChannelExist(videoChannel, res)
|
2019-08-15 05:53:26 -04:00
|
|
|
}
|
|
|
|
|
2021-05-28 04:21:39 -04:00
|
|
|
async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
|
2019-08-15 05:53:26 -04:00
|
|
|
const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
|
|
|
|
|
2021-05-28 04:21:39 -04:00
|
|
|
return processVideoChannelExist(videoChannel, res)
|
2019-07-23 04:40:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2019-08-15 05:53:26 -04:00
|
|
|
doesVideoChannelIdExist,
|
|
|
|
doesVideoChannelNameWithHostExist
|
|
|
|
}
|
|
|
|
|
2021-05-28 04:21:39 -04:00
|
|
|
function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) {
|
2019-08-15 05:53:26 -04:00
|
|
|
if (!videoChannel) {
|
2021-05-31 19:36:53 -04:00
|
|
|
res.fail({
|
|
|
|
status: HttpStatusCode.NOT_FOUND_404,
|
|
|
|
message: 'Video channel not found'
|
|
|
|
})
|
2019-08-15 05:53:26 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoChannel = videoChannel
|
|
|
|
return true
|
2019-07-23 04:40:39 -04:00
|
|
|
}
|