]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/shared/video-channels.ts
Fix video right check
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / shared / video-channels.ts
CommitLineData
41fb13c3 1import express from 'express'
10363c74 2import { VideoChannelModel } from '@server/models/video/video-channel'
2cb03dc1 3import { MChannelBannerAccountDefault } from '@server/types/models'
c0e8b12e 4import { HttpStatusCode } from '@shared/models'
3e753302 5
012580d9 6async function doesVideoChannelIdExist (id: number, res: express.Response) {
453e83ea 7 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
3e753302 8
012580d9 9 return processVideoChannelExist(videoChannel, res)
453e83ea
C
10}
11
012580d9 12async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
453e83ea
C
13 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
14
012580d9 15 return processVideoChannelExist(videoChannel, res)
3e753302
C
16}
17
18// ---------------------------------------------------------------------------
19
20export {
453e83ea
C
21 doesVideoChannelIdExist,
22 doesVideoChannelNameWithHostExist
23}
24
012580d9 25function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) {
453e83ea 26 if (!videoChannel) {
76148b27
RK
27 res.fail({
28 status: HttpStatusCode.NOT_FOUND_404,
29 message: 'Video channel not found'
30 })
453e83ea
C
31 return false
32 }
33
34 res.locals.videoChannel = videoChannel
35 return true
3e753302 36}