diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-17 15:45:42 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | 8a19bee1a1ee39f973bb37429e4f73c3f2873cdb (patch) | |
tree | 33c93ef19451d7e46d4be74ce0681359d2dcc70e /server/helpers/custom-validators/video-channels.ts | |
parent | 965c4b22d0e4d2f853501e844e6ebbb861bd389d (diff) | |
download | PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.gz PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.zst PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.zip |
Add ability to set a name to a channel
Diffstat (limited to 'server/helpers/custom-validators/video-channels.ts')
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 22 |
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' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import 'multer' | 3 | import 'multer' |
4 | import * as validator from 'validator' | 4 | import * as validator from 'validator' |
5 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 5 | import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' |
6 | import { VideoChannelModel } from '../../models/video/video-channel' | 6 | import { VideoChannelModel } from '../../models/video/video-channel' |
7 | import { exists } from './misc' | 7 | import { exists } from './misc' |
8 | import { Response } from 'express' | ||
9 | 8 | ||
10 | const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS | 9 | const 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 | ||
24 | async function isLocalVideoChannelNameExist (name: string, res: Response) { | 23 | async 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 | ||
30 | async function isVideoChannelExist (id: string, res: express.Response) { | 29 | async 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 | ||
40 | async 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 | ||
43 | export { | 52 | export { |
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 | ||
51 | function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { | 61 | function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { |