X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Futils.ts;h=af5be0c69dcbc40b845c22bcd82b7c90d122d956;hb=6599f096d5a26f2cc9624359d92cc501ec189586;hp=9c08afb711af7329863d0dd385608ae7f9a46b31;hpb=075f16caac5236cb04c98ae7b3a989766d764bb3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 9c08afb71..af5be0c69 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -1,6 +1,8 @@ import * as express from 'express' +import * as Promise from 'bluebird' import { pseudoRandomBytesPromise } from './core-utils' +import { CONFIG, database as db } from '../initializers' import { ResultList } from '../../shared' function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { @@ -12,28 +14,44 @@ function generateRandomString (size: number) { } interface FormatableToJSON { - toFormatedJSON () + toFormattedJSON () } -function getFormatedObjects (objects: T[], objectsTotal: number) { - const formatedObjects: U[] = [] +function getFormattedObjects (objects: T[], objectsTotal: number) { + const formattedObjects: U[] = [] objects.forEach(object => { - formatedObjects.push(object.toFormatedJSON()) + formattedObjects.push(object.toFormattedJSON()) }) const res: ResultList = { total: objectsTotal, - data: formatedObjects + data: formattedObjects } return res } +function isSignupAllowed () { + if (CONFIG.SIGNUP.ENABLED === false) { + return Promise.resolve(false) + } + + // No limit and signup is enabled + if (CONFIG.SIGNUP.LIMIT === -1) { + return Promise.resolve(true) + } + + return db.User.countTotal().then(totalUsers => { + return totalUsers < CONFIG.SIGNUP.LIMIT + }) +} + // --------------------------------------------------------------------------- export { badRequest, generateRandomString, - getFormatedObjects + getFormattedObjects, + isSignupAllowed }