aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/accounts.ts2
-rw-r--r--server/helpers/custom-validators/activitypub/actor.ts2
-rw-r--r--server/helpers/custom-validators/video-channels.ts22
3 files changed, 18 insertions, 8 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts
index 0607d661c..191de1496 100644
--- a/server/helpers/custom-validators/accounts.ts
+++ b/server/helpers/custom-validators/accounts.ts
@@ -42,7 +42,7 @@ function isAccountNameWithHostExist (nameWithDomain: string, res: Response, send
42 42
43 let promise: Bluebird<AccountModel> 43 let promise: Bluebird<AccountModel>
44 if (!host || host === CONFIG.WEBSERVER.HOST) promise = AccountModel.loadLocalByName(accountName) 44 if (!host || host === CONFIG.WEBSERVER.HOST) promise = AccountModel.loadLocalByName(accountName)
45 else promise = AccountModel.loadLocalByNameAndHost(accountName, host) 45 else promise = AccountModel.loadByNameAndHost(accountName, host)
46 46
47 return isAccountExist(promise, res, sendNotFound) 47 return isAccountExist(promise, res, sendNotFound)
48} 48}
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
index ae5014f8f..c3a62c12d 100644
--- a/server/helpers/custom-validators/activitypub/actor.ts
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -27,7 +27,7 @@ function isActorPublicKeyValid (publicKey: string) {
27 validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY) 27 validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY)
28} 28}
29 29
30const actorNameRegExp = new RegExp('[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_]+') 30const actorNameRegExp = new RegExp('^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\\-_]+$')
31function isActorPreferredUsernameValid (preferredUsername: string) { 31function isActorPreferredUsernameValid (preferredUsername: string) {
32 return exists(preferredUsername) && validator.matches(preferredUsername, actorNameRegExp) 32 return exists(preferredUsername) && validator.matches(preferredUsername, actorNameRegExp)
33} 33}
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) {