]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/middlewares/video-channels.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / video-channels.ts
1 import * as express from 'express'
2 import { VideoChannelModel } from '../../models/video/video-channel'
3 import { MChannelAccountDefault } from '@server/typings/models'
4
5 async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
6 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
7
8 return processVideoChannelExist(videoChannel, res)
9 }
10
11 async function doesVideoChannelIdExist (id: number, res: express.Response) {
12 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
13
14 return processVideoChannelExist(videoChannel, res)
15 }
16
17 async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
18 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
19
20 return processVideoChannelExist(videoChannel, res)
21 }
22
23 // ---------------------------------------------------------------------------
24
25 export {
26 doesLocalVideoChannelNameExist,
27 doesVideoChannelIdExist,
28 doesVideoChannelNameWithHostExist
29 }
30
31 function 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 }