]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/shared/video-channels.ts
Made the video channels limit (per user) server-wide configurable (#4491)
[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 doesLocalVideoChannelNameExist (name: string, res: express.Response) {
453e83ea 7 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
3e753302 8
012580d9 9 return processVideoChannelExist(videoChannel, res)
453e83ea 10}
3e753302 11
012580d9 12async function doesVideoChannelIdExist (id: number, res: express.Response) {
453e83ea 13 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
3e753302 14
012580d9 15 return processVideoChannelExist(videoChannel, res)
453e83ea
C
16}
17
012580d9 18async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
453e83ea
C
19 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
20
012580d9 21 return processVideoChannelExist(videoChannel, res)
3e753302
C
22}
23
24// ---------------------------------------------------------------------------
25
26export {
453e83ea
C
27 doesLocalVideoChannelNameExist,
28 doesVideoChannelIdExist,
29 doesVideoChannelNameWithHostExist
30}
31
012580d9 32function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) {
453e83ea 33 if (!videoChannel) {
76148b27
RK
34 res.fail({
35 status: HttpStatusCode.NOT_FOUND_404,
36 message: 'Video channel not found'
37 })
453e83ea
C
38 return false
39 }
40
41 res.locals.videoChannel = videoChannel
42 return true
3e753302 43}