]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/actor.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / actor.ts
index 74241aba9aed7058a2c94e14cb9a763b1419e8ca..f802658cfe9d3b6c3509427964940f8c0b365deb 100644 (file)
@@ -173,25 +173,28 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ
 
 type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string }
 async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) {
-  if (info.name !== undefined) {
-    if (actor.avatarId) {
-      try {
-        await actor.Avatar.destroy({ transaction: t })
-      } catch (err) {
-        logger.error('Cannot remove old avatar of actor %s.', actor.url, { err })
-      }
-    }
+  if (!info.name) return actor
 
-    const avatar = await AvatarModel.create({
-      filename: info.name,
-      onDisk: info.onDisk,
-      fileUrl: info.fileUrl
-    }, { transaction: t })
+  if (actor.Avatar) {
+    // Don't update the avatar if the filename did not change
+    if (actor.Avatar.fileUrl === info.fileUrl) return actor
 
-    actor.avatarId = avatar.id
-    actor.Avatar = avatar
+    try {
+      await actor.Avatar.destroy({ transaction: t })
+    } catch (err) {
+      logger.error('Cannot remove old avatar of actor %s.', actor.url, { err })
+    }
   }
 
+  const avatar = await AvatarModel.create({
+    filename: info.name,
+    onDisk: info.onDisk,
+    fileUrl: info.fileUrl
+  }, { transaction: t })
+
+  actor.avatarId = avatar.id
+  actor.Avatar = avatar
+
   return actor
 }