X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=server%2Fcontrollers%2Fstatic.ts;h=7425fd0973d5c3b9a1fdbb06f175129fafb52f0a;hb=a434c465455d63a3961e778abca82150186cf171;hp=8fbf9cc9741b209933472a7a21f0af526ef29f67;hpb=493799609519c71a5f79b3e92444c5fed6f772dd;p=oweals%2Fpeertube.git diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 8fbf9cc97..7425fd097 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -7,11 +7,12 @@ import { STATIC_PATHS } from '../initializers' import { VideosPreviewCache } from '../lib' +import { asyncMiddleware } from '../middlewares' const staticRouter = express.Router() /* - Cors is very important to let other pods access torrent and video files + Cors is very important to let other servers access torrent and video files */ const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR @@ -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 }) }