From 02adbd5fa2eb828bde92e9cc3532a45a2c7086ca Mon Sep 17 00:00:00 2001 From: guole Date: Thu, 2 Jan 2025 17:39:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9=20pushoo=20?= =?UTF-8?q?=E4=B8=AD=E8=87=AA=E5=AE=9A=E4=B9=89=20webhook=20=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=BA=86=20eslint?= =?UTF-8?q?=20=E7=9B=B8=E5=85=B3=E7=BB=84=E4=BB=B6=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=9C=AC=E5=9C=B0=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=BE=9D=E8=B5=96=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 16 ++--- src/client/utils/i18n/i18n.js | 3 +- src/server/function/twikoo/package.json | 2 +- src/server/function/twikoo/utils/notify.js | 76 +++++++++++++--------- src/server/netlify/package.json | 2 +- src/server/self-hosted/package.json | 2 +- src/server/vercel/package.json | 2 +- 7 files changed, 60 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 260c6148e..76cb72435 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "twikoo", - "version": "1.6.40", + "version": "1.6.41", "description": "A simple comment system.", "keywords": [ "twikoojs", @@ -49,13 +49,13 @@ "cross-env": "^7.0.3", "css-loader": "^6.5.1", "element-ui": "^2.15.6", - "eslint": "^8.2.0", - "eslint-config-standard": "^16.0.3", - "eslint-plugin-import": "^2.25.3", + "eslint": "^8.57.1", + "eslint-config-standard": "^17.1.0", + "eslint-plugin-import": "^2.26.0", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^5.1.1", - "eslint-plugin-standard": "^4.1.0", - "eslint-plugin-vue": "^8.0.3", + "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-standard": "^5.0.0", + "eslint-plugin-vue": "^9.0.0", "js-sha256": "^0.11.0", "marked": "^4.0.12", "mini-css-extract-plugin": "^2.6.1", @@ -71,4 +71,4 @@ "webpack-cli": "^4.9.1", "webpack-dev-server": "^4.4.0" } -} +} \ No newline at end of file diff --git a/src/client/utils/i18n/i18n.js b/src/client/utils/i18n/i18n.js index 306082c20..a72fe2df6 100644 --- a/src/client/utils/i18n/i18n.js +++ b/src/client/utils/i18n/i18n.js @@ -23,7 +23,8 @@ const pushooChannels = [ 'pushdeer', 'igot', 'telegram', - 'feishu' + 'feishu', + 'webhook' ].map(s => `"${s}"`) const smtpServices = [ diff --git a/src/server/function/twikoo/package.json b/src/server/function/twikoo/package.json index 82bc8255b..e137550fb 100644 --- a/src/server/function/twikoo/package.json +++ b/src/server/function/twikoo/package.json @@ -1,6 +1,6 @@ { "name": "twikoo-func", - "version": "1.6.40", + "version": "1.6.41", "description": "A simple comment system.", "author": "imaegoo (https://github.com/imaegoo)", "license": "MIT", diff --git a/src/server/function/twikoo/utils/notify.js b/src/server/function/twikoo/utils/notify.js index f67875112..5d5eaf4a6 100644 --- a/src/server/function/twikoo/utils/notify.js +++ b/src/server/function/twikoo/utils/notify.js @@ -11,7 +11,7 @@ const logger = require('./logger') let nodemailer -function lazilyGetNodemailer () { +function lazilyGetNodemailer() { return nodemailer ?? (nodemailer = getNodemailer()) } @@ -19,7 +19,7 @@ let transporter const fn = { // 发送通知 - async sendNotice (comment, config, getParentComment) { + async sendNotice(comment, config, getParentComment) { if (comment.isSpam && config.NOTIFY_SPAM === 'false') return await Promise.all([ fn.noticeMaster(comment, config), @@ -30,7 +30,7 @@ const fn = { }) }, // 初始化邮件插件 - async initMailer ({ config, throwErr = false } = {}) { + async initMailer({ config, throwErr = false } = {}) { try { if (!config || !config.SMTP_USER || !config.SMTP_PASS) { throw new Error('数据库配置不存在') @@ -69,7 +69,7 @@ const fn = { } }, // 博主通知 - async noticeMaster (comment, config) { + async noticeMaster(comment, config) { if (!transporter && !await fn.initMailer({ config })) { logger.info('未配置邮箱或邮箱配置有误,不通知') return @@ -130,7 +130,7 @@ const fn = { return sendResult }, // 即时消息通知 - async noticePushoo (comment, config) { + async noticePushoo(comment, config) { if (!config.PUSHOO_CHANNEL || !config.PUSHOO_TOKEN) { logger.info('没有配置 pushoo,放弃即时消息通知') return @@ -140,43 +140,59 @@ const fn = { return } const pushContent = fn.getIMPushContent(comment, config) - const sendResult = await pushoo(config.PUSHOO_CHANNEL, { - token: config.PUSHOO_TOKEN, - title: pushContent.subject, - content: pushContent.content, - options: { - bark: { - url: pushContent.url + try { + const sendResult = await pushoo(config.PUSHOO_CHANNEL, { + token: config.PUSHOO_TOKEN, + title: pushContent.subject, + content: pushContent.content, + options: { + data: { + url: pushContent.url, + text: pushContent.TEXT, + ip: pushContent.IP, + nick: pushContent.NICK, + mail: pushContent.MAIL, + } } - } - }) - logger.info('即时消息通知结果:', sendResult) + }) + logger.info('即时消息通知结果:', sendResult) + } catch (e) { + throw new Error(error); + } }, // 即时消息推送内容获取 - getIMPushContent (comment, config) { + getIMPushContent(comment, config) { const SITE_NAME = config.SITE_NAME const NICK = comment.nick const MAIL = comment.mail const IP = comment.ip const COMMENT = $(comment.comment).text() + const TEXT = COMMENT; const SITE_URL = config.SITE_URL const POST_URL = fn.appendHashToUrl(comment.href || SITE_URL + comment.url, comment.id) const subject = config.MAIL_SUBJECT_ADMIN || `${SITE_NAME}有新评论了` - const content = `评论人:${NICK} ([${MAIL}](mailto:${MAIL})) - -评论人IP:${IP} + const content = + ` + 评论人:${NICK} ([${MAIL}](mailto:${MAIL})) -评论内容:${COMMENT} + 评论人IP:${IP} + + 评论内容:${COMMENT} -原文链接:[${POST_URL}](${POST_URL})` - return { - subject, - content, - url: POST_URL - } - }, + 原文链接:[${POST_URL}](${POST_URL}) + ` + return { + subject, + content, + url: POST_URL, + NICK, + MAIL, + IP, + TEXT + } + }, // 回复通知 - async noticeReply (currentComment, config, getParentComment) { + async noticeReply(currentComment, config, getParentComment) { if (!currentComment.pid) { logger.info('无父级评论,不通知') return @@ -248,14 +264,14 @@ const fn = { logger.log('回复通知结果:', sendResult) return sendResult }, - appendHashToUrl (url, hash) { + appendHashToUrl(url, hash) { if (url.indexOf('#') === -1) { return `${url}#${hash}` } else { return `${url.substring(0, url.indexOf('#'))}#${hash}` } }, - async emailTest (event, config, isAdminUser) { + async emailTest(event, config, isAdminUser) { const res = {} if (isAdminUser) { try { diff --git a/src/server/netlify/package.json b/src/server/netlify/package.json index 6008941a9..263198e69 100644 --- a/src/server/netlify/package.json +++ b/src/server/netlify/package.json @@ -1,6 +1,6 @@ { "name": "twikoo-netlify", - "version": "1.6.40", + "version": "1.6.41", "description": "A simple comment system.", "author": "imaegoo (https://github.com/imaegoo)", "license": "MIT", diff --git a/src/server/self-hosted/package.json b/src/server/self-hosted/package.json index b405202cb..305517c18 100644 --- a/src/server/self-hosted/package.json +++ b/src/server/self-hosted/package.json @@ -1,6 +1,6 @@ { "name": "tkserver", - "version": "1.6.40", + "version": "1.6.41", "description": "A simple comment system.", "keywords": [ "twikoo", diff --git a/src/server/vercel/package.json b/src/server/vercel/package.json index a8dddfda9..be296deb9 100644 --- a/src/server/vercel/package.json +++ b/src/server/vercel/package.json @@ -1,6 +1,6 @@ { "name": "twikoo-vercel", - "version": "1.6.40", + "version": "1.6.41", "description": "A simple comment system.", "author": "imaegoo (https://github.com/imaegoo)", "license": "MIT", From 9cb2b767a13dfd271ddc413f139d74632ce230f1 Mon Sep 17 00:00:00 2001 From: guole Date: Mon, 6 Jan 2025 09:48:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=20eslint-plugin-n=20=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 76cb72435..af43e59f6 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "eslint": "^8.57.1", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.26.0", + "eslint-plugin-n": "^17.15.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^6.0.0", "eslint-plugin-standard": "^5.0.0", @@ -71,4 +72,4 @@ "webpack-cli": "^4.9.1", "webpack-dev-server": "^4.4.0" } -} \ No newline at end of file +}