From eb08047657e739bcd9e592d76307befa3998482b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Oct 2017 11:55:06 +0200 Subject: Use async/await in controllers --- server/controllers/static.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'server/controllers/static.ts') diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 8fbf9cc97..c7c952d6f 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -7,6 +7,7 @@ import { STATIC_PATHS } from '../initializers' import { VideosPreviewCache } from '../lib' +import { asyncMiddleware } from '../middlewares' const staticRouter = express.Router() @@ -39,7 +40,7 @@ staticRouter.use( // Video previews path for express staticRouter.use( STATIC_PATHS.PREVIEWS + ':uuid.jpg', - getPreview + asyncMiddleware(getPreview) ) // --------------------------------------------------------------------------- @@ -50,11 +51,9 @@ export { // --------------------------------------------------------------------------- -function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { - VideosPreviewCache.Instance.getPreviewPath(req.params.uuid) - .then(path => { - if (!path) return res.sendStatus(404) +async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { + const path = await VideosPreviewCache.Instance.getPreviewPath(req.params.uuid) + if (!path) return res.sendStatus(404) - return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) - }) + return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) } -- cgit v1.2.3