1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 17:59:37 +02:00

Use async/await in controllers

This commit is contained in:
Chocobozzz 2017-10-25 11:55:06 +02:00
parent 5f04dd2f74
commit eb08047657
No known key found for this signature in database
GPG key ID: 583A612D890159BE
20 changed files with 823 additions and 992 deletions

View file

@ -2,30 +2,32 @@ import * as express from 'express'
import { isSignupAllowed } from '../../helpers'
import { CONFIG } from '../../initializers'
import { asyncMiddleware } from '../../middlewares'
import { ServerConfig } from '../../../shared'
const configRouter = express.Router()
configRouter.get('/', getConfig)
configRouter.get('/',
asyncMiddleware(getConfig)
)
function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
const allowed = await isSignupAllowed()
isSignupAllowed().then(allowed => {
const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
.filter(key => CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
.map(r => parseInt(r, 10))
const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
.filter(key => CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
.map(r => parseInt(r, 10))
const json: ServerConfig = {
signup: {
allowed
},
transcoding: {
enabledResolutions
}
const json: ServerConfig = {
signup: {
allowed
},
transcoding: {
enabledResolutions
}
}
res.json(json)
})
return res.json(json)
}
// ---------------------------------------------------------------------------