diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/static.ts | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index e65282339..2fd14131e 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -6,6 +6,7 @@ import { | |||
6 | STATIC_MAX_AGE, | 6 | STATIC_MAX_AGE, |
7 | STATIC_PATHS | 7 | STATIC_PATHS |
8 | } from '../initializers' | 8 | } from '../initializers' |
9 | import { VideosPreviewCache } from '../lib' | ||
9 | 10 | ||
10 | const staticRouter = express.Router() | 11 | const staticRouter = express.Router() |
11 | 12 | ||
@@ -38,8 +39,8 @@ staticRouter.use( | |||
38 | // Video previews path for express | 39 | // Video previews path for express |
39 | const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR | 40 | const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR |
40 | staticRouter.use( | 41 | staticRouter.use( |
41 | STATIC_PATHS.PREVIEWS, | 42 | STATIC_PATHS.PREVIEWS + ':uuid.jpg', |
42 | express.static(previewsPhysicalPath, { maxAge: STATIC_MAX_AGE }) | 43 | getPreview |
43 | ) | 44 | ) |
44 | 45 | ||
45 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
@@ -47,3 +48,14 @@ staticRouter.use( | |||
47 | export { | 48 | export { |
48 | staticRouter | 49 | staticRouter |
49 | } | 50 | } |
51 | |||
52 | // --------------------------------------------------------------------------- | ||
53 | |||
54 | function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
55 | VideosPreviewCache.Instance.getPreviewPath(req.params.uuid) | ||
56 | .then(path => { | ||
57 | if (!path) return res.sendStatus(404) | ||
58 | |||
59 | return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) | ||
60 | }) | ||
61 | } | ||