aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-06-07 08:53:14 +0200
committerChocobozzz <me@florianbigard.com>2023-06-29 10:19:33 +0200
commitbafaba0bcda0c9fb553b9eebef3764994bb4ff60 (patch)
treebff9a580cda865cd81c91cd5e1b7b527df45dac1 /server/controllers
parentf162d32da098aa55f6de2367142faa166edb7c08 (diff)
downloadPeerTube-bafaba0bcda0c9fb553b9eebef3764994bb4ff60.tar.gz
PeerTube-bafaba0bcda0c9fb553b9eebef3764994bb4ff60.tar.zst
PeerTube-bafaba0bcda0c9fb553b9eebef3764994bb4ff60.zip
Support lazy download of remote video miniatures
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/lazy-static.ts19
-rw-r--r--server/controllers/static.ts2
2 files changed, 19 insertions, 2 deletions
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts
index 8e18b0642..dad30365c 100644
--- a/server/controllers/lazy-static.ts
+++ b/server/controllers/lazy-static.ts
@@ -6,6 +6,7 @@ import { FILES_CACHE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/
6import { 6import {
7 AvatarPermanentFileCache, 7 AvatarPermanentFileCache,
8 VideoCaptionsSimpleFileCache, 8 VideoCaptionsSimpleFileCache,
9 VideoMiniaturePermanentFileCache,
9 VideoPreviewsSimpleFileCache, 10 VideoPreviewsSimpleFileCache,
10 VideoStoryboardsSimpleFileCache, 11 VideoStoryboardsSimpleFileCache,
11 VideoTorrentsSimpleFileCache 12 VideoTorrentsSimpleFileCache
@@ -40,6 +41,12 @@ lazyStaticRouter.use(
40) 41)
41 42
42lazyStaticRouter.use( 43lazyStaticRouter.use(
44 LAZY_STATIC_PATHS.THUMBNAILS + ':filename',
45 asyncMiddleware(getThumbnail),
46 handleStaticError
47)
48
49lazyStaticRouter.use(
43 LAZY_STATIC_PATHS.PREVIEWS + ':filename', 50 LAZY_STATIC_PATHS.PREVIEWS + ':filename',
44 asyncMiddleware(getPreview), 51 asyncMiddleware(getPreview),
45 handleStaticError 52 handleStaticError
@@ -72,7 +79,6 @@ export {
72} 79}
73 80
74// --------------------------------------------------------------------------- 81// ---------------------------------------------------------------------------
75
76const avatarPermanentFileCache = new AvatarPermanentFileCache() 82const avatarPermanentFileCache = new AvatarPermanentFileCache()
77 83
78function getActorImage (req: express.Request, res: express.Response, next: express.NextFunction) { 84function getActorImage (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -81,6 +87,17 @@ function getActorImage (req: express.Request, res: express.Response, next: expre
81 return avatarPermanentFileCache.lazyServe({ filename, res, next }) 87 return avatarPermanentFileCache.lazyServe({ filename, res, next })
82} 88}
83 89
90// ---------------------------------------------------------------------------
91const videoMiniaturePermanentFileCache = new VideoMiniaturePermanentFileCache()
92
93function getThumbnail (req: express.Request, res: express.Response, next: express.NextFunction) {
94 const filename = req.params.filename
95
96 return videoMiniaturePermanentFileCache.lazyServe({ filename, res, next })
97}
98
99// ---------------------------------------------------------------------------
100
84async function getPreview (req: express.Request, res: express.Response) { 101async function getPreview (req: express.Request, res: express.Response) {
85 const result = await VideoPreviewsSimpleFileCache.Instance.getFilePath(req.params.filename) 102 const result = await VideoPreviewsSimpleFileCache.Instance.getFilePath(req.params.filename)
86 if (!result) return res.status(HttpStatusCode.NOT_FOUND_404).end() 103 if (!result) return res.status(HttpStatusCode.NOT_FOUND_404).end()
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 9baff94c0..bbd0dd011 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -72,7 +72,7 @@ staticRouter.use(
72 handleStaticError 72 handleStaticError
73) 73)
74 74
75// Thumbnails path for express 75// FIXME: deprecated in v6, to remove
76const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR 76const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
77staticRouter.use( 77staticRouter.use(
78 STATIC_PATHS.THUMBNAILS, 78 STATIC_PATHS.THUMBNAILS,