aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-09-16 14:49:08 +0200
committerChocobozzz <me@florianbigard.com>2022-09-16 14:56:12 +0200
commite0bfb72ce07c7b3c4dc0cce4188adc45a07464ac (patch)
treefa36d49c9b76686f44c79286e379d8a155107129 /server
parent9a3a23a834679e072c15960903e05e667ef14481 (diff)
downloadPeerTube-e0bfb72ce07c7b3c4dc0cce4188adc45a07464ac.tar.gz
PeerTube-e0bfb72ce07c7b3c4dc0cce4188adc45a07464ac.tar.zst
PeerTube-e0bfb72ce07c7b3c4dc0cce4188adc45a07464ac.zip
Cleanup actor image without width
Diffstat (limited to 'server')
-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