X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=server%2Fcontrollers%2Fstatic.ts;h=7425fd0973d5c3b9a1fdbb06f175129fafb52f0a;hb=a434c465455d63a3961e778abca82150186cf171;hp=e65282339e9f2143484cbd6ad483be457166e00a;hpb=4d4e5cd4dca78480ec7f40e747f424cd107376a4;p=oweals%2Fpeertube.git diff --git a/server/controllers/static.ts b/server/controllers/static.ts index e65282339..7425fd097 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -6,18 +6,20 @@ import { STATIC_MAX_AGE, 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 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 @@ -36,10 +38,9 @@ staticRouter.use( ) // Video previews path for express -const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR staticRouter.use( - STATIC_PATHS.PREVIEWS, - express.static(previewsPhysicalPath, { maxAge: STATIC_MAX_AGE }) + STATIC_PATHS.PREVIEWS + ':uuid.jpg', + asyncMiddleware(getPreview) ) // --------------------------------------------------------------------------- @@ -47,3 +48,12 @@ staticRouter.use( export { staticRouter } + +// --------------------------------------------------------------------------- + +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 }) +}