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 axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class SpugPush extends NotificationProvider {
@ -11,16 +12,20 @@ class SpugPush extends NotificationProvider {
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
await axios.post(`https://push.spug.cc/send/${notification.templateKey}`, {
"status": heartbeatJSON["status"],
"msg": heartbeatJSON["msg"],
"duration": heartbeatJSON["duration"],
"name": monitorJSON["name"],
"target": this.extractAddress(monitorJSON),
});
let formData = {msg}
const apiUrl = `https://push.spug.cc/send/${notification.templateKey}`;
if (heartbeatJSON == null) {
formData.title = "Uptime Kuma Message";
} else if (heartbeatJSON["status"] === UP) {
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;
} catch (error) {
this.throwGeneralAxiosError(error);
}