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