]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/middlewares/video-channels.ts
Remove uneccessary details to link titles
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / video-channels.ts
CommitLineData
453e83ea
C
1import * as express from 'express'
2import { VideoChannelModel } from '../../models/video/video-channel'
0283eaac 3import { MChannelAccountDefault } from '@server/typings/models'
3e753302 4
453e83ea
C
5async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
6 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
3e753302 7
453e83ea
C
8 return processVideoChannelExist(videoChannel, res)
9}
3e753302 10
453e83ea
C
11async function doesVideoChannelIdExist (id: number, res: express.Response) {
12 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
3e753302 13
453e83ea
C
14 return processVideoChannelExist(videoChannel, res)
15}
16
17async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
18 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
19
20 return processVideoChannelExist(videoChannel, res)
3e753302
C
21}
22
23// ---------------------------------------------------------------------------
24
25export {
453e83ea
C
26 doesLocalVideoChannelNameExist,
27 doesVideoChannelIdExist,
28 doesVideoChannelNameWithHostExist
29}
30
0283eaac 31function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) {
453e83ea
C
32 if (!videoChannel) {
33 res.status(404)
34 .json({ error: 'Video channel not found' })
35 .end()
36
37 return false
38 }
39
40 res.locals.videoChannel = videoChannel
41 return true
3e753302 42}