]>
Commit | Line | Data |
---|---|---|
453e83ea C |
1 | import * as express from 'express' |
2 | import { VideoChannelModel } from '../../models/video/video-channel' | |
0283eaac | 3 | import { MChannelAccountDefault } from '@server/typings/models' |
3e753302 | 4 | |
453e83ea C |
5 | async 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 |
11 | async 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 | ||
17 | async 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 | ||
25 | export { | |
453e83ea C |
26 | doesLocalVideoChannelNameExist, |
27 | doesVideoChannelIdExist, | |
28 | doesVideoChannelNameWithHostExist | |
29 | } | |
30 | ||
0283eaac | 31 | function 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 | } |