mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Don't always replace actor avatar
This commit is contained in:
parent
d7a25329f9
commit
66fb2aa39b
7 changed files with 60 additions and 37 deletions
|
@ -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
|
||||
|
||||
if (actor.Avatar) {
|
||||
// Don't update the avatar if the filename did not change
|
||||
if (actor.Avatar.filename === info.name) return actor
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue