Skip to content

Commit

Permalink
fix: cravatar does not support sha256
Browse files Browse the repository at this point in the history
  • Loading branch information
imaegoo committed Jul 9, 2024
1 parent c24151f commit 92a3a87
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/Twikoo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ onMounted(() => {

<!-- Twikoo -->
<div id="twikoo"></div>
<component :is="'script'" src="https://cdn.jsdelivr.net/npm/twikoo@1.6.36/dist/twikoo.min.js" integrity="sha384-ocJyLUeo5I91x224iE/ke7PPHyXVSUKNL7GfqnEto/HxGuBLnLLlitt3dFT/Zwrn" crossorigin="anonymous" ref="twikooJs"></component>
<component :is="'script'" src="https://cdn.jsdelivr.net/npm/twikoo@1.6.37/dist/twikoo.min.js" integrity="sha384-ocJyLUeo5I91x224iE/ke7PPHyXVSUKNL7GfqnEto/HxGuBLnLLlitt3dFT/Zwrn" crossorigin="anonymous" ref="twikooJs"></component>
</div>
</template>
2 changes: 1 addition & 1 deletion docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports.main = require('twikoo-func').main
8. 创建完成后,点击“twikoo"进入云函数详情页,进入“函数代码”标签,点击“文件 - 新建文件”,输入 `package.json`,回车
9. 复制以下代码、粘贴到代码框中,点击“保存并安装依赖”
``` json
{ "dependencies": { "twikoo-func": "1.6.36" } }
{ "dependencies": { "twikoo-func": "1.6.37" } }
```

## 腾讯云命令行部署
Expand Down
6 changes: 3 additions & 3 deletions docs/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ twikoo:

``` html
<div id="tcomment"></div>
<script src="https://cdn.jsdelivr.net/npm/twikoo@1.6.36/dist/twikoo.all.min.js" integrity="sha384-4KfOjEinLSkv1i1J8TzlkC/RTnuiLoR1OLerVgjEKoH5djYtbf7mzEFsz9p3nfuA" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/twikoo@1.6.37/dist/twikoo.all.min.js" integrity="sha384-4KfOjEinLSkv1i1J8TzlkC/RTnuiLoR1OLerVgjEKoH5djYtbf7mzEFsz9p3nfuA" crossorigin="anonymous"></script>
<script>
twikoo.init({
envId: '您的环境id', // 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app)
Expand All @@ -111,8 +111,8 @@ twikoo.init({

如果遇到默认 CDN 加载速度缓慢,可更换其他 CDN 镜像。以下为可供选择的公共 CDN,其中一些 CDN 可能需要数天时间同步最新版本:

* `https://lib.baomitu.com/twikoo/1.6.36/twikoo.all.min.js`
* `https://cdn.jsdelivr.net/npm/twikoo@1.6.36/dist/twikoo.all.min.js`
* `https://lib.baomitu.com/twikoo/1.6.37/twikoo.all.min.js`
* `https://cdn.jsdelivr.net/npm/twikoo@1.6.37/dist/twikoo.all.min.js`

> 建议使用 CDN 引入 Twikoo 的用户参考上一段的示例在代码中加入 [SRI](https://developer.mozilla.org/zh-CN/docs/Web/Security/Subresource_Integrity) 属性以确保完整性。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo",
"version": "1.6.36",
"version": "1.6.37",
"description": "A simple comment system.",
"keywords": [
"twikoojs",
Expand Down
2 changes: 1 addition & 1 deletion src/client/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const version = '1.6.36'
const version = '1.6.37'

export { version }
4 changes: 3 additions & 1 deletion src/client/view/components/TkAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</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 @@ -51,7 +52,8 @@ export default {
return getQQAvatar(this.mail)
}
if (this.mail) {
return `https://${this.gravatarCdn}/avatar/${sha256(normalizeMail(this.mail))}?d=${this.defaultGravatar}`
const hashMethod = this.gravatarCdn === 'cravatar.cn' ? md5 : sha256
return `https://${this.gravatarCdn}/avatar/${hashMethod(normalizeMail(this.mail))}?d=${this.defaultGravatar}`
}
return ''
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/aws-lambda/src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-aws-lambda",
"version": "1.6.36",
"version": "1.6.37",
"description": "A simple comment system.",
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion src/server/function/twikoo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,12 @@ async function parse (comment) {
const isAdminUser = await isAdmin()
const isBloggerMail = equalsMail(comment.mail, config.BLOGGER_EMAIL)
if (isBloggerMail && !isAdminUser) throw new Error('请先登录管理面板,再使用博主身份发送评论')
const hashMethod = this.gravatarCdn === 'cravatar.cn' ? md5 : sha256
const commentDo = {
uid: await getUid(),
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? hashMethod(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: auth.getClientIP(),
Expand Down
2 changes: 1 addition & 1 deletion src/server/function/twikoo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-func",
"version": "1.6.36",
"version": "1.6.37",
"description": "A simple comment system.",
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/server/netlify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-netlify",
"version": "1.6.36",
"version": "1.6.37",
"description": "A simple comment system.",
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/server/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"commander": "^11.1.0",
"dotenv": "^16.4.1",
"tkserver": "1.6.36"
"tkserver": "1.6.37"
},
"devDependencies": {
"patch-package": "^8.0.0",
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 @@ -659,12 +659,13 @@ async function parse (comment, request) {
const isAdminUser = isAdmin(request.body.accessToken)
const isBloggerMail = equalsMail(comment.mail, config.BLOGGER_EMAIL)
if (isBloggerMail && !isAdminUser) throw new Error('请先登录管理面板,再使用博主身份发送评论')
const hashMethod = this.gravatarCdn === 'cravatar.cn' ? md5 : sha256
const commentDo = {
_id: uuidv4().replace(/-/g, ''),
uid: request.body.accessToken,
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? hashMethod(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: getIp(request),
Expand Down
3 changes: 2 additions & 1 deletion src/server/self-hosted/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,13 @@ async function parse (comment, request) {
const isAdminUser = isAdmin(request.body.accessToken)
const isBloggerMail = equalsMail(comment.mail, config.BLOGGER_EMAIL)
if (isBloggerMail && !isAdminUser) throw new Error('请先登录管理面板,再使用博主身份发送评论')
const hashMethod = this.gravatarCdn === 'cravatar.cn' ? md5 : sha256
const commentDo = {
_id: uuidv4().replace(/-/g, ''),
uid: request.body.accessToken,
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? hashMethod(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: getIp(request),
Expand Down
4 changes: 2 additions & 2 deletions src/server/self-hosted/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tkserver",
"version": "1.6.36",
"version": "1.6.37",
"description": "A simple comment system.",
"keywords": [
"twikoo",
Expand Down Expand Up @@ -31,7 +31,7 @@
"get-user-ip": "^1.0.1",
"lokijs": "^1.5.12",
"mongodb": "^6.3.0",
"twikoo-func": "1.6.36",
"twikoo-func": "1.6.37",
"uuid": "^8.3.2"
}
}
3 changes: 2 additions & 1 deletion src/server/vercel/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,13 @@ async function parse (comment, request) {
const isAdminUser = isAdmin()
const isBloggerMail = equalsMail(comment.mail, config.BLOGGER_EMAIL)
if (isBloggerMail && !isAdminUser) throw new Error('请先登录管理面板,再使用博主身份发送评论')
const hashMethod = this.gravatarCdn === 'cravatar.cn' ? md5 : sha256
const commentDo = {
_id: uuidv4().replace(/-/g, ''),
uid: getUid(),
nick: comment.nick ? comment.nick : '匿名',
mail: comment.mail ? comment.mail : '',
mailMd5: comment.mail ? sha256(normalizeMail(comment.mail)) : '',
mailMd5: comment.mail ? hashMethod(normalizeMail(comment.mail)) : '',
link: comment.link ? comment.link : '',
ua: comment.ua,
ip: getIp(request),
Expand Down
4 changes: 2 additions & 2 deletions src/server/vercel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-vercel",
"version": "1.6.36",
"version": "1.6.37",
"description": "A simple comment system.",
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
"license": "MIT",
Expand All @@ -13,7 +13,7 @@
"dependencies": {
"get-user-ip": "^1.0.1",
"mongodb": "^6.3.0",
"twikoo-func": "1.6.36",
"twikoo-func": "1.6.37",
"uuid": "^8.3.2"
}
}

0 comments on commit 92a3a87

Please sign in to comment.