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