aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/lazy-static.ts20
-rw-r--r--server/models/actor/actor-image.ts4
2 files changed, 22 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) {
diff --git a/server/models/actor/actor-image.ts b/server/models/actor/actor-image.ts
index a35f9edb0..98a7f6fba 100644
--- a/server/models/actor/actor-image.ts
+++ b/server/models/actor/actor-image.ts
@@ -98,4 +98,8 @@ export class ActorImageModel extends Model<Partial<AttributesOnly<ActorImageMode
98 const imagePath = join(CONFIG.STORAGE.ACTOR_IMAGES, this.filename) 98 const imagePath = join(CONFIG.STORAGE.ACTOR_IMAGES, this.filename)
99 return remove(imagePath) 99 return remove(imagePath)
100 } 100 }
101
102 isOwned () {
103 return !this.fileUrl
104 }
101} 105}