diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-12 11:56:02 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-12 11:56:02 +0200 |
commit | f981dae8617271a2dc713bb683951730b306e0c5 (patch) | |
tree | ecee631766bc1b98c20a7836479fed40850c5a56 /server/controllers | |
parent | 075f16caac5236cb04c98ae7b3a989766d764bb3 (diff) | |
download | PeerTube-f981dae8617271a2dc713bb683951730b306e0c5.tar.gz PeerTube-f981dae8617271a2dc713bb683951730b306e0c5.tar.zst PeerTube-f981dae8617271a2dc713bb683951730b306e0c5.zip |
Add previews cache system between pods
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 | } | ||