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.ts22
1 files changed, 16 insertions, 6 deletions
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts
index 32faf36f7..f13519c1d 100644
--- a/server/helpers/custom-validators/video-channels.ts
+++ b/server/helpers/custom-validators/video-channels.ts
@@ -2,10 +2,9 @@ import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import 'multer' 3import 'multer'
4import * as validator from 'validator' 4import * as validator from 'validator'
5import { CONSTRAINTS_FIELDS } from '../../initializers' 5import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
6import { VideoChannelModel } from '../../models/video/video-channel' 6import { VideoChannelModel } from '../../models/video/video-channel'
7import { exists } from './misc' 7import { exists } from './misc'
8import { Response } from 'express'
9 8
10const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS 9const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
11 10
@@ -21,13 +20,13 @@ function isVideoChannelSupportValid (value: string) {
21 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) 20 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
22} 21}
23 22
24async function isLocalVideoChannelNameExist (name: string, res: Response) { 23async function isLocalVideoChannelNameExist (name: string, res: express.Response) {
25 const videoChannel = await VideoChannelModel.loadLocalByName(name) 24 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
26 25
27 return processVideoChannelExist(videoChannel, res) 26 return processVideoChannelExist(videoChannel, res)
28} 27}
29 28
30async function isVideoChannelExist (id: string, res: express.Response) { 29async function isVideoChannelIdExist (id: string, res: express.Response) {
31 let videoChannel: VideoChannelModel 30 let videoChannel: VideoChannelModel
32 if (validator.isInt(id)) { 31 if (validator.isInt(id)) {
33 videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) 32 videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
@@ -38,14 +37,25 @@ async function isVideoChannelExist (id: string, res: express.Response) {
38 return processVideoChannelExist(videoChannel, res) 37 return processVideoChannelExist(videoChannel, res)
39} 38}
40 39
40async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
41 const [ name, host ] = nameWithDomain.split('@')
42 let videoChannel: VideoChannelModel
43
44 if (!host || host === CONFIG.WEBSERVER.HOST) videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
45 else videoChannel = await VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
46
47 return processVideoChannelExist(videoChannel, res)
48}
49
41// --------------------------------------------------------------------------- 50// ---------------------------------------------------------------------------
42 51
43export { 52export {
53 isVideoChannelNameWithHostExist,
44 isLocalVideoChannelNameExist, 54 isLocalVideoChannelNameExist,
45 isVideoChannelDescriptionValid, 55 isVideoChannelDescriptionValid,
46 isVideoChannelNameValid, 56 isVideoChannelNameValid,
47 isVideoChannelSupportValid, 57 isVideoChannelSupportValid,
48 isVideoChannelExist 58 isVideoChannelIdExist
49} 59}
50 60
51function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { 61function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {