From fb059f5e91bbe8ef97cc9107b3af6996b82e4b0d Mon Sep 17 00:00:00 2001 From: ngc7331 Date: Sat, 2 Apr 2022 14:40:33 +0800 Subject: [PATCH 1/5] Add support for Pushdeer notifications --- server/notification-providers/pushdeer.js | 52 +++++++++++++++++++++++ server/notification.js | 2 + src/components/notifications/Pushdeer.vue | 19 +++++++++ src/components/notifications/index.js | 2 + 4 files changed, 75 insertions(+) create mode 100644 server/notification-providers/pushdeer.js create mode 100644 src/components/notifications/Pushdeer.vue diff --git a/server/notification-providers/pushdeer.js b/server/notification-providers/pushdeer.js new file mode 100644 index 000000000..f86577693 --- /dev/null +++ b/server/notification-providers/pushdeer.js @@ -0,0 +1,52 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class Pushdeer extends NotificationProvider { + + name = "Pushdeer"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + let pushdeerlink = "https://api2.pushdeer.com/message/push"; + + let valid = msg != null && monitorJSON != null && heartbeatJSON != null; + + let title; + if (valid && heartbeatJSON.status == UP) { + title = "## UptimeKuma: " + monitorJSON.name + " up"; + } else if (valid && heartbeatJSON.status == DOWN) { + title = "## UptimeKuma: " + monitorJSON.name + " down"; + } else { + title = "## UptimeKuma Message"; + } + + let data = { + "pushkey": notification.pushdeerKey, + "text": title, + "desp": msg.replace(/\n/g, "\n\n"), + "type": "markdown", + }; + + try { + let res = await axios.post(pushdeerlink, 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; diff --git a/server/notification.js b/server/notification.js index a83a8cdce..e3d37bafb 100644 --- a/server/notification.js +++ b/server/notification.js @@ -32,6 +32,7 @@ const GoogleChat = require("./notification-providers/google-chat"); const Gorush = require("./notification-providers/gorush"); const Alerta = require("./notification-providers/alerta"); const OneBot = require("./notification-providers/onebot"); +const Pushdeer = require("./notification-providers/pushdeer"); class Notification { @@ -75,6 +76,7 @@ class Notification { new Gorush(), new Alerta(), new OneBot(), + new Pushdeer(), ]; for (let item of list) { diff --git a/src/components/notifications/Pushdeer.vue b/src/components/notifications/Pushdeer.vue new file mode 100644 index 000000000..762715504 --- /dev/null +++ b/src/components/notifications/Pushdeer.vue @@ -0,0 +1,19 @@ + + + \ No newline at end of file diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 2fa36c0f4..2a7d77933 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -30,6 +30,7 @@ import GoogleChat from "./GoogleChat.vue"; import Gorush from "./Gorush.vue"; import Alerta from "./Alerta.vue"; import OneBot from "./OneBot.vue"; +import Pushdeer from "./Pushdeer.vue"; /** * Manage all notification form. @@ -69,6 +70,7 @@ const NotificationFormList = { "gorush": Gorush, "alerta": Alerta, "OneBot": OneBot, + "Pushdeer": Pushdeer, }; export default NotificationFormList; From 93c51504f93d7828674f797f06e24d3a3fcd9b95 Mon Sep 17 00:00:00 2001 From: ngc7331 Date: Wed, 6 Apr 2022 08:38:48 +0800 Subject: [PATCH 2/5] fixes: formatting and security issues Co-authored-by: Matthew Nickson --- server/notification-providers/pushdeer.js | 6 +++--- src/components/notifications/Pushdeer.vue | 6 +++--- src/languages/en.js | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/notification-providers/pushdeer.js b/server/notification-providers/pushdeer.js index f86577693..6831b8cce 100644 --- a/server/notification-providers/pushdeer.js +++ b/server/notification-providers/pushdeer.js @@ -14,11 +14,11 @@ class Pushdeer extends NotificationProvider { let title; if (valid && heartbeatJSON.status == UP) { - title = "## UptimeKuma: " + monitorJSON.name + " up"; + title = "## Uptime Kuma: " + monitorJSON.name + " up"; } else if (valid && heartbeatJSON.status == DOWN) { - title = "## UptimeKuma: " + monitorJSON.name + " down"; + title = "## Uptime Kuma: " + monitorJSON.name + " down"; } else { - title = "## UptimeKuma Message"; + title = "## Uptime Kuma Message"; } let data = { diff --git a/src/components/notifications/Pushdeer.vue b/src/components/notifications/Pushdeer.vue index 762715504..80d0f48ff 100644 --- a/src/components/notifications/Pushdeer.vue +++ b/src/components/notifications/Pushdeer.vue @@ -1,11 +1,11 @@ @@ -16,4 +16,4 @@ export default { HiddenInput, }, }; - \ No newline at end of file + diff --git a/src/languages/en.js b/src/languages/en.js index 2dcec68cc..f432a9c46 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -451,4 +451,5 @@ export default { onebotPrivateMessage: "Private", onebotUserOrGroupId: "Group/User ID", onebotSafetyTips: "For safety, must set access token", + "Pushdeer Key": "Pushdeer Key", }; From fb0064082ee4a301e3c1afb969e347cfd9600878 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Thu, 14 Apr 2022 14:29:54 +0800 Subject: [PATCH 3/5] Change Pushdeer to PushDeer --- server/notification-providers/pushdeer.js | 8 ++++---- server/notification.js | 4 ++-- .../notifications/{Pushdeer.vue => PushDeer.vue} | 2 +- src/components/notifications/index.js | 4 ++-- src/languages/en.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) rename src/components/notifications/{Pushdeer.vue => PushDeer.vue} (96%) diff --git a/server/notification-providers/pushdeer.js b/server/notification-providers/pushdeer.js index 6831b8cce..620c1b20a 100644 --- a/server/notification-providers/pushdeer.js +++ b/server/notification-providers/pushdeer.js @@ -2,9 +2,9 @@ const NotificationProvider = require("./notification-provider"); const axios = require("axios"); const { DOWN, UP } = require("../../src/util"); -class Pushdeer extends NotificationProvider { +class PushDeer extends NotificationProvider { - name = "Pushdeer"; + name = "PushDeer"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { let okMsg = "Sent Successfully."; @@ -36,7 +36,7 @@ class Pushdeer extends NotificationProvider { this.throwGeneralAxiosError(error); } if (res.data.content.result.length === 0) { - let error = "Invalid Pushdeer key"; + let error = "Invalid PushDeer key"; this.throwGeneralAxiosError(error); } else if (JSON.parse(res.data.content.result[0]).success != "ok") { let error = "Unknown error"; @@ -49,4 +49,4 @@ class Pushdeer extends NotificationProvider { } } -module.exports = Pushdeer; +module.exports = PushDeer; diff --git a/server/notification.js b/server/notification.js index e3d37bafb..842e0e2f8 100644 --- a/server/notification.js +++ b/server/notification.js @@ -32,7 +32,7 @@ const GoogleChat = require("./notification-providers/google-chat"); const Gorush = require("./notification-providers/gorush"); const Alerta = require("./notification-providers/alerta"); const OneBot = require("./notification-providers/onebot"); -const Pushdeer = require("./notification-providers/pushdeer"); +const PushDeer = require("./notification-providers/pushdeer"); class Notification { @@ -76,7 +76,7 @@ class Notification { new Gorush(), new Alerta(), new OneBot(), - new Pushdeer(), + new PushDeer(), ]; for (let item of list) { diff --git a/src/components/notifications/Pushdeer.vue b/src/components/notifications/PushDeer.vue similarity index 96% rename from src/components/notifications/Pushdeer.vue rename to src/components/notifications/PushDeer.vue index 80d0f48ff..c2b7f5cb0 100644 --- a/src/components/notifications/Pushdeer.vue +++ b/src/components/notifications/PushDeer.vue @@ -1,6 +1,6 @@