aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-25 16:03:33 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commitf5028693a896a3076dd286ac0030e3d8f78f5ebf (patch)
tree09144ed6357e49ea575fb110247f933283ad235e /server/helpers/utils.ts
parenteb08047657e739bcd9e592d76307befa3998482b (diff)
downloadPeerTube-f5028693a896a3076dd286ac0030e3d8f78f5ebf.tar.gz
PeerTube-f5028693a896a3076dd286ac0030e3d8f78f5ebf.tar.zst
PeerTube-f5028693a896a3076dd286ac0030e3d8f78f5ebf.zip
Use async/await in lib and initializers
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r--server/helpers/utils.ts20
1 files changed, 11 insertions, 9 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 6cabe117c..8b81a61e1 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -8,11 +8,13 @@ import { ResultList } from '../../shared'
8import { VideoResolution } from '../../shared/models/videos/video-resolution.enum' 8import { VideoResolution } from '../../shared/models/videos/video-resolution.enum'
9 9
10function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { 10function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) {
11 res.type('json').status(400).end() 11 return res.type('json').status(400).end()
12} 12}
13 13
14function generateRandomString (size: number) { 14async function generateRandomString (size: number) {
15 return pseudoRandomBytesPromise(size).then(raw => raw.toString('hex')) 15 const raw = await pseudoRandomBytesPromise(size)
16
17 return raw.toString('hex')
16} 18}
17 19
18interface FormattableToJSON { 20interface FormattableToJSON {
@@ -34,19 +36,19 @@ function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], obje
34 return res 36 return res
35} 37}
36 38
37function isSignupAllowed () { 39async function isSignupAllowed () {
38 if (CONFIG.SIGNUP.ENABLED === false) { 40 if (CONFIG.SIGNUP.ENABLED === false) {
39 return Promise.resolve(false) 41 return false
40 } 42 }
41 43
42 // No limit and signup is enabled 44 // No limit and signup is enabled
43 if (CONFIG.SIGNUP.LIMIT === -1) { 45 if (CONFIG.SIGNUP.LIMIT === -1) {
44 return Promise.resolve(true) 46 return true
45 } 47 }
46 48
47 return db.User.countTotal().then(totalUsers => { 49 const totalUsers = await db.User.countTotal()
48 return totalUsers < CONFIG.SIGNUP.LIMIT 50
49 }) 51 return totalUsers < CONFIG.SIGNUP.LIMIT
50} 52}
51 53
52function computeResolutionsToTranscode (videoFileHeight: number) { 54function computeResolutionsToTranscode (videoFileHeight: number) {