aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/static.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-12 11:56:02 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-12 11:56:02 +0200
commitf981dae8617271a2dc713bb683951730b306e0c5 (patch)
treeecee631766bc1b98c20a7836479fed40850c5a56 /server/controllers/static.ts
parent075f16caac5236cb04c98ae7b3a989766d764bb3 (diff)
downloadPeerTube-f981dae8617271a2dc713bb683951730b306e0c5.tar.gz
PeerTube-f981dae8617271a2dc713bb683951730b306e0c5.tar.zst
PeerTube-f981dae8617271a2dc713bb683951730b306e0c5.zip
Add previews cache system between pods
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r--server/controllers/static.ts16
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'
9import { VideosPreviewCache } from '../lib'
9 10
10const staticRouter = express.Router() 11const staticRouter = express.Router()
11 12
@@ -38,8 +39,8 @@ staticRouter.use(
38// Video previews path for express 39// Video previews path for express
39const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR 40const previewsPhysicalPath = CONFIG.STORAGE.PREVIEWS_DIR
40staticRouter.use( 41staticRouter.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(
47export { 48export {
48 staticRouter 49 staticRouter
49} 50}
51
52// ---------------------------------------------------------------------------
53
54function 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}