-
Notifications
You must be signed in to change notification settings - Fork 324
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "twikoo", | ||
"version": "1.6.40", | ||
"version": "1.6.41", | ||
"description": "A simple comment system.", | ||
"keywords": [ | ||
"twikoojs", | ||
|
@@ -49,13 +49,14 @@ | |
"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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 勿升级 eslint,导致流水线不通过 |
||
"eslint-plugin-n": "^17.15.1", | ||
"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", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,15 @@ | |
|
||
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), | ||
|
@@ -30,7 +30,7 @@ | |
}) | ||
}, | ||
// 初始化邮件插件 | ||
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 @@ | |
} | ||
}, | ||
// 博主通知 | ||
async noticeMaster (comment, config) { | ||
async noticeMaster(comment, config) { | ||
if (!transporter && !await fn.initMailer({ config })) { | ||
logger.info('未配置邮箱或邮箱配置有误,不通知') | ||
return | ||
|
@@ -130,7 +130,7 @@ | |
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 @@ | |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
Check failure on line 160 in src/server/function/twikoo/utils/notify.js GitHub Actions / build (18.x)
|
||
} | ||
}, | ||
// 即时消息推送内容获取 | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -248,14 +264,14 @@ | |
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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请勿提交版本号,版本号由 @imaegoo 统一维护,只在发版时自动递增