X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Futils.ts;h=3af14a68a51182ba16d81564d8ec2ffdc94d175a;hb=0f91ae62df8a37194fea84ce1efa9e733d9c1fd8;hp=8b81a61e173046d41a48c5067a52eeb68999476d;hpb=f5028693a896a3076dd286ac0030e3d8f78f5ebf;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 8b81a61e1..3af14a68a 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -1,11 +1,12 @@ import * as express from 'express' import * as Sequelize from 'sequelize' -import * as Promise from 'bluebird' 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' +import { logger } from './logger' function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { return res.type('json').status(400).end() @@ -79,6 +80,20 @@ function resetSequelizeInstance (instance: Sequelize.Instance, savedFields: }) } +let serverAccount: AccountInstance +async function getServerAccount () { + if (serverAccount === undefined) { + serverAccount = await db.Account.loadApplication() + } + + if (!serverAccount) { + logger.error('Cannot load server account.') + process.exit(0) + } + + return Promise.resolve(serverAccount) +} + type SortType = { sortModel: any, sortValue: string } // --------------------------------------------------------------------------- @@ -90,5 +105,6 @@ export { isSignupAllowed, computeResolutionsToTranscode, resetSequelizeInstance, + getServerAccount, SortType }