aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/static.ts
diff options
context:
space:
mode:
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}