twikoo-func 1.6.37 → 1.6.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/package.json +1 -1
- package/utils/index.js +1 -0
- package/utils/spam.js +19 -6
package/index.js
CHANGED
|
@@ -622,7 +622,7 @@ async function parse (comment) {
|
|
|
622
622
|
const isAdminUser = await isAdmin()
|
|
623
623
|
const isBloggerMail = equalsMail(comment.mail, config.BLOGGER_EMAIL)
|
|
624
624
|
if (isBloggerMail && !isAdminUser) throw new Error('请先登录管理面板,再使用博主身份发送评论')
|
|
625
|
-
const hashMethod =
|
|
625
|
+
const hashMethod = config.GRAVATAR_CDN === 'cravatar.cn' ? md5 : sha256
|
|
626
626
|
const commentDo = {
|
|
627
627
|
uid: await getUid(),
|
|
628
628
|
nick: comment.nick ? comment.nick : '匿名',
|
|
@@ -643,7 +643,7 @@ async function parse (comment) {
|
|
|
643
643
|
}
|
|
644
644
|
if (isQQ(comment.mail)) {
|
|
645
645
|
commentDo.mail = addQQMailSuffix(comment.mail)
|
|
646
|
-
commentDo.mailMd5 =
|
|
646
|
+
commentDo.mailMd5 = hashMethod(normalizeMail(commentDo.mail))
|
|
647
647
|
commentDo.avatar = await getQQAvatar(comment.mail)
|
|
648
648
|
}
|
|
649
649
|
return commentDo
|
package/package.json
CHANGED
package/utils/index.js
CHANGED
|
@@ -218,6 +218,7 @@ const fn = {
|
|
|
218
218
|
async getQQAvatar (qq) {
|
|
219
219
|
try {
|
|
220
220
|
const qqNum = qq.replace(/@qq.com/ig, '')
|
|
221
|
+
// TODO: 这个接口已经失效了,暂时找不到新的接口
|
|
221
222
|
const result = await axios.get(`https://aq.qq.com/cn2/get_img/get_face?img_type=3&uin=${qqNum}`)
|
|
222
223
|
return result.data?.url || null
|
|
223
224
|
} catch (e) {
|
package/utils/spam.js
CHANGED
|
@@ -3,6 +3,9 @@ const {
|
|
|
3
3
|
getCryptoJS,
|
|
4
4
|
getTencentcloud
|
|
5
5
|
} = require('./lib')
|
|
6
|
+
const {
|
|
7
|
+
equalsMail
|
|
8
|
+
} = require('.')
|
|
6
9
|
const AkismetClient = getAkismetClient()
|
|
7
10
|
const CryptoJS = getCryptoJS()
|
|
8
11
|
|
|
@@ -29,20 +32,30 @@ const fn = {
|
|
|
29
32
|
if (comment.isSpam) {
|
|
30
33
|
// 预检测没过的,就不再检测了
|
|
31
34
|
isSpam = true
|
|
35
|
+
} else if (equalsMail(config.BLOGGER_EMAIL, comment.mail)) {
|
|
36
|
+
// 博主本人评论,不再检测了
|
|
37
|
+
isSpam = false
|
|
32
38
|
} else if (config.QCLOUD_SECRET_ID && config.QCLOUD_SECRET_KEY) {
|
|
33
39
|
// 腾讯云内容安全
|
|
34
|
-
const client = new (getTencentCloud().tms.
|
|
40
|
+
const client = new (getTencentCloud().tms.v20201229.Client)({
|
|
35
41
|
credential: { secretId: config.QCLOUD_SECRET_ID, secretKey: config.QCLOUD_SECRET_KEY },
|
|
36
42
|
region: 'ap-shanghai',
|
|
37
43
|
profile: { httpProfile: { endpoint: 'tms.tencentcloudapi.com' } }
|
|
38
44
|
})
|
|
39
|
-
const
|
|
45
|
+
const textModerationParams = {
|
|
46
|
+
// 文档: https://cloud.tencent.com/document/api/1124/51860
|
|
40
47
|
Content: CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(comment.comment)),
|
|
41
|
-
|
|
42
|
-
User: { Nickname: comment.nick }
|
|
43
|
-
|
|
48
|
+
DataId: comment.id,
|
|
49
|
+
User: { Nickname: comment.nick },
|
|
50
|
+
Device: { IP: comment.ip }
|
|
51
|
+
}
|
|
52
|
+
if (config.QCLOUD_CMS_BIZTYPE) {
|
|
53
|
+
textModerationParams.BizType = config.QCLOUD_CMS_BIZTYPE
|
|
54
|
+
}
|
|
55
|
+
logger.log('腾讯云请求参数:', textModerationParams)
|
|
56
|
+
const checkResult = await client.TextModeration(textModerationParams)
|
|
44
57
|
logger.log('腾讯云返回结果:', checkResult)
|
|
45
|
-
isSpam = checkResult.
|
|
58
|
+
isSpam = checkResult.Suggestion !== 'Pass'
|
|
46
59
|
} else if (config.AKISMET_KEY) {
|
|
47
60
|
// Akismet
|
|
48
61
|
const akismetClient = new AkismetClient({
|