aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/video-channels.ts')
-rw-r--r--server/helpers/custom-validators/video-channels.ts33
1 files changed, 27 insertions, 6 deletions
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts
index 5de01f74b..267d987fc 100644
--- a/server/helpers/custom-validators/video-channels.ts
+++ b/server/helpers/custom-validators/video-channels.ts
@@ -1,14 +1,14 @@
1import * as Promise from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as validator from 'validator'
3import * as express from 'express' 2import * as express from 'express'
4import 'express-validator' 3import 'express-validator'
5import 'multer' 4import 'multer'
5import * as validator from 'validator'
6 6
7import { database as db, CONSTRAINTS_FIELDS } from '../../initializers' 7import { CONSTRAINTS_FIELDS, database as db } from '../../initializers'
8import { VideoChannelInstance } from '../../models' 8import { VideoChannelInstance } from '../../models'
9import { logger } from '../logger' 9import { logger } from '../logger'
10import { exists } from './misc'
11import { isActivityPubUrlValid } from './index' 10import { isActivityPubUrlValid } from './index'
11import { exists } from './misc'
12 12
13const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS 13const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
14 14
@@ -25,7 +25,7 @@ function isVideoChannelNameValid (value: string) {
25} 25}
26 26
27function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { 27function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) {
28 let promise: Promise<VideoChannelInstance> 28 let promise: Bluebird<VideoChannelInstance>
29 if (validator.isInt(id)) { 29 if (validator.isInt(id)) {
30 promise = db.VideoChannel.loadAndPopulateAccount(+id) 30 promise = db.VideoChannel.loadAndPopulateAccount(+id)
31 } else { // UUID 31 } else { // UUID
@@ -48,11 +48,32 @@ function checkVideoChannelExists (id: string, res: express.Response, callback: (
48 }) 48 })
49} 49}
50 50
51async function isVideoChannelExistsPromise (id: string, res: express.Response) {
52 let videoChannel: VideoChannelInstance
53 if (validator.isInt(id)) {
54 videoChannel = await db.VideoChannel.loadAndPopulateAccount(+id)
55 } else { // UUID
56 videoChannel = await db.VideoChannel.loadByUUIDAndPopulateAccount(id)
57 }
58
59 if (!videoChannel) {
60 res.status(404)
61 .json({ error: 'Video channel not found' })
62 .end()
63
64 return false
65 }
66
67 res.locals.videoChannel = videoChannel
68 return true
69}
70
51// --------------------------------------------------------------------------- 71// ---------------------------------------------------------------------------
52 72
53export { 73export {
54 isVideoChannelDescriptionValid, 74 isVideoChannelDescriptionValid,
55 isVideoChannelNameValid,
56 checkVideoChannelExists, 75 checkVideoChannelExists,
76 isVideoChannelNameValid,
77 isVideoChannelExistsPromise,
57 isVideoChannelUrlValid 78 isVideoChannelUrlValid
58} 79}