diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/accounts.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/actor.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 22 |
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 | ||
30 | const actorNameRegExp = new RegExp('[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_]+') | 30 | const actorNameRegExp = new RegExp('^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\\-_]+$') |
31 | function isActorPreferredUsernameValid (preferredUsername: string) { | 31 | function 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' | |||
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) { |