Skip to content

Commit

Permalink
add getMailMd5, use hash of nick if no mail (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
mercury233 authored Nov 23, 2022
1 parent 5af1473 commit 05cd75f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/server/function/twikoo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
getUrlsQuery,
parseComment,
parseCommentForAdmin,
getMailMd5,
getAvatar,
isQQ,
addQQMailSuffix,
Expand Down Expand Up @@ -778,7 +779,7 @@ async function getRecentComments (event) {
href: comment.href,
nick: comment.nick,
avatar: getAvatar(comment, config),
mailMd5: comment.mailMd5 || md5(comment.mail),
mailMd5: getMailMd5(comment),
link: comment.link,
comment: comment.comment,
commentText: $(comment.comment).text(),
Expand Down
13 changes: 11 additions & 2 deletions src/server/function/twikoo/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const fn = {
id: comment._id.toString(),
nick: comment.nick,
avatar: comment.avatar,
mailMd5: comment.mailMd5 || md5(comment.mail),
mailMd5: fn.getMailMd5(comment),
link: comment.link,
comment: comment.comment,
os: displayOs,
Expand Down Expand Up @@ -116,13 +116,22 @@ const fn = {
}
return url.substring(x)
},
getMailMd5 (comment) {
if (comment.mailMd5) {
return comment.mailMd5
}
if (comment.mail) {
return md5(comment.mail)
}
return md5(comment.nick)
},
getAvatar (comment, config) {
if (comment.avatar) {
return comment.avatar
} else {
const gravatarCdn = config.GRAVATAR_CDN || 'cravatar.cn'
const defaultGravatar = config.DEFAULT_GRAVATAR || 'identicon'
const mailMd5 = comment.mailMd5 || md5(comment.mail)
const mailMd5 = fn.getMailMd5(comment)
return `https://${gravatarCdn}/avatar/${mailMd5}?d=${defaultGravatar}`
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/server/self-hosted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
getUrlsQuery,
parseComment,
parseCommentForAdmin,
getMailMd5,
getAvatar,
isQQ,
addQQMailSuffix,
Expand Down Expand Up @@ -789,7 +790,7 @@ async function getRecentComments (event) {
url: comment.url,
nick: comment.nick,
avatar: getAvatar(comment, config),
mailMd5: comment.mailMd5 || md5(comment.mail),
mailMd5: getMailMd5(comment),
link: comment.link,
comment: comment.comment,
commentText: $(comment.comment).text(),
Expand Down
3 changes: 2 additions & 1 deletion src/server/vercel/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
getUrlsQuery,
parseComment,
parseCommentForAdmin,
getMailMd5,
getAvatar,
isQQ,
addQQMailSuffix,
Expand Down Expand Up @@ -803,7 +804,7 @@ async function getRecentComments (event) {
url: comment.url,
nick: comment.nick,
avatar: getAvatar(comment, config),
mailMd5: comment.mailMd5 || md5(comment.mail),
mailMd5: getMailMd5(comment),
link: comment.link,
comment: comment.comment,
commentText: $(comment.comment).text(),
Expand Down

0 comments on commit 05cd75f

Please sign in to comment.