mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-21 17:29:39 +08:00
feat(notification): 新增 PushPlusPlus 通知支持
- 在 notification.js 中添加 PushPlusPlus 通知提供商 - 在 NotificationDialog.vue 中添加 PushPlusPlus 选项 - 在 notifications/index.js 中导入并注册 PushPlusPlus 组件
This commit is contained in:
42
server/notification-providers/pushplusplus.js
Normal file
42
server/notification-providers/pushplusplus.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
const { DOWN, UP } = require("../../src/util");
|
||||
|
||||
class PushPlusPlus extends NotificationProvider {
|
||||
name = "PushPlusPlus";
|
||||
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
const url = `https://pushplus.plus/send`;
|
||||
try {
|
||||
await axios.post(notification.pushPlusPlusToken, {
|
||||
"title": this.checkStatus(heartbeatJSON, monitorJSON),
|
||||
"content": msg,
|
||||
});
|
||||
|
||||
return okMsg;
|
||||
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted title for message
|
||||
* @param {?object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||
* @param {?object} monitorJSON Monitor details (For Up/Down only)
|
||||
* @returns {string} Formatted title
|
||||
*/
|
||||
checkStatus(heartbeatJSON, monitorJSON) {
|
||||
let title = "UptimeKuma Message";
|
||||
if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||
title = "UptimeKuma Monitor Up " + monitorJSON["name"];
|
||||
}
|
||||
if (heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
||||
title = "UptimeKuma Monitor Down " + monitorJSON["name"];
|
||||
}
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PushPlusPlus;
|
Reference in New Issue
Block a user