PeerTube/server/middlewares/validators/shared/video-channels.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-08-27 14:32:44 +02:00
import express from 'express'
import { VideoChannelModel } from '@server/models/video/video-channel'
2021-04-06 17:01:35 +02:00
import { MChannelBannerAccountDefault } from '@server/types/models'
2021-07-16 10:42:24 +02:00
import { HttpStatusCode } from '@shared/models'
2019-07-23 10:40:39 +02:00
async function doesVideoChannelIdExist (id: number, res: express.Response) {
2019-08-15 11:53:26 +02:00
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
2019-07-23 10:40:39 +02:00
return processVideoChannelExist(videoChannel, res)
2019-08-15 11:53:26 +02:00
}
async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
2019-08-15 11:53:26 +02:00
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
doesVideoChannelIdExist,
doesVideoChannelNameWithHostExist
}
function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) {
2019-08-15 11:53:26 +02:00
if (!videoChannel) {
res.fail({
status: HttpStatusCode.NOT_FOUND_404,
message: 'Video channel not found'
})
2019-08-15 11:53:26 +02:00
return false
}
res.locals.videoChannel = videoChannel
return true
2019-07-23 10:40:39 +02:00
}