Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增对 pushoo 中自定义 webhook 的支持,更新了 eslint 相关组件版本,解决本地开发环境依赖冲突 #776

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo",
"version": "1.6.40",
"version": "1.6.41",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请勿提交版本号,版本号由 @imaegoo 统一维护,只在发版时自动递增

"description": "A simple comment system.",
"keywords": [
"twikoojs",
Expand Down Expand Up @@ -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",
Comment on lines +52 to +54
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

勿升级 eslint,导致流水线不通过

"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",
Expand All @@ -71,4 +71,4 @@
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.4.0"
}
}
}
3 changes: 2 additions & 1 deletion src/client/utils/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const pushooChannels = [
'pushdeer',
'igot',
'telegram',
'feishu'
'feishu',
'webhook'
].map(s => `"${s}"`)

const smtpServices = [
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.40",
"version": "1.6.41",
"description": "A simple comment system.",
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
76 changes: 46 additions & 30 deletions src/server/function/twikoo/utils/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const logger = require('./logger')

let nodemailer

function lazilyGetNodemailer () {
function lazilyGetNodemailer() {
return nodemailer ?? (nodemailer = getNodemailer())
}

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),
Expand All @@ -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('数据库配置不存在')
Expand Down Expand Up @@ -69,7 +69,7 @@ const fn = {
}
},
// 博主通知
async noticeMaster (comment, config) {
async noticeMaster(comment, config) {
if (!transporter && !await fn.initMailer({ config })) {
logger.info('未配置邮箱或邮箱配置有误,不通知')
return
Expand Down Expand Up @@ -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
Expand All @@ -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,
Comment on lines +150 to +154
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

与通知无关的内容不需要传给 pushoo

}
}
}
})
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 on lines +175 to +176
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多余的行首空格


评论内容:${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
Comment on lines +188 to +191
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

命名规则:小驼峰

}
},
// 回复通知
async noticeReply (currentComment, config, getParentComment) {
async noticeReply(currentComment, config, getParentComment) {
if (!currentComment.pid) {
logger.info('无父级评论,不通知')
return
Expand Down Expand Up @@ -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 {
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.40",
"version": "1.6.41",
"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/self-hosted/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tkserver",
"version": "1.6.40",
"version": "1.6.41",
"description": "A simple comment system.",
"keywords": [
"twikoo",
Expand Down
2 changes: 1 addition & 1 deletion 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.40",
"version": "1.6.41",
"description": "A simple comment system.",
"author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
Loading