diff --git a/server/notification-providers/pushdeer.js b/server/notification-providers/pushdeer.js new file mode 100644 index 000000000..620c1b20a --- /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 = "## 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(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..842e0e2f8 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/PingChart.vue b/src/components/PingChart.vue index 4ff4c708f..9132b4e90 100644 --- a/src/components/PingChart.vue +++ b/src/components/PingChart.vue @@ -220,6 +220,7 @@ export default { if (newPeriod == "0") { newPeriod = null; this.heartbeatList = null; + this.$root.storage().removeItem(`chart-period-${this.monitorId}`); } else { this.loading = true; @@ -228,6 +229,7 @@ export default { toast.error(res.msg); } else { this.heartbeatList = res.data; + this.$root.storage()[`chart-period-${this.monitorId}`] = newPeriod; } this.loading = false; }); @@ -248,6 +250,12 @@ export default { }, { deep: true } ); + + // Load chart period from storage if saved + let period = this.$root.storage()[`chart-period-${this.monitorId}`]; + if (period != null) { + this.chartPeriodHrs = Math.min(period, 6); + } } }; diff --git a/src/components/notifications/PushDeer.vue b/src/components/notifications/PushDeer.vue new file mode 100644 index 000000000..c2b7f5cb0 --- /dev/null +++ b/src/components/notifications/PushDeer.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 2fa36c0f4..496d35fa0 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; diff --git a/src/languages/en.js b/src/languages/en.js index 2dcec68cc..0ba98e11c 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", };