diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-25 11:55:06 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | eb08047657e739bcd9e592d76307befa3998482b (patch) | |
tree | fc309f51ece792fd4307c4af510710a853e1d6b2 /server/controllers/api/config.ts | |
parent | 5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (diff) | |
download | PeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.gz PeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.zst PeerTube-eb08047657e739bcd9e592d76307befa3998482b.zip |
Use async/await in controllers
Diffstat (limited to 'server/controllers/api/config.ts')
-rw-r--r-- | server/controllers/api/config.ts | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index c9a051bdc..5f704f0ee 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -2,30 +2,32 @@ import * as express from 'express' | |||
2 | 2 | ||
3 | import { isSignupAllowed } from '../../helpers' | 3 | import { isSignupAllowed } from '../../helpers' |
4 | import { CONFIG } from '../../initializers' | 4 | import { CONFIG } from '../../initializers' |
5 | import { asyncMiddleware } from '../../middlewares' | ||
5 | import { ServerConfig } from '../../../shared' | 6 | import { ServerConfig } from '../../../shared' |
6 | 7 | ||
7 | const configRouter = express.Router() | 8 | const configRouter = express.Router() |
8 | 9 | ||
9 | configRouter.get('/', getConfig) | 10 | configRouter.get('/', |
11 | asyncMiddleware(getConfig) | ||
12 | ) | ||
10 | 13 | ||
11 | function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 14 | async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { |
15 | const allowed = await isSignupAllowed() | ||
12 | 16 | ||
13 | isSignupAllowed().then(allowed => { | 17 | const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) |
14 | const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) | 18 | .filter(key => CONFIG.TRANSCODING.RESOLUTIONS[key] === true) |
15 | .filter(key => CONFIG.TRANSCODING.RESOLUTIONS[key] === true) | 19 | .map(r => parseInt(r, 10)) |
16 | .map(r => parseInt(r, 10)) | ||
17 | 20 | ||
18 | const json: ServerConfig = { | 21 | const json: ServerConfig = { |
19 | signup: { | 22 | signup: { |
20 | allowed | 23 | allowed |
21 | }, | 24 | }, |
22 | transcoding: { | 25 | transcoding: { |
23 | enabledResolutions | 26 | enabledResolutions |
24 | } | ||
25 | } | 27 | } |
28 | } | ||
26 | 29 | ||
27 | res.json(json) | 30 | return res.json(json) |
28 | }) | ||
29 | } | 31 | } |
30 | 32 | ||
31 | // --------------------------------------------------------------------------- | 33 | // --------------------------------------------------------------------------- |