- if (avatarPathUnsafeCache.has(filename)) {
- return res.sendFile(avatarPathUnsafeCache.get(filename), { maxAge: STATIC_MAX_AGE.SERVER })
+ if (actorImagePathUnsafeCache.has(filename)) {
+ return res.sendFile(actorImagePathUnsafeCache.get(filename), { maxAge: STATIC_MAX_AGE.SERVER })
+ }
+
+ const image = await ActorImageModel.loadByName(filename)
+ if (!image) return res.status(HttpStatusCode.NOT_FOUND_404).end()
+
+ if (image.onDisk === false) {
+ if (!image.fileUrl) return res.status(HttpStatusCode.NOT_FOUND_404).end()
+
+ logger.info('Lazy serve remote actor image %s.', image.fileUrl)
+
+ try {
+ await pushActorImageProcessInQueue({
+ filename: image.filename,
+ fileUrl: image.fileUrl,
+ size: {
+ height: image.height,
+ width: image.width
+ },
+ type: image.type
+ })
+ } catch (err) {
+ logger.warn('Cannot process remote actor image %s.', image.fileUrl, { err })
+ return res.status(HttpStatusCode.NOT_FOUND_404).end()
+ }
+
+ image.onDisk = true
+ image.save()
+ .catch(err => logger.error('Cannot save new actor image disk state.', { err }))