aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/actors/image.ts21
1 files changed, 16 insertions, 5 deletions
diff --git a/server/lib/activitypub/actors/image.ts b/server/lib/activitypub/actors/image.ts
index d17c2ef1a..e1d29af5b 100644
--- a/server/lib/activitypub/actors/image.ts
+++ b/server/lib/activitypub/actors/image.ts
@@ -13,20 +13,31 @@ type ImageInfo = {
13} 13}
14 14
15async function updateActorImages (actor: MActorImages, type: ActorImageType, imagesInfo: ImageInfo[], t: Transaction) { 15async function updateActorImages (actor: MActorImages, type: ActorImageType, imagesInfo: ImageInfo[], t: Transaction) {
16 const avatarsOrBanners = type === ActorImageType.AVATAR 16 const getAvatarsOrBanners = () => {
17 ? actor.Avatars 17 const result = type === ActorImageType.AVATAR
18 : actor.Banners 18 ? actor.Avatars
19 : actor.Banners
20
21 return result || []
22 }
19 23
20 if (imagesInfo.length === 0) { 24 if (imagesInfo.length === 0) {
21 await deleteActorImages(actor, type, t) 25 await deleteActorImages(actor, type, t)
22 } 26 }
23 27
28 // Cleanup old images that did not have a width
29 for (const oldImageModel of getAvatarsOrBanners()) {
30 if (oldImageModel.width) continue
31
32 await safeDeleteActorImage(actor, oldImageModel, type, t)
33 }
34
24 for (const imageInfo of imagesInfo) { 35 for (const imageInfo of imagesInfo) {
25 const oldImageModel = (avatarsOrBanners || []).find(i => i.width === imageInfo.width) 36 const oldImageModel = getAvatarsOrBanners().find(i => imageInfo.width && i.width === imageInfo.width)
26 37
27 if (oldImageModel) { 38 if (oldImageModel) {
28 // Don't update the avatar if the file URL did not change 39 // Don't update the avatar if the file URL did not change
29 if (imageInfo?.fileUrl && oldImageModel.fileUrl === imageInfo.fileUrl) { 40 if (imageInfo.fileUrl && oldImageModel.fileUrl === imageInfo.fileUrl) {
30 continue 41 continue
31 } 42 }
32 43