mirror of https://github.com/halo-dev/halo
feat: add gravatar url into annotation of spec of comment for anonymous (#5642)
/kind feature /area core #### What this PR does / why we need it: see https://github.com/halo-dev/plugin-comment-widget/issues/97 #### Which issue(s) this PR fixes: Fixes #5641 ```release-note 评论数据返回邮箱地址 hash 值以便生成默认头像 ```pull/5672/head
parent
aab367a1f7
commit
c630a37eea
|
@ -100,6 +100,7 @@ public class Comment extends AbstractExtension {
|
||||||
public static final String KIND_EMAIL = "Email";
|
public static final String KIND_EMAIL = "Email";
|
||||||
public static final String AVATAR_ANNO = "avatar";
|
public static final String AVATAR_ANNO = "avatar";
|
||||||
public static final String WEBSITE_ANNO = "website";
|
public static final String WEBSITE_ANNO = "website";
|
||||||
|
public static final String EMAIL_HASH_ANNO = "email-hash";
|
||||||
|
|
||||||
@Schema(requiredMode = REQUIRED, minLength = 1)
|
@Schema(requiredMode = REQUIRED, minLength = 1)
|
||||||
private String kind;
|
private String kind;
|
||||||
|
|
|
@ -8,16 +8,19 @@ import static run.halo.app.extension.index.query.QueryFactory.isNull;
|
||||||
import static run.halo.app.extension.index.query.QueryFactory.or;
|
import static run.halo.app.extension.index.query.QueryFactory.or;
|
||||||
|
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
||||||
import org.springframework.security.core.context.SecurityContext;
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.DigestUtils;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import run.halo.app.content.comment.OwnerInfo;
|
import run.halo.app.content.comment.OwnerInfo;
|
||||||
|
@ -167,6 +170,15 @@ public class CommentPublicQueryServiceImpl implements CommentPublicQueryService
|
||||||
commentVo.getSpec().setIpAddress("");
|
commentVo.getSpec().setIpAddress("");
|
||||||
var specOwner = commentVo.getSpec().getOwner();
|
var specOwner = commentVo.getSpec().getOwner();
|
||||||
specOwner.setName("");
|
specOwner.setName("");
|
||||||
|
var email = owner.getEmail();
|
||||||
|
if (StringUtils.isNotBlank(email)) {
|
||||||
|
var emailHash = DigestUtils.md5DigestAsHex(email.getBytes());
|
||||||
|
if (specOwner.getAnnotations() == null) {
|
||||||
|
specOwner.setAnnotations(new HashMap<>(2));
|
||||||
|
}
|
||||||
|
specOwner.getAnnotations()
|
||||||
|
.put(Comment.CommentOwner.EMAIL_HASH_ANNO, emailHash);
|
||||||
|
}
|
||||||
if (specOwner.getAnnotations() != null) {
|
if (specOwner.getAnnotations() != null) {
|
||||||
specOwner.getAnnotations().remove("Email");
|
specOwner.getAnnotations().remove("Email");
|
||||||
}
|
}
|
||||||
|
@ -210,6 +222,15 @@ public class CommentPublicQueryServiceImpl implements CommentPublicQueryService
|
||||||
replyVo.getSpec().setIpAddress("");
|
replyVo.getSpec().setIpAddress("");
|
||||||
var specOwner = replyVo.getSpec().getOwner();
|
var specOwner = replyVo.getSpec().getOwner();
|
||||||
specOwner.setName("");
|
specOwner.setName("");
|
||||||
|
var email = owner.getEmail();
|
||||||
|
if (StringUtils.isNotBlank(email)) {
|
||||||
|
var emailHash = DigestUtils.md5DigestAsHex(email.getBytes());
|
||||||
|
if (specOwner.getAnnotations() == null) {
|
||||||
|
specOwner.setAnnotations(new HashMap<>(2));
|
||||||
|
}
|
||||||
|
specOwner.getAnnotations()
|
||||||
|
.put(Comment.CommentOwner.EMAIL_HASH_ANNO, emailHash);
|
||||||
|
}
|
||||||
if (specOwner.getAnnotations() != null) {
|
if (specOwner.getAnnotations() != null) {
|
||||||
specOwner.getAnnotations().remove("Email");
|
specOwner.getAnnotations().remove("Email");
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,7 +389,7 @@ class CommentPublicQueryServiceIntegrationTest {
|
||||||
"name":"",
|
"name":"",
|
||||||
"displayName":"fake-display-name",
|
"displayName":"fake-display-name",
|
||||||
"annotations":{
|
"annotations":{
|
||||||
|
"email-hash": "4249f4df72b475e7894fabed1c5888cf"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"creationTime": "2024-03-11T06:23:42.923294424Z",
|
"creationTime": "2024-03-11T06:23:42.923294424Z",
|
||||||
|
|
Loading…
Reference in New Issue