From 7a7724e66e4533523083e7336cd0d0c747c4a33b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 13 Nov 2017 17:39:41 +0100 Subject: Handle follow/accept --- server/helpers/custom-validators/video-accounts.ts | 8 ++++++++ server/helpers/utils.ts | 11 +++++++++++ 2 files changed, 19 insertions(+) (limited to 'server/helpers') 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' import { logger } from '../logger' import { isUserUsernameValid } from './users' +import { isHostValid } from './pods' function isVideoAccountNameValid (value: string) { return isUserUsernameValid(value) } +function isAccountNameWithHostValid (value: string) { + const [ name, host ] = value.split('@') + + return isVideoAccountNameValid(name) && isHostValid(host) +} + function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) { let promise: Promise if (validator.isInt(id)) { @@ -41,5 +48,6 @@ function checkVideoAccountExists (id: string, res: express.Response, callback: ( export { checkVideoAccountExists, + isAccountNameWithHostValid, isVideoAccountNameValid } 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' import { CONFIG, database as db } from '../initializers' import { ResultList } from '../../shared' import { VideoResolution } from '../../shared/models/videos/video-resolution.enum' +import { AccountInstance } from '../models/account/account-interface' function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { return res.type('json').status(400).end() @@ -78,6 +79,15 @@ function resetSequelizeInstance (instance: Sequelize.Instance, savedFields: }) } +let applicationAccount: AccountInstance +async function getApplicationAccount () { + if (applicationAccount === undefined) { + applicationAccount = await db.Account.loadApplication() + } + + return Promise.resolve(applicationAccount) +} + type SortType = { sortModel: any, sortValue: string } // --------------------------------------------------------------------------- @@ -89,5 +99,6 @@ export { isSignupAllowed, computeResolutionsToTranscode, resetSequelizeInstance, + getApplicationAccount, SortType } -- cgit v1.2.3