Skip to content

Commit

Permalink
fix: mailMd5 field compatible with sha256 avatar links
Browse files Browse the repository at this point in the history
复用mailMd5字段来存储sha256,不然再增加一个mailSha256字段,改动太大了,也不利于兼容升级
  • Loading branch information
imaegoo committed May 28, 2024
1 parent d3d5487 commit b1f3c86
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/client/view/components/TkAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</template>

<script>
import md5 from 'blueimp-md5'
import { sha256 } from 'js-sha256'
import { convertLink, normalizeMail, isQQ, getQQAvatar } from '../../utils'
import iconUser from '@fortawesome/fontawesome-free/svgs/solid/user-circle.svg'
Expand Down Expand Up @@ -45,15 +44,15 @@ export default {
if (this.avatar) {
return this.avatar
}
if (this.mail) {
if (this.gravatarCdn === 'cravatar.cn') {
return `https://${this.gravatarCdn}/avatar/${md5(normalizeMail(this.mail))}?d=${this.defaultGravatar}`
}
return `https://${this.gravatarCdn}/avatar/${sha256(normalizeMail(this.mail))}?d=${this.defaultGravatar}`
if (this.mailMd5) {
return `https://${this.gravatarCdn}/avatar/${this.mailMd5}?d=${this.defaultGravatar}`
}
if (this.mail && isQQ(this.mail)) {
return getQQAvatar(this.mail)
}
if (this.mail) {
return `https://${this.gravatarCdn}/avatar/${sha256(normalizeMail(this.mail))}?d=${this.defaultGravatar}`
}
return ''
}
},
Expand Down
4 changes: 3 additions & 1 deletion src/server/function/twikoo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
getCheerio,
getDomPurify,
getMd5,
getSha256,
getXml2js
} = require('./utils/lib')
const {
Expand Down Expand Up @@ -53,6 +54,7 @@ const _ = db.command
const $ = getCheerio()
const DOMPurify = getDomPurify()
const md5 = getMd5()
const sha256 = getSha256()
const xml2js = getXml2js()

// 常量 / constants
Expand Down Expand Up @@ -624,7 +626,7 @@ async function parse (comment) {
uid: await getUid(),
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? md5(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: auth.getClientIP(),
Expand Down
6 changes: 4 additions & 2 deletions src/server/function/twikoo/utils/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ module.exports = {
return md5
},
getSha256 () {
const sha256 = require('js-sha256') // SHA256 哈希
return sha256
const { SHA256 } = require('crypto-js') // SHA256 哈希
return (message) => {
return SHA256(message).toString()
}
},
getNodemailer () {
if (customLibs.nodemailer) return customLibs.nodemailer
Expand Down
4 changes: 3 additions & 1 deletion src/server/self-hosted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
getCheerio,
getDomPurify,
getMd5,
getSha256,
getXml2js
} = require('twikoo-func/utils/lib')
const {
Expand Down Expand Up @@ -53,6 +54,7 @@ const logger = require('twikoo-func/utils/logger')
const $ = getCheerio()
const DOMPurify = getDomPurify()
const md5 = getMd5()
const sha256 = getSha256()
const xml2js = getXml2js()

// 常量 / constants
Expand Down Expand Up @@ -662,7 +664,7 @@ async function parse (comment, request) {
uid: request.body.accessToken,
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? md5(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: getIp(request),
Expand Down
4 changes: 3 additions & 1 deletion src/server/self-hosted/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
getCheerio,
getDomPurify,
getMd5,
getSha256,
getXml2js
} = require('twikoo-func/utils/lib')
const {
Expand Down Expand Up @@ -51,6 +52,7 @@ const logger = require('twikoo-func/utils/logger')
const $ = getCheerio()
const DOMPurify = getDomPurify()
const md5 = getMd5()
const sha256 = getSha256()
const xml2js = getXml2js()

// 常量 / constants
Expand Down Expand Up @@ -641,7 +643,7 @@ async function parse (comment, request) {
uid: request.body.accessToken,
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? md5(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: getIp(request),
Expand Down
4 changes: 3 additions & 1 deletion src/server/vercel/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
getAxios,
getDomPurify,
getMd5,
getSha256,
getXml2js
} = require('twikoo-func/utils/lib')
const {
Expand Down Expand Up @@ -53,6 +54,7 @@ const $ = getCheerio()
const axios = getAxios()
const DOMPurify = getDomPurify()
const md5 = getMd5()
const sha256 = getSha256()
const xml2js = getXml2js()

// 常量 / constants
Expand Down Expand Up @@ -665,7 +667,7 @@ async function parse (comment, request) {
uid: getUid(),
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? md5(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: getIp(request),
Expand Down

0 comments on commit b1f3c86

Please sign in to comment.