diff options
author | Chocobozzz <me@florianbigard.com> | 2019-11-21 12:16:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-11-25 10:59:44 +0100 |
commit | 66fb2aa39b6f8e4677f80128c27fbafd3a8fe2e7 (patch) | |
tree | 9d2f21e81cc42d8d51ac7ae35d91c30f143f0be0 /server/lib/activitypub | |
parent | d7a25329f9e607894d29ab342b9cb66638b56dc0 (diff) | |
download | PeerTube-66fb2aa39b6f8e4677f80128c27fbafd3a8fe2e7.tar.gz PeerTube-66fb2aa39b6f8e4677f80128c27fbafd3a8fe2e7.tar.zst PeerTube-66fb2aa39b6f8e4677f80128c27fbafd3a8fe2e7.zip |
Don't always replace actor avatar
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/actor.ts | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 74241aba9..14dd1b9b9 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -173,25 +173,28 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ | |||
173 | 173 | ||
174 | type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string } | 174 | type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string } |
175 | async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) { | 175 | async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) { |
176 | if (info.name !== undefined) { | 176 | if (!info.name) return actor |
177 | if (actor.avatarId) { | ||
178 | try { | ||
179 | await actor.Avatar.destroy({ transaction: t }) | ||
180 | } catch (err) { | ||
181 | logger.error('Cannot remove old avatar of actor %s.', actor.url, { err }) | ||
182 | } | ||
183 | } | ||
184 | 177 | ||
185 | const avatar = await AvatarModel.create({ | 178 | if (actor.Avatar) { |
186 | filename: info.name, | 179 | // Don't update the avatar if the filename did not change |
187 | onDisk: info.onDisk, | 180 | if (actor.Avatar.filename === info.name) return actor |
188 | fileUrl: info.fileUrl | ||
189 | }, { transaction: t }) | ||
190 | 181 | ||
191 | actor.avatarId = avatar.id | 182 | try { |
192 | actor.Avatar = avatar | 183 | await actor.Avatar.destroy({ transaction: t }) |
184 | } catch (err) { | ||
185 | logger.error('Cannot remove old avatar of actor %s.', actor.url, { err }) | ||
186 | } | ||
193 | } | 187 | } |
194 | 188 | ||
189 | const avatar = await AvatarModel.create({ | ||
190 | filename: info.name, | ||
191 | onDisk: info.onDisk, | ||
192 | fileUrl: info.fileUrl | ||
193 | }, { transaction: t }) | ||
194 | |||
195 | actor.avatarId = avatar.id | ||
196 | actor.Avatar = avatar | ||
197 | |||
195 | return actor | 198 | return actor |
196 | } | 199 | } |
197 | 200 | ||