aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/lazy-static.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-14 16:14:45 +0200
committerChocobozzz <me@florianbigard.com>2021-06-14 16:14:45 +0200
commit79db409a41bd28fd2773626c9a93b5d326a38bc0 (patch)
treefa947a47d7d2b0a9d7cf7d981a11bcdf6ddc545e /server/controllers/lazy-static.ts
parenta9fbc2aaa17ab74b38952f905c567c4fd2c9d9e8 (diff)
downloadPeerTube-79db409a41bd28fd2773626c9a93b5d326a38bc0.tar.gz
PeerTube-79db409a41bd28fd2773626c9a93b5d326a38bc0.tar.zst
PeerTube-79db409a41bd28fd2773626c9a93b5d326a38bc0.zip
More robust actor image lazy load
Diffstat (limited to 'server/controllers/lazy-static.ts')
-rw-r--r--server/controllers/lazy-static.ts20
1 files changed, 18 insertions, 2 deletions
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts
index 27b1b7160..9a7dacba0 100644
--- a/server/controllers/lazy-static.ts
+++ b/server/controllers/lazy-static.ts
@@ -48,7 +48,7 @@ export {
48 48
49// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
50 50
51async function getActorImage (req: express.Request, res: express.Response) { 51async function getActorImage (req: express.Request, res: express.Response, next: express.NextFunction) {
52 const filename = req.params.filename 52 const filename = req.params.filename
53 53
54 if (actorImagePathUnsafeCache.has(filename)) { 54 if (actorImagePathUnsafeCache.has(filename)) {
@@ -78,7 +78,23 @@ async function getActorImage (req: express.Request, res: express.Response) {
78 const path = image.getPath() 78 const path = image.getPath()
79 79
80 actorImagePathUnsafeCache.set(filename, path) 80 actorImagePathUnsafeCache.set(filename, path)
81 return res.sendFile(path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER }) 81
82 return res.sendFile(path, { maxAge: STATIC_MAX_AGE.LAZY_SERVER }, (err: any) => {
83 if (!err) return
84
85 // It seems this actor image is not on the disk anymore
86 if (err.status === HttpStatusCode.NOT_FOUND_404 && !image.isOwned()) {
87 logger.error('Cannot lazy serve actor image %s.', filename, { err })
88
89 actorImagePathUnsafeCache.del(filename)
90
91 image.onDisk = false
92 image.save()
93 .catch(err => logger.error('Cannot save new actor image disk state.', { err }))
94 }
95
96 return next(err)
97 })
82} 98}
83 99
84async function getPreview (req: express.Request, res: express.Response) { 100async function getPreview (req: express.Request, res: express.Response) {