]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/shared/video-channels.ts
Give moderators access to edit channels (#4608)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / shared / video-channels.ts
1 import express from 'express'
2 import { VideoChannelModel } from '@server/models/video/video-channel'
3 import { MChannelBannerAccountDefault } from '@server/types/models'
4 import { HttpStatusCode } from '@shared/models'
5
6 async function doesVideoChannelIdExist (id: number, res: express.Response) {
7 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
8
9 return processVideoChannelExist(videoChannel, res)
10 }
11
12 async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
13 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
14
15 return processVideoChannelExist(videoChannel, res)
16 }
17
18 // ---------------------------------------------------------------------------
19
20 export {
21 doesVideoChannelIdExist,
22 doesVideoChannelNameWithHostExist
23 }
24
25 function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) {
26 if (!videoChannel) {
27 res.fail({
28 status: HttpStatusCode.NOT_FOUND_404,
29 message: 'Video channel not found'
30 })
31 return false
32 }
33
34 res.locals.videoChannel = videoChannel
35 return true
36 }