]>
Commit | Line | Data |
---|---|---|
453e83ea | 1 | import * as express from 'express' |
2cb03dc1 | 2 | import { MChannelBannerAccountDefault } from '@server/types/models' |
2d53be02 | 3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
2cb03dc1 | 4 | import { VideoChannelModel } from '../../models/video/video-channel' |
3e753302 | 5 | |
012580d9 | 6 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { |
453e83ea | 7 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) |
3e753302 | 8 | |
012580d9 | 9 | return processVideoChannelExist(videoChannel, res) |
453e83ea | 10 | } |
3e753302 | 11 | |
012580d9 | 12 | async function doesVideoChannelIdExist (id: number, res: express.Response) { |
453e83ea | 13 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) |
3e753302 | 14 | |
012580d9 | 15 | return processVideoChannelExist(videoChannel, res) |
453e83ea C |
16 | } |
17 | ||
012580d9 | 18 | async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { |
453e83ea C |
19 | const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) |
20 | ||
012580d9 | 21 | return processVideoChannelExist(videoChannel, res) |
3e753302 C |
22 | } |
23 | ||
24 | // --------------------------------------------------------------------------- | |
25 | ||
26 | export { | |
453e83ea C |
27 | doesLocalVideoChannelNameExist, |
28 | doesVideoChannelIdExist, | |
29 | doesVideoChannelNameWithHostExist | |
30 | } | |
31 | ||
012580d9 | 32 | function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) { |
453e83ea | 33 | if (!videoChannel) { |
012580d9 C |
34 | res.status(HttpStatusCode.NOT_FOUND_404) |
35 | .json({ error: 'Video channel not found' }) | |
453e83ea C |
36 | |
37 | return false | |
38 | } | |
39 | ||
40 | res.locals.videoChannel = videoChannel | |
41 | return true | |
3e753302 | 42 | } |