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