增加 ntfy 通知 (#2537)

Co-authored-by: qiaoyun680 <qiaoyun680>
This commit is contained in:
qiaoyun680
2024-10-22 21:47:38 +08:00
committed by GitHub
parent 3822c37fa0
commit 185fd2ff91
9 changed files with 1142 additions and 4 deletions
+41
View File
@@ -95,6 +95,10 @@ const push_config = {
WEBHOOK_HEADERS: '', // 自定义通知 请求头
WEBHOOK_METHOD: '', // 自定义通知 请求方法
WEBHOOK_CONTENT_TYPE: '', // 自定义通知 content-type
NTFY_URL: '', // ntfy地址,如https://ntfy.sh,默认为https://ntfy.sh
NTFY_TOPIC: '', // ntfy的消息应用topic
NTFY_PRIORITY: '3', // 推送消息优先级,默认为3
};
for (const key in push_config) {
@@ -1188,6 +1192,42 @@ function webhookNotify(text, desp) {
});
}
function ntfyNotify(text, desp) {
return new Promise((resolve) => {
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY } = push_config;
if (NTFY_TOPIC) {
const options = {
url: NTFY_URL || `https://ntfy.sh`,
body: `${desp}\n${text}`,
headers: {
'Title': 'qinglong',
'Priority': NTFY_PRIORITY || '3'
},
timeout,
};
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log('Ntfy 通知调用API失败😞\n', err);
} else {
if (data.success) {
console.log('Ntfy 发送通知消息成功🎉\n');
} else {
console.log(`Ntfy 发送通知消息异常 ${JSON.stringify(data)}`);
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
});
} else {
resolve();
}
});
}
function parseString(input, valueFormatFn) {
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
const matches = {};
@@ -1316,6 +1356,7 @@ async function sendNotify(text, desp, params = {}) {
chronocatNotify(text, desp), // Chronocat
webhookNotify(text, desp), // 自定义通知
qmsgNotify(text, desp), // 自定义通知
ntfyNotify(text, desp), // Ntfy
]);
}