twikoo-vercel 1.4.8 → 1.4.12
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/api/index.js +30 -4
- package/package.json +1 -1
package/api/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Twikoo vercel function v1.4.
|
|
2
|
+
* Twikoo vercel function v1.4.12
|
|
3
3
|
* (c) 2020-present iMaeGoo
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -27,7 +27,7 @@ const window = new JSDOM('').window
|
|
|
27
27
|
const DOMPurify = createDOMPurify(window)
|
|
28
28
|
|
|
29
29
|
// 常量 / constants
|
|
30
|
-
const VERSION = '1.4.
|
|
30
|
+
const VERSION = '1.4.12'
|
|
31
31
|
const RES_CODE = {
|
|
32
32
|
SUCCESS: 0,
|
|
33
33
|
NO_PARAM: 100,
|
|
@@ -891,6 +891,7 @@ async function sendNotice (comment) {
|
|
|
891
891
|
noticeWeChat(comment),
|
|
892
892
|
noticePushPlus(comment),
|
|
893
893
|
noticeWeComPush(comment),
|
|
894
|
+
noticeDingTalkHook(comment),
|
|
894
895
|
noticeQQ(comment)
|
|
895
896
|
]).catch(console.error)
|
|
896
897
|
return { code: RES_CODE.SUCCESS }
|
|
@@ -940,7 +941,8 @@ async function noticeMaster (comment) {
|
|
|
940
941
|
'SC_SENDKEY',
|
|
941
942
|
'QM_SENDKEY',
|
|
942
943
|
'PUSH_PLUS_TOKEN',
|
|
943
|
-
'WECOM_API_URL'
|
|
944
|
+
'WECOM_API_URL',
|
|
945
|
+
'DINGTALK_WEBHOOK_URL'
|
|
944
946
|
]
|
|
945
947
|
// 判断是否存在即时消息推送配置
|
|
946
948
|
const hasIMPushConfig = IM_PUSH_CONFIGS.some(item => !!config[item])
|
|
@@ -948,6 +950,9 @@ async function noticeMaster (comment) {
|
|
|
948
950
|
if (hasIMPushConfig && config.SC_MAIL_NOTIFY !== 'true') return
|
|
949
951
|
const SITE_NAME = config.SITE_NAME
|
|
950
952
|
const NICK = comment.nick
|
|
953
|
+
const IMG = comment.avatar
|
|
954
|
+
const IP = comment.ip
|
|
955
|
+
const MAIL = comment.mail
|
|
951
956
|
const COMMENT = comment.comment
|
|
952
957
|
const SITE_URL = config.SITE_URL
|
|
953
958
|
const POST_URL = appendHashToUrl(comment.href || SITE_URL + comment.url, comment.id)
|
|
@@ -958,6 +963,9 @@ async function noticeMaster (comment) {
|
|
|
958
963
|
.replace(/\${SITE_URL}/g, SITE_URL)
|
|
959
964
|
.replace(/\${SITE_NAME}/g, SITE_NAME)
|
|
960
965
|
.replace(/\${NICK}/g, NICK)
|
|
966
|
+
.replace(/\${IMG}/g, IMG)
|
|
967
|
+
.replace(/\${IP}/g, IP)
|
|
968
|
+
.replace(/\${MAIL}/g, MAIL)
|
|
961
969
|
.replace(/\${COMMENT}/g, COMMENT)
|
|
962
970
|
.replace(/\${POST_URL}/g, POST_URL)
|
|
963
971
|
} else {
|
|
@@ -1046,6 +1054,18 @@ async function noticeWeComPush (comment) {
|
|
|
1046
1054
|
console.log('WinxinPush 通知结果:', sendResult)
|
|
1047
1055
|
}
|
|
1048
1056
|
|
|
1057
|
+
// 自定义钉钉WebHook通知
|
|
1058
|
+
async function noticeDingTalkHook (comment) {
|
|
1059
|
+
if (!config.DINGTALK_WEBHOOK_URL) {
|
|
1060
|
+
console.log('没有配置 DingTalk_WebHook,放弃钉钉WebHook推送')
|
|
1061
|
+
return
|
|
1062
|
+
}
|
|
1063
|
+
if (config.BLOGGER_EMAIL === comment.mail) return
|
|
1064
|
+
const DingTalkContent = config.SITE_NAME + '有新评论啦!🎉🎉' + '\n\n' + '@' + comment.nick + ' 说:' + $(comment.comment).text() + '\n' + 'E-mail: ' + comment.mail + '\n' + 'IP: ' + comment.ip + '\n' + '点此查看完整内容:' + appendHashToUrl(comment.href || config.SITE_URL + comment.url, comment.id)
|
|
1065
|
+
const sendResult = await axios.post(config.DINGTALK_WEBHOOK_URL, { msgtype: 'text', text: { content: DingTalkContent } })
|
|
1066
|
+
console.log('钉钉WebHook 通知结果:', sendResult)
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1049
1069
|
// QQ通知
|
|
1050
1070
|
async function noticeQQ (comment) {
|
|
1051
1071
|
if (!config.QM_SENDKEY) {
|
|
@@ -1093,6 +1113,8 @@ async function noticeReply (currentComment) {
|
|
|
1093
1113
|
// 回复自己的评论,不邮件通知
|
|
1094
1114
|
if (currentComment.mail === parentComment.mail) return
|
|
1095
1115
|
const PARENT_NICK = parentComment.nick
|
|
1116
|
+
const IMG = currentComment.avatar
|
|
1117
|
+
const PARENT_IMG = parentComment.avatar
|
|
1096
1118
|
const SITE_NAME = config.SITE_NAME
|
|
1097
1119
|
const NICK = currentComment.nick
|
|
1098
1120
|
const COMMENT = currentComment.comment
|
|
@@ -1103,6 +1125,8 @@ async function noticeReply (currentComment) {
|
|
|
1103
1125
|
let emailContent
|
|
1104
1126
|
if (config.MAIL_TEMPLATE) {
|
|
1105
1127
|
emailContent = config.MAIL_TEMPLATE
|
|
1128
|
+
.replace(/\${IMG}/g, IMG)
|
|
1129
|
+
.replace(/\${PARENT_IMG}/g, PARENT_IMG)
|
|
1106
1130
|
.replace(/\${SITE_URL}/g, SITE_URL)
|
|
1107
1131
|
.replace(/\${SITE_NAME}/g, SITE_NAME)
|
|
1108
1132
|
.replace(/\${PARENT_NICK}/g, PARENT_NICK)
|
|
@@ -1168,6 +1192,7 @@ async function parse (comment) {
|
|
|
1168
1192
|
ip: request.headers['x-real-ip'],
|
|
1169
1193
|
master: isBloggerMail,
|
|
1170
1194
|
url: comment.url,
|
|
1195
|
+
avatar: getAvatar(comment),
|
|
1171
1196
|
href: comment.href,
|
|
1172
1197
|
comment: DOMPurify.sanitize(comment.comment, { FORBID_TAGS: ['style'], FORBID_ATTR: ['style'] }),
|
|
1173
1198
|
pid: comment.pid ? comment.pid : comment.rid,
|
|
@@ -1458,7 +1483,7 @@ function getAvatar (comment) {
|
|
|
1458
1483
|
if (comment.avatar) {
|
|
1459
1484
|
return comment.avatar
|
|
1460
1485
|
} else {
|
|
1461
|
-
const gravatarCdn = config.GRAVATAR_CDN || 'cn
|
|
1486
|
+
const gravatarCdn = config.GRAVATAR_CDN || 'cravatar.cn'
|
|
1462
1487
|
const defaultGravatar = config.DEFAULT_GRAVATAR || 'identicon'
|
|
1463
1488
|
const mailMd5 = comment.mailMd5 || md5(comment.mail)
|
|
1464
1489
|
return `https://${gravatarCdn}/avatar/${mailMd5}?d=${defaultGravatar}`
|
|
@@ -1504,6 +1529,7 @@ async function getConfig () {
|
|
|
1504
1529
|
DEFAULT_GRAVATAR: config.DEFAULT_GRAVATAR,
|
|
1505
1530
|
SHOW_IMAGE: config.SHOW_IMAGE || 'true',
|
|
1506
1531
|
IMAGE_CDN: config.IMAGE_CDN,
|
|
1532
|
+
IMAGE_CDN_TOKEN: config.IMAGE_CDN_TOKEN,
|
|
1507
1533
|
SHOW_EMOTION: config.SHOW_EMOTION || 'true',
|
|
1508
1534
|
EMOTION_CDN: config.EMOTION_CDN,
|
|
1509
1535
|
COMMENT_PLACEHOLDER: config.COMMENT_PLACEHOLDER,
|
package/package.json
CHANGED