1
0
Fork 0
peertube/server/helpers/middlewares/video-channels.ts

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-08-15 05:53:26 -04:00
import * as express from 'express'
import { VideoChannelModel } from '../../models/video/video-channel'
2019-08-20 07:52:49 -04:00
import { MChannelAccountDefault } from '@server/typings/models'
2019-07-23 04:40:39 -04:00
2019-08-15 05:53:26 -04:00
async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
2019-07-23 04:40:39 -04:00
2019-08-15 05:53:26 -04:00
return processVideoChannelExist(videoChannel, res)
}
2019-07-23 04:40:39 -04:00
2019-08-15 05:53:26 -04:00
async function doesVideoChannelIdExist (id: number, res: express.Response) {
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
2019-07-23 04:40:39 -04:00
2019-08-15 05:53:26 -04: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 04:40:39 -04:00
}
// ---------------------------------------------------------------------------
export {
2019-08-15 05:53:26 -04:00
doesLocalVideoChannelNameExist,
doesVideoChannelIdExist,
doesVideoChannelNameWithHostExist
}
2019-08-20 07:52:49 -04:00
function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) {
2019-08-15 05:53:26 -04:00
if (!videoChannel) {
res.status(404)
.json({ error: 'Video channel not found' })
.end()
return false
}
res.locals.videoChannel = videoChannel
return true
2019-07-23 04:40:39 -04:00
}