X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fstatic.ts;h=c7c952d6fcc86b8470debbf02ba02b6af4ff0c4d;hb=eb08047657e739bcd9e592d76307befa3998482b;hp=2fd14131e23e262101b1360ecbce968e4ad5f9dd;hpb=f981dae8617271a2dc713bb683951730b306e0c5;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 2fd14131e..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() @@ -18,7 +19,7 @@ const torrentsPhysicalPath = CONFIG.STORAGE.TORRENTS_DIR staticRouter.use( STATIC_PATHS.TORRENTS, cors(), - express.static(torrentsPhysicalPath, { maxAge: STATIC_MAX_AGE }) + express.static(torrentsPhysicalPath, { maxAge: 0 }) // Don't cache because we could regenerate the torrent file ) // Videos path for webseeding @@ -37,10 +38,9 @@ staticRouter.use( ) // Video previews path for express -const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR staticRouter.use( STATIC_PATHS.PREVIEWS + ':uuid.jpg', - getPreview + asyncMiddleware(getPreview) ) // --------------------------------------------------------------------------- @@ -51,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 }) }