twikoo-func 1.4.13 → 1.4.17
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 +31 -9
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Twikoo cloudbase function v1.4.
|
|
2
|
+
* Twikoo cloudbase function v1.4.17
|
|
3
3
|
* (c) 2020-present iMaeGoo
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -31,7 +31,7 @@ const window = new JSDOM('').window
|
|
|
31
31
|
const DOMPurify = createDOMPurify(window)
|
|
32
32
|
|
|
33
33
|
// 常量 / constants
|
|
34
|
-
const VERSION = '1.4.
|
|
34
|
+
const VERSION = '1.4.17'
|
|
35
35
|
const RES_CODE = {
|
|
36
36
|
SUCCESS: 0,
|
|
37
37
|
FAIL: 1000,
|
|
@@ -880,6 +880,7 @@ async function sendNotice (comment) {
|
|
|
880
880
|
noticePushPlus(comment),
|
|
881
881
|
noticeWeComPush(comment),
|
|
882
882
|
noticeDingTalkHook(comment),
|
|
883
|
+
noticePushdeer(comment),
|
|
883
884
|
noticeQQ(comment)
|
|
884
885
|
]).catch(err => {
|
|
885
886
|
console.error('邮件通知异常:', err)
|
|
@@ -931,7 +932,8 @@ async function noticeMaster (comment) {
|
|
|
931
932
|
'QM_SENDKEY',
|
|
932
933
|
'PUSH_PLUS_TOKEN',
|
|
933
934
|
'WECOM_API_URL',
|
|
934
|
-
'DINGTALK_WEBHOOK_URL'
|
|
935
|
+
'DINGTALK_WEBHOOK_URL',
|
|
936
|
+
'PUSHDEER_KEY'
|
|
935
937
|
]
|
|
936
938
|
// 判断是否存在即时消息推送配置
|
|
937
939
|
const hasIMPushConfig = IM_PUSH_CONFIGS.some(item => !!config[item])
|
|
@@ -939,7 +941,7 @@ async function noticeMaster (comment) {
|
|
|
939
941
|
if (hasIMPushConfig && config.SC_MAIL_NOTIFY !== 'true') return
|
|
940
942
|
const SITE_NAME = config.SITE_NAME
|
|
941
943
|
const NICK = comment.nick
|
|
942
|
-
const IMG = comment
|
|
944
|
+
const IMG = getAvatar(comment)
|
|
943
945
|
const IP = comment.ip
|
|
944
946
|
const MAIL = comment.mail
|
|
945
947
|
const COMMENT = comment.comment
|
|
@@ -1062,7 +1064,7 @@ async function noticeQQ (comment) {
|
|
|
1062
1064
|
return
|
|
1063
1065
|
}
|
|
1064
1066
|
if (config.BLOGGER_EMAIL === comment.mail) return
|
|
1065
|
-
const pushContent = getIMPushContent(comment)
|
|
1067
|
+
const pushContent = getIMPushContent(comment, { withUrl: false })
|
|
1066
1068
|
const qmApiUrl = 'https://qmsg.zendee.cn'
|
|
1067
1069
|
const qmApiParam = {
|
|
1068
1070
|
msg: pushContent.subject + '\n' + pushContent.content.replace(/<br>/g, '\n')
|
|
@@ -1073,8 +1075,20 @@ async function noticeQQ (comment) {
|
|
|
1073
1075
|
console.log('QQ通知结果:', sendResult)
|
|
1074
1076
|
}
|
|
1075
1077
|
|
|
1078
|
+
async function noticePushdeer (comment) {
|
|
1079
|
+
if (!config.PUSHDEER_KEY) return
|
|
1080
|
+
if (config.BLOGGER_EMAIL === comment.mail) return
|
|
1081
|
+
const pushContent = getIMPushContent(comment, { markdown: true })
|
|
1082
|
+
const sendResult = await axios.post('https://api2.pushdeer.com/message/push', {
|
|
1083
|
+
pushkey: config.PUSHDEER_KEY,
|
|
1084
|
+
text: pushContent.subject,
|
|
1085
|
+
desp: pushContent.content
|
|
1086
|
+
})
|
|
1087
|
+
console.log('Pushdeer 通知结果:', sendResult)
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1076
1090
|
// 即时消息推送内容获取
|
|
1077
|
-
function getIMPushContent (comment) {
|
|
1091
|
+
function getIMPushContent (comment, { withUrl = true, markdown = false } = {}) {
|
|
1078
1092
|
const SITE_NAME = config.SITE_NAME
|
|
1079
1093
|
const NICK = comment.nick
|
|
1080
1094
|
const MAIL = comment.mail
|
|
@@ -1083,7 +1097,14 @@ function getIMPushContent (comment) {
|
|
|
1083
1097
|
const SITE_URL = config.SITE_URL
|
|
1084
1098
|
const POST_URL = appendHashToUrl(comment.href || SITE_URL + comment.url, comment.id)
|
|
1085
1099
|
const subject = config.MAIL_SUBJECT_ADMIN || `${SITE_NAME}有新评论了`
|
|
1086
|
-
|
|
1100
|
+
let content = `评论人:${NICK}(${MAIL})<br>评论人IP:${IP}<br>评论内容:${COMMENT}`
|
|
1101
|
+
// Qmsg 会过滤带网址的推送消息,所以不能带网址
|
|
1102
|
+
if (withUrl) {
|
|
1103
|
+
content += `<br>您可以点击 ${markdown ? `[${POST_URL}](${POST_URL})` : POST_URL} 查看回复的完整內容`
|
|
1104
|
+
}
|
|
1105
|
+
if (markdown) {
|
|
1106
|
+
content = content.replace(/<br>/g, '\n\n')
|
|
1107
|
+
}
|
|
1087
1108
|
return {
|
|
1088
1109
|
subject,
|
|
1089
1110
|
content
|
|
@@ -1104,8 +1125,8 @@ async function noticeReply (currentComment) {
|
|
|
1104
1125
|
// 回复自己的评论,不邮件通知
|
|
1105
1126
|
if (currentComment.mail === parentComment.mail) return
|
|
1106
1127
|
const PARENT_NICK = parentComment.nick
|
|
1107
|
-
const IMG = currentComment
|
|
1108
|
-
const PARENT_IMG = parentComment
|
|
1128
|
+
const IMG = getAvatar(currentComment)
|
|
1129
|
+
const PARENT_IMG = getAvatar(parentComment)
|
|
1109
1130
|
const SITE_NAME = config.SITE_NAME
|
|
1110
1131
|
const NICK = currentComment.nick
|
|
1111
1132
|
const COMMENT = currentComment.comment
|
|
@@ -1583,6 +1604,7 @@ async function readConfig () {
|
|
|
1583
1604
|
|
|
1584
1605
|
// 写入配置
|
|
1585
1606
|
async function writeConfig (newConfig) {
|
|
1607
|
+
if (!Object.keys(newConfig).length) return 0
|
|
1586
1608
|
console.log('写入配置:', newConfig)
|
|
1587
1609
|
try {
|
|
1588
1610
|
let updated
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twikoo-func",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.17",
|
|
4
4
|
"description": "A simple comment system based on Tencent CloudBase (tcb).",
|
|
5
5
|
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"crypto-js": "^4.0.0",
|
|
22
22
|
"dompurify": "^2.2.6",
|
|
23
23
|
"jsdom": "^16.4.0",
|
|
24
|
-
"marked": "^
|
|
24
|
+
"marked": "^4.0.12",
|
|
25
25
|
"nodemailer": "^6.4.17",
|
|
26
26
|
"querystring": "^0.2.0",
|
|
27
27
|
"tencentcloud-sdk-nodejs": "^4.0.65",
|