diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/video-accounts.ts | 8 | ||||
-rw-r--r-- | server/helpers/utils.ts | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/video-accounts.ts b/server/helpers/custom-validators/video-accounts.ts index 3f3e9edd1..31808ae1e 100644 --- a/server/helpers/custom-validators/video-accounts.ts +++ b/server/helpers/custom-validators/video-accounts.ts | |||
@@ -8,11 +8,18 @@ import { AccountInstance } from '../../models' | |||
8 | import { logger } from '../logger' | 8 | import { logger } from '../logger' |
9 | 9 | ||
10 | import { isUserUsernameValid } from './users' | 10 | import { isUserUsernameValid } from './users' |
11 | import { isHostValid } from './pods' | ||
11 | 12 | ||
12 | function isVideoAccountNameValid (value: string) { | 13 | function isVideoAccountNameValid (value: string) { |
13 | return isUserUsernameValid(value) | 14 | return isUserUsernameValid(value) |
14 | } | 15 | } |
15 | 16 | ||
17 | function isAccountNameWithHostValid (value: string) { | ||
18 | const [ name, host ] = value.split('@') | ||
19 | |||
20 | return isVideoAccountNameValid(name) && isHostValid(host) | ||
21 | } | ||
22 | |||
16 | function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) { | 23 | function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) { |
17 | let promise: Promise<AccountInstance> | 24 | let promise: Promise<AccountInstance> |
18 | if (validator.isInt(id)) { | 25 | if (validator.isInt(id)) { |
@@ -41,5 +48,6 @@ function checkVideoAccountExists (id: string, res: express.Response, callback: ( | |||
41 | 48 | ||
42 | export { | 49 | export { |
43 | checkVideoAccountExists, | 50 | checkVideoAccountExists, |
51 | isAccountNameWithHostValid, | ||
44 | isVideoAccountNameValid | 52 | isVideoAccountNameValid |
45 | } | 53 | } |
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 0ebbf48a8..39957c90f 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -5,6 +5,7 @@ import { pseudoRandomBytesPromise } from './core-utils' | |||
5 | import { CONFIG, database as db } from '../initializers' | 5 | import { CONFIG, database as db } from '../initializers' |
6 | import { ResultList } from '../../shared' | 6 | import { ResultList } from '../../shared' |
7 | import { VideoResolution } from '../../shared/models/videos/video-resolution.enum' | 7 | import { VideoResolution } from '../../shared/models/videos/video-resolution.enum' |
8 | import { AccountInstance } from '../models/account/account-interface' | ||
8 | 9 | ||
9 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { | 10 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { |
10 | return res.type('json').status(400).end() | 11 | return res.type('json').status(400).end() |
@@ -78,6 +79,15 @@ function resetSequelizeInstance (instance: Sequelize.Instance<any>, savedFields: | |||
78 | }) | 79 | }) |
79 | } | 80 | } |
80 | 81 | ||
82 | let applicationAccount: AccountInstance | ||
83 | async function getApplicationAccount () { | ||
84 | if (applicationAccount === undefined) { | ||
85 | applicationAccount = await db.Account.loadApplication() | ||
86 | } | ||
87 | |||
88 | return Promise.resolve(applicationAccount) | ||
89 | } | ||
90 | |||
81 | type SortType = { sortModel: any, sortValue: string } | 91 | type SortType = { sortModel: any, sortValue: string } |
82 | 92 | ||
83 | // --------------------------------------------------------------------------- | 93 | // --------------------------------------------------------------------------- |
@@ -89,5 +99,6 @@ export { | |||
89 | isSignupAllowed, | 99 | isSignupAllowed, |
90 | computeResolutionsToTranscode, | 100 | computeResolutionsToTranscode, |
91 | resetSequelizeInstance, | 101 | resetSequelizeInstance, |
102 | getApplicationAccount, | ||
92 | SortType | 103 | SortType |
93 | } | 104 | } |