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