Add SpugPush notification provider

This commit is contained in:
vapao 2025-05-02 14:38:20 +08:00
parent 9eb55be198
commit ab68c35ad6

View file

@ -1,5 +1,6 @@
const NotificationProvider = require("./notification-provider"); const NotificationProvider = require("./notification-provider");
const axios = require("axios"); const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class SpugPush extends NotificationProvider { class SpugPush extends NotificationProvider {
@ -11,16 +12,20 @@ class SpugPush extends NotificationProvider {
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully."; let okMsg = "Sent Successfully.";
try { try {
await axios.post(`https://push.spug.cc/send/${notification.templateKey}`, { let formData = {msg}
"status": heartbeatJSON["status"], const apiUrl = `https://push.spug.cc/send/${notification.templateKey}`;
"msg": heartbeatJSON["msg"], if (heartbeatJSON == null) {
"duration": heartbeatJSON["duration"], formData.title = "Uptime Kuma Message";
"name": monitorJSON["name"], } else if (heartbeatJSON["status"] === UP) {
"target": this.extractAddress(monitorJSON), formData.title = `UptimeKuma 「${monitorJSON["name"]}」 is Up`;
}); formData.msg = `[✅ Up] ${heartbeatJSON["msg"]}`
} else if (heartbeatJSON["status"] === DOWN) {
formData.title = `UptimeKuma 「${monitorJSON["name"]}」 is Down`;
formData.msg = `[🔴 Down] ${heartbeatJSON["msg"]}`
}
await axios.post(apiUrl, formData);
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error); this.throwGeneralAxiosError(error);
} }