aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/middlewares/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/middlewares/video-channels.ts')
-rw-r--r--server/helpers/middlewares/video-channels.ts45
1 files changed, 32 insertions, 13 deletions
diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts
index 1b573ca37..17b7692c5 100644
--- a/server/helpers/middlewares/video-channels.ts
+++ b/server/helpers/middlewares/video-channels.ts
@@ -1,23 +1,42 @@
1import { Response } from 'express' 1import * as express from 'express'
2import { VideoAbuseModel } from '../../models/video/video-abuse' 2import { VideoChannelModel } from '../../models/video/video-channel'
3import { MChannelActorAccountDefault } from '../../typings/models'
3 4
4async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { 5async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
5 const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) 6 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
6 7
7 if (videoAbuse === null) { 8 return processVideoChannelExist(videoChannel, res)
8 res.status(404) 9}
9 .json({ error: 'Video abuse not found' })
10 .end()
11 10
12 return false 11async function doesVideoChannelIdExist (id: number, res: express.Response) {
13 } 12 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
14 13
15 res.locals.videoAbuse = videoAbuse 14 return processVideoChannelExist(videoChannel, res)
16 return true 15}
16
17async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
18 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
19
20 return processVideoChannelExist(videoChannel, res)
17} 21}
18 22
19// --------------------------------------------------------------------------- 23// ---------------------------------------------------------------------------
20 24
21export { 25export {
22 doesVideoAbuseExist 26 doesLocalVideoChannelNameExist,
27 doesVideoChannelIdExist,
28 doesVideoChannelNameWithHostExist
29}
30
31function processVideoChannelExist (videoChannel: MChannelActorAccountDefault, res: express.Response) {
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
23} 42}