feat: 添加Gotify推送

This commit is contained in:
andywang425 2023-09-02 17:54:20 +08:00 committed by shanmite
parent 201770573e
commit 69c297ecaa
2 changed files with 60 additions and 7 deletions

View File

@ -92,6 +92,8 @@ module.exports = Object.freeze({
SMTP_PORT: "",
SMTP_USER: "",
SMTP_PASS: "",
SMTP_TO_USER: ""
SMTP_TO_USER: "",
GOTIFY_URL: "",
GOTIFY_APPKEY: ""
}
})

View File

@ -80,6 +80,13 @@ let SMTP_USER = '';
let SMTP_PASS = '';
let SMTP_TO_USER = '';
// ====================================Gotify======================================
// 官方文档https://gotify.net/docs/pushmsg
// 此处填你的Gotify消息推送地址例如http://localhost/message
let GOTIFY_URL = '';
// 此处填你想推送的Application的Token不包含推送时额外添加的前缀 Bearer
let GOTIFY_APPKEY = '';
//==========================云端环境变量的判断与接收=========================
if (process.env.SCKEY) {
SCKEY = process.env.SCKEY;
@ -190,6 +197,13 @@ if (process.env.SMTP_TO_USER) {
SMTP_TO_USER = process.env.SMTP_TO_USER;
}
if (process.env.GOTIFY_URL) {
GOTIFY_URL = process.env.GOTIFY_URL;
if (process.env.GOTIFY_APPKEY) {
GOTIFY_APPKEY = process.env.GOTIFY_APPKEY
}
}
//==========================云端环境变量的判断与接收=========================
async function sendNotify(text, desp, params = {}) {
@ -223,7 +237,9 @@ async function sendNotify(text, desp, params = {}) {
// Qmsg
qmsg(text, desp),
//电子邮件
email(text, desp)
email(text, desp),
// Gotify
gotifyNotify(text, desp)
])
}
@ -820,6 +836,41 @@ function pushPlusNotify(text, desp) {
})
}
function gotifyNotify(test, desp) {
return new Promise(resolve => {
if (GOTIFY_APPKEY) {
send({
method: 'POST',
url: GOTIFY_URL,
contents: {
title: test,
message: desp,
},
config: {
retry: false
},
headers: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
'authorization': 'Bearer ' + GOTIFY_APPKEY
},
success: () => {
// HTTP 响应码 200 就说明成功了
log.info('发送通知', 'Gotify 发送通知消息成功')
resolve();
},
failure: err => {
log.error('发送通知', 'Gotify 发送通知调用API失败' + err)
resolve();
}
})
} else {
log.debug('发送通知', '您未提供Gotify推送所需的GOTIFY_APPKEY取消Gotify推送消息通知');
resolve()
}
})
}
async function qmsg(text, desp) {
return new Promise(resolve => {
if (QMSG_KEY) {