mirror of https://github.com/halo-dev/halo
fix: resolve the issue of missing old avatar (#4293)
#### What type of PR is this? /kind bug /area core #### What this PR does / why we need it: 解决 #4253 所导致的用户旧头像被删除的问题。 #### Special notes for your reviewer: 1. 使用 2.7.x 之前的 Halo 版本,新建用户并设置其头像。 2. 升级 Halo 至 2.8.0-rc.1 3. 头像还存在即可。 4. 测试头像上传、移除功能是否正常可用。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/4262/head
parent
cf9a9e8a6d
commit
a5bace37ee
|
@ -209,6 +209,7 @@ public class UserEndpoint implements CustomEndpoint {
|
|||
.flatMap(user -> {
|
||||
MetadataUtil.nullSafeAnnotations(user)
|
||||
.remove(User.AVATAR_ATTACHMENT_NAME_ANNO);
|
||||
user.getSpec().setAvatar(null);
|
||||
return client.update(user);
|
||||
})
|
||||
.flatMap(user -> ServerResponse.ok().bodyValue(user));
|
||||
|
|
|
@ -78,12 +78,6 @@ public class UserReconciler implements Reconciler<Request> {
|
|||
oldAvatarAttachmentName = null;
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(oldAvatarAttachmentName)
|
||||
&& StringUtils.isNotBlank(avatarAttachmentName)) {
|
||||
oldAvatarAttachmentName = avatarAttachmentName;
|
||||
annotations.put(User.LAST_AVATAR_ATTACHMENT_NAME_ANNO, oldAvatarAttachmentName);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(avatarAttachmentName)) {
|
||||
client.fetch(Attachment.class, avatarAttachmentName)
|
||||
.ifPresent(attachment -> {
|
||||
|
@ -93,9 +87,15 @@ public class UserReconciler implements Reconciler<Request> {
|
|||
}
|
||||
user.getSpec().setAvatar(avatarUri.toString());
|
||||
});
|
||||
} else {
|
||||
} else if (StringUtils.isNotBlank(oldAvatarAttachmentName)) {
|
||||
user.getSpec().setAvatar(null);
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(oldAvatarAttachmentName)
|
||||
&& StringUtils.isNotBlank(avatarAttachmentName)) {
|
||||
annotations.put(User.LAST_AVATAR_ATTACHMENT_NAME_ANNO, avatarAttachmentName);
|
||||
}
|
||||
|
||||
client.update(user);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue