]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/helpers/middlewares/video-channels.ts
Fix is managaeble for channels
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / video-channels.ts
... / ...
CommitLineData
1import * as express from 'express'
2import { VideoChannelModel } from '../../models/video/video-channel'
3import { MChannelAccountDefault } from '@server/typings/models'
4
5async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
6 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
7
8 return processVideoChannelExist(videoChannel, res)
9}
10
11async function doesVideoChannelIdExist (id: number, res: express.Response) {
12 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
13
14 return processVideoChannelExist(videoChannel, res)
15}
16
17async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
18 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
19
20 return processVideoChannelExist(videoChannel, res)
21}
22
23// ---------------------------------------------------------------------------
24
25export {
26 doesLocalVideoChannelNameExist,
27 doesVideoChannelIdExist,
28 doesVideoChannelNameWithHostExist
29}
30
31function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) {
32 if (!videoChannel) {
33 res.status(404)
34 .json({ error: 'Video channel not found' })
35 .end()
36
37 return false
38 }
39
40 res.locals.videoChannel = videoChannel
41 return true
42}