diff options
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r-- | server/controllers/static.ts | 13 |
1 files changed, 6 insertions, 7 deletions
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 { | |||
7 | STATIC_PATHS | 7 | STATIC_PATHS |
8 | } from '../initializers' | 8 | } from '../initializers' |
9 | import { VideosPreviewCache } from '../lib' | 9 | import { VideosPreviewCache } from '../lib' |
10 | import { asyncMiddleware } from '../middlewares' | ||
10 | 11 | ||
11 | const staticRouter = express.Router() | 12 | const staticRouter = express.Router() |
12 | 13 | ||
@@ -39,7 +40,7 @@ staticRouter.use( | |||
39 | // Video previews path for express | 40 | // Video previews path for express |
40 | staticRouter.use( | 41 | staticRouter.use( |
41 | STATIC_PATHS.PREVIEWS + ':uuid.jpg', | 42 | STATIC_PATHS.PREVIEWS + ':uuid.jpg', |
42 | getPreview | 43 | asyncMiddleware(getPreview) |
43 | ) | 44 | ) |
44 | 45 | ||
45 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
@@ -50,11 +51,9 @@ export { | |||
50 | 51 | ||
51 | // --------------------------------------------------------------------------- | 52 | // --------------------------------------------------------------------------- |
52 | 53 | ||
53 | function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { | 54 | async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { |
54 | VideosPreviewCache.Instance.getPreviewPath(req.params.uuid) | 55 | const path = await VideosPreviewCache.Instance.getPreviewPath(req.params.uuid) |
55 | .then(path => { | 56 | if (!path) return res.sendStatus(404) |
56 | if (!path) return res.sendStatus(404) | ||
57 | 57 | ||
58 | return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) | 58 | return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) |
59 | }) | ||
60 | } | 59 | } |