From 9ade9af1e29979e8f81b461eda13f86560939d6a Mon Sep 17 00:00:00 2001 From: Niyas Date: Thu, 5 Aug 2021 21:41:11 +0530 Subject: [PATCH 01/10] Discord enhancements --- server/notification.js | 78 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/server/notification.js b/server/notification.js index f53b681a..06926b31 100644 --- a/server/notification.js +++ b/server/notification.js @@ -83,41 +83,91 @@ class Notification { return await Notification.smtp(notification, msg) } else if (notification.type === "discord") { + let kumaURL = notification.discorduptimekumaUrl || "https://github.com/louislam/uptime-kuma"; + let dashboardURL = notification.discorduptimekumaUrl + '/dashboard/' + monitorJSON["id"]; try { // If heartbeatJSON is null, assume we're testing. if (heartbeatJSON == null) { - let data = { - username: "Uptime-Kuma", + let discordtestdata = { + username: "Uptime Kuma", content: msg, } - await axios.post(notification.discordWebhookUrl, data) + await axios.post(notification.discordWebhookUrl, discordtestdata) return okMsg; } // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] == 0) { - var alertColor = "16711680"; - } else if (heartbeatJSON["status"] == 1) { - var alertColor = "65280"; - } - let data = { - username: "Uptime-Kuma", + let discorddowndata = { + username: "Uptime Kuma", embeds: [{ - title: "Uptime-Kuma Alert", - color: alertColor, + title: "❌ One of your services went down. ❌", + color: 16711680, + timestamp: heartbeatJSON["time"], fields: [ + { + name: "Service Name", + value: monitorJSON["name"], + }, + { + name: "Service URL", + value: monitorJSON["url"], + }, { name: "Time (UTC)", value: heartbeatJSON["time"], }, { - name: "Message", - value: msg, + name: "Error", + value: heartbeatJSON["msg"], + }, + { + name: "Visit Service Dashboard", + value: "[Visit Dashboard]("+ dashboardURL + ")", + }, + { + name: "Visit Uptime Kuma", + value: "[Visit]("+ kumaURL +")", }, ], }], } - await axios.post(notification.discordWebhookUrl, data) + await axios.post(notification.discordWebhookUrl, discorddowndata) return okMsg; + + } else if (heartbeatJSON["status"] == 1) { + let discordupdata = { + username: "Uptime Kuma", + embeds: [{ + title: "✅ Your service " + monitorJSON["name"] + " is up! ✅", + color: 65280, + timestamp: heartbeatJSON["time"], + fields: [ + { + name: "Service Name", + value: monitorJSON["name"], + }, + { + name: "Service URL", + value: "[Visit Service]("+ monitorJSON["url"] +")", + }, + { + name: "Time (UTC)", + value: heartbeatJSON["time"], + }, + { + name: "Ping", + value: heartbeatJSON["ping"] + "ms", + }, + { + name: "Visit Uptime Kuma", + value: "[Visit]("+ kumaURL +")", + }, + ], + }], + } + await axios.post(notification.discordWebhookUrl, discordupdata) + return okMsg; + } } catch (error) { throwGeneralAxiosError(error) } From 908176c910e59740efa8238961d73bd3d12ef28f Mon Sep 17 00:00:00 2001 From: Niyas Date: Thu, 5 Aug 2021 21:42:45 +0530 Subject: [PATCH 02/10] Discord enhancements --- src/components/NotificationDialog.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 4eea85d6..3a80a929 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -143,6 +143,8 @@
+ +
You can get this by going to Server Settings -> Integrations -> Create Webhook
From 3a7414125a6af1eb24167f8a7eddee1dd7c926f7 Mon Sep 17 00:00:00 2001 From: Niyas Date: Fri, 6 Aug 2021 17:37:22 +0530 Subject: [PATCH 03/10] Updated discord embeds --- server/notification.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/server/notification.js b/server/notification.js index 06926b31..bf4bac54 100644 --- a/server/notification.js +++ b/server/notification.js @@ -83,8 +83,6 @@ class Notification { return await Notification.smtp(notification, msg) } else if (notification.type === "discord") { - let kumaURL = notification.discorduptimekumaUrl || "https://github.com/louislam/uptime-kuma"; - let dashboardURL = notification.discorduptimekumaUrl + '/dashboard/' + monitorJSON["id"]; try { // If heartbeatJSON is null, assume we're testing. if (heartbeatJSON == null) { @@ -120,14 +118,6 @@ class Notification { name: "Error", value: heartbeatJSON["msg"], }, - { - name: "Visit Service Dashboard", - value: "[Visit Dashboard]("+ dashboardURL + ")", - }, - { - name: "Visit Uptime Kuma", - value: "[Visit]("+ kumaURL +")", - }, ], }], } @@ -158,10 +148,6 @@ class Notification { name: "Ping", value: heartbeatJSON["ping"] + "ms", }, - { - name: "Visit Uptime Kuma", - value: "[Visit]("+ kumaURL +")", - }, ], }], } From 91fce75a9354038c8cc60e1f18c818df89619c7b Mon Sep 17 00:00:00 2001 From: Niyas Date: Fri, 6 Aug 2021 17:38:16 +0530 Subject: [PATCH 04/10] Removed UptimeKuma url field --- src/components/NotificationDialog.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 3a80a929..4eea85d6 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -143,8 +143,6 @@
- -
You can get this by going to Server Settings -> Integrations -> Create Webhook
From ebf207c2f513d7d12872efdb9994a5bb333b7f2c Mon Sep 17 00:00:00 2001 From: Niyas Date: Sat, 7 Aug 2021 11:12:36 +0530 Subject: [PATCH 05/10] Custom embed username --- server/notification.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/notification.js b/server/notification.js index bf4bac54..65cccfbf 100644 --- a/server/notification.js +++ b/server/notification.js @@ -87,7 +87,7 @@ class Notification { // If heartbeatJSON is null, assume we're testing. if (heartbeatJSON == null) { let discordtestdata = { - username: "Uptime Kuma", + username: notification.discordUsername || "Uptime Kuma", content: msg, } await axios.post(notification.discordWebhookUrl, discordtestdata) @@ -96,7 +96,7 @@ class Notification { // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] == 0) { let discorddowndata = { - username: "Uptime Kuma", + username: notification.discordUsername || "Uptime Kuma", embeds: [{ title: "❌ One of your services went down. ❌", color: 16711680, @@ -126,7 +126,7 @@ class Notification { } else if (heartbeatJSON["status"] == 1) { let discordupdata = { - username: "Uptime Kuma", + username: notification.discordUsername || "Uptime Kuma", embeds: [{ title: "✅ Your service " + monitorJSON["name"] + " is up! ✅", color: 65280, From 4469b3a19b90e0d12b452363b1819a3fb0c65346 Mon Sep 17 00:00:00 2001 From: Niyas Date: Sat, 7 Aug 2021 11:13:25 +0530 Subject: [PATCH 06/10] Added discord username field --- src/components/NotificationDialog.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 4eea85d6..1260e024 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -143,6 +143,8 @@
+ +
You can get this by going to Server Settings -> Integrations -> Create Webhook
From 2677f5dd876f67a378137c6b7dad6afd4c3ee807 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sun, 8 Aug 2021 02:18:33 +0800 Subject: [PATCH 07/10] run eslint for discord enhancement --- server/notification.js | 112 ++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/server/notification.js b/server/notification.js index 65cccfbf..c43983d7 100644 --- a/server/notification.js +++ b/server/notification.js @@ -96,63 +96,63 @@ class Notification { // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] == 0) { let discorddowndata = { - username: notification.discordUsername || "Uptime Kuma", - embeds: [{ - title: "❌ One of your services went down. ❌", - color: 16711680, - timestamp: heartbeatJSON["time"], - fields: [ - { - name: "Service Name", - value: monitorJSON["name"], - }, - { - name: "Service URL", - value: monitorJSON["url"], - }, - { - name: "Time (UTC)", - value: heartbeatJSON["time"], - }, - { - name: "Error", - value: heartbeatJSON["msg"], - }, - ], - }], - } - await axios.post(notification.discordWebhookUrl, discorddowndata) - return okMsg; - - } else if (heartbeatJSON["status"] == 1) { + username: notification.discordUsername || "Uptime Kuma", + embeds: [{ + title: "❌ One of your services went down. ❌", + color: 16711680, + timestamp: heartbeatJSON["time"], + fields: [ + { + name: "Service Name", + value: monitorJSON["name"], + }, + { + name: "Service URL", + value: monitorJSON["url"], + }, + { + name: "Time (UTC)", + value: heartbeatJSON["time"], + }, + { + name: "Error", + value: heartbeatJSON["msg"], + }, + ], + }], + } + await axios.post(notification.discordWebhookUrl, discorddowndata) + return okMsg; + + } if (heartbeatJSON["status"] == 1) { let discordupdata = { - username: notification.discordUsername || "Uptime Kuma", - embeds: [{ - title: "✅ Your service " + monitorJSON["name"] + " is up! ✅", - color: 65280, - timestamp: heartbeatJSON["time"], - fields: [ - { - name: "Service Name", - value: monitorJSON["name"], - }, - { - name: "Service URL", - value: "[Visit Service]("+ monitorJSON["url"] +")", - }, - { - name: "Time (UTC)", - value: heartbeatJSON["time"], - }, - { - name: "Ping", - value: heartbeatJSON["ping"] + "ms", - }, - ], - }], - } - await axios.post(notification.discordWebhookUrl, discordupdata) - return okMsg; + username: notification.discordUsername || "Uptime Kuma", + embeds: [{ + title: "✅ Your service " + monitorJSON["name"] + " is up! ✅", + color: 65280, + timestamp: heartbeatJSON["time"], + fields: [ + { + name: "Service Name", + value: monitorJSON["name"], + }, + { + name: "Service URL", + value: "[Visit Service](" + monitorJSON["url"] + ")", + }, + { + name: "Time (UTC)", + value: heartbeatJSON["time"], + }, + { + name: "Ping", + value: heartbeatJSON["ping"] + "ms", + }, + ], + }], + } + await axios.post(notification.discordWebhookUrl, discordupdata) + return okMsg; } } catch (error) { throwGeneralAxiosError(error) From c990edc87ddd2060383442fa02ebae8e05e05fda Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sun, 8 Aug 2021 02:34:51 +0800 Subject: [PATCH 08/10] allowElseIf for else return, since its auto fix removes "else" but without newline --- .eslintrc.js | 3 --- server/notification.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 41ad54b8..dcd4215c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -62,9 +62,6 @@ module.exports = { exceptAfterSingleLine: true, }], "no-unneeded-ternary": "error", - "no-else-return": ["error", { - "allowElseIf": false, - }], "array-bracket-newline": ["error", "consistent"], "eol-last": ["error", "always"], //'prefer-template': 'error', diff --git a/server/notification.js b/server/notification.js index c43983d7..38cb80d9 100644 --- a/server/notification.js +++ b/server/notification.js @@ -124,7 +124,7 @@ class Notification { await axios.post(notification.discordWebhookUrl, discorddowndata) return okMsg; - } if (heartbeatJSON["status"] == 1) { + } else if (heartbeatJSON["status"] == 1) { let discordupdata = { username: notification.discordUsername || "Uptime Kuma", embeds: [{ From d5b40dfebf9ed4427e480478344e35ee60b293b3 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sun, 8 Aug 2021 11:03:22 +0800 Subject: [PATCH 09/10] better code reuse and "Username" to "Bot Display Name" --- server/notification.js | 8 +++++--- src/components/NotificationDialog.vue | 14 ++++++++------ src/main.js | 6 ++++++ src/util.js | 3 ++- src/util.ts | 1 + 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/server/notification.js b/server/notification.js index 38cb80d9..05dae8ad 100644 --- a/server/notification.js +++ b/server/notification.js @@ -84,10 +84,12 @@ class Notification { } else if (notification.type === "discord") { try { + const discordDisplayName = notification.discordUsername || "Uptime Kuma"; + // If heartbeatJSON is null, assume we're testing. if (heartbeatJSON == null) { let discordtestdata = { - username: notification.discordUsername || "Uptime Kuma", + username: discordDisplayName, content: msg, } await axios.post(notification.discordWebhookUrl, discordtestdata) @@ -96,7 +98,7 @@ class Notification { // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] == 0) { let discorddowndata = { - username: notification.discordUsername || "Uptime Kuma", + username: discordDisplayName, embeds: [{ title: "❌ One of your services went down. ❌", color: 16711680, @@ -126,7 +128,7 @@ class Notification { } else if (heartbeatJSON["status"] == 1) { let discordupdata = { - username: notification.discordUsername || "Uptime Kuma", + username: discordDisplayName, embeds: [{ title: "✅ Your service " + monitorJSON["name"] + " is up! ✅", color: 65280, diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 1260e024..e4adb528 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -143,8 +143,11 @@
- - +
+ +
+ +
You can get this by going to Server Settings -> Integrations -> Create Webhook
@@ -235,17 +238,17 @@ @@ -336,7 +339,6 @@
-
@@ -512,3 +512,13 @@ export default { }, } + + diff --git a/src/layouts/Layout.vue b/src/layouts/Layout.vue index 4405ebb7..9607483e 100644 --- a/src/layouts/Layout.vue +++ b/src/layouts/Layout.vue @@ -1,76 +1,78 @@ - diff --git a/src/main.js b/src/main.js index 5b9ab944..6ef72034 100644 --- a/src/main.js +++ b/src/main.js @@ -9,6 +9,7 @@ import { FontAwesomeIcon } from "./icon.js"; import EmptyLayout from "./layouts/EmptyLayout.vue"; import Layout from "./layouts/Layout.vue"; import socket from "./mixins/socket"; +import theme from "./mixins/theme"; import Dashboard from "./pages/Dashboard.vue"; import DashboardHome from "./pages/DashboardHome.vue"; import Details from "./pages/Details.vue"; @@ -77,6 +78,7 @@ const router = createRouter({ const app = createApp({ mixins: [ socket, + theme ], data() { return { diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 59abd27c..46449ade 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -29,7 +29,7 @@ export default { notificationList: [], windowWidth: window.innerWidth, showListMobile: false, - connectionErrorMsg: "Cannot connect to the socket server. Reconnecting..." + connectionErrorMsg: "Cannot connect to the socket server. Reconnecting...", } }, diff --git a/src/mixins/theme.js b/src/mixins/theme.js new file mode 100644 index 00000000..673a8caa --- /dev/null +++ b/src/mixins/theme.js @@ -0,0 +1,39 @@ +export default { + + data() { + return { + system: (window.matchMedia("(prefers-color-scheme: dark)")) ? "dark" : "light", + userTheme: localStorage.theme, + }; + }, + + mounted() { + // Default Light + if (! this.userTheme) { + this.userTheme = "light"; + } + + document.body.classList.add(this.theme); + }, + + computed: { + theme() { + if (this.userTheme === "auto") { + return this.system; + } + return this.userTheme; + } + }, + + watch: { + userTheme(to, from) { + localStorage.theme = to; + }, + + theme(to, from) { + document.body.classList.remove(from); + document.body.classList.add(this.theme); + } + } +} + diff --git a/src/pages/Dashboard.vue b/src/pages/Dashboard.vue index 60b7ca46..bbb60a26 100644 --- a/src/pages/Dashboard.vue +++ b/src/pages/Dashboard.vue @@ -89,7 +89,7 @@ export default { } - diff --git a/src/pages/DashboardHome.vue b/src/pages/DashboardHome.vue index 1fd4f602..969652f3 100644 --- a/src/pages/DashboardHome.vue +++ b/src/pages/DashboardHome.vue @@ -169,7 +169,7 @@ export default { } - diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 5eaab88b..72f2d6a0 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -20,6 +20,19 @@
+
+
+ + + + + + + + +
+
+
-
+

Notifications

@@ -201,8 +214,17 @@ export default { } - diff --git a/src/util.js b/src/util.js index 8e80cb61..44630993 100644 --- a/src/util.js +++ b/src/util.js @@ -29,7 +29,7 @@ function ucfirst(str) { exports.ucfirst = ucfirst; function debug(msg) { if (process.env.NODE_ENV === "development") { - console.log(msg); + console.debug(msg); } } exports.debug = debug; diff --git a/src/util.ts b/src/util.ts index 4d532320..1ed6d4c6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -39,6 +39,6 @@ export function ucfirst(str) { export function debug(msg) { if (process.env.NODE_ENV === "development") { - console.log(msg) + console.debug(msg); } }