X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fstatic.ts;h=c7c952d6fcc86b8470debbf02ba02b6af4ff0c4d;hb=b7a485121d71c95fcf5e432e4cc745cf91af4f93;hp=8fbf9cc9741b209933472a7a21f0af526ef29f67;hpb=493799609519c71a5f79b3e92444c5fed6f772dd;p=github%2FChocobozzz%2FPeerTube.git 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 }) }