mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-15 14:24:02 +02:00

Some checks failed
Auto Test / armv7-simple-test (18, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / check-linters (push) Has been cancelled
Auto Test / e2e-test (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Merge Conflict Labeler / Labeling (push) Has been cancelled
validate / json-yaml-validate (push) Has been cancelled
validate / validate (push) Has been cancelled
Auto Test / auto-test (18, ARM64) (push) Has been cancelled
Auto Test / auto-test (18, macos-latest) (push) Has been cancelled
Auto Test / auto-test (18, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (18, windows-latest) (push) Has been cancelled
Auto Test / auto-test (20, ARM64) (push) Has been cancelled
Auto Test / auto-test (20, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (20, windows-latest) (push) Has been cancelled
Signed-off-by: ianlv <sunlvyun@outlook.com>
56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
class PushDeer extends NotificationProvider {
|
|
name = "PushDeer";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
const okMsg = "Sent Successfully.";
|
|
const serverUrl = notification.pushdeerServer || "https://api2.pushdeer.com";
|
|
// capture group below is necessary to prevent an ReDOS-attack
|
|
const url = `${serverUrl.trim().replace(/([^/])\/+$/, "$1")}/message/push`;
|
|
|
|
let valid = msg != null && monitorJSON != null && heartbeatJSON != null;
|
|
|
|
let title;
|
|
if (valid && heartbeatJSON.status === UP) {
|
|
title = "## Uptime Kuma: " + monitorJSON.name + " up";
|
|
} else if (valid && heartbeatJSON.status === DOWN) {
|
|
title = "## Uptime Kuma: " + monitorJSON.name + " down";
|
|
} else {
|
|
title = "## Uptime Kuma Message";
|
|
}
|
|
|
|
let data = {
|
|
"pushkey": notification.pushdeerKey,
|
|
"text": title,
|
|
"desp": msg.replace(/\n/g, "\n\n"),
|
|
"type": "markdown",
|
|
};
|
|
|
|
try {
|
|
let res = await axios.post(url, data);
|
|
|
|
if ("error" in res.data) {
|
|
let error = res.data.error;
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
if (res.data.content.result.length === 0) {
|
|
let error = "Invalid PushDeer key";
|
|
this.throwGeneralAxiosError(error);
|
|
} else if (JSON.parse(res.data.content.result[0]).success !== "ok") {
|
|
let error = "Unknown error";
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
return okMsg;
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = PushDeer;
|