From 5b20133eb401631efc5d32957fc83fb1d096ef3b Mon Sep 17 00:00:00 2001 From: cyril59310 Date: Sun, 4 May 2025 17:42:30 +0200 Subject: [PATCH] Add disable url --- ...05-1200-add-disable-url-to-notification.js | 11 ++++++++ server/notification-providers/discord.js | 4 +-- server/server.js | 26 +++++++++++++++++++ src/components/notifications/Discord.vue | 11 ++++++++ src/lang/en.json | 4 ++- 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 db/knex_migrations/2023-10-05-1200-add-disable-url-to-notification.js diff --git a/db/knex_migrations/2023-10-05-1200-add-disable-url-to-notification.js b/db/knex_migrations/2023-10-05-1200-add-disable-url-to-notification.js new file mode 100644 index 000000000..391a614e7 --- /dev/null +++ b/db/knex_migrations/2023-10-05-1200-add-disable-url-to-notification.js @@ -0,0 +1,11 @@ +exports.up = function(knex) { + return knex.schema.alterTable("notification", function(table) { + table.boolean("disable_url").defaultTo(false).notNullable().comment("Disable URL in Discord notifications"); + }); +}; + +exports.down = function(knex) { + return knex.schema.alterTable("notification", function(table) { + table.dropColumn("disable_url"); + }); +}; diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index 6a52f8f3e..5cd419608 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -48,7 +48,7 @@ class Discord extends NotificationProvider { }, { name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL", - value: this.extractAddress(monitorJSON), + value: notification.disableUrl ? "Hidden" : this.extractAddress(monitorJSON), }, { name: `Time (${heartbeatJSON["timezone"]})`, @@ -85,7 +85,7 @@ class Discord extends NotificationProvider { }, { name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL", - value: this.extractAddress(monitorJSON), + value: notification.disableUrl ? "Hidden" : this.extractAddress(monitorJSON), }, { name: `Time (${heartbeatJSON["timezone"]})`, diff --git a/server/server.js b/server/server.js index ec5ad49f6..90918eae9 100644 --- a/server/server.js +++ b/server/server.js @@ -313,6 +313,32 @@ let needSetup = false; const statusPageRouter = require("./routers/status-page-router"); app.use(statusPageRouter); + // Update notification + app.put("/notification/:id", async (req, res) => { + try { + await R.exec("UPDATE notification SET disableUrl = ? WHERE id = ?", [ + req.body.disableUrl || false, + req.params.id, + ]); + + res.status(200).send({ message: "Notification updated successfully" }); + } catch (error) { + res.status(500).send({ error: "Failed to update notification" }); + } + }); + + // Get notification + app.get("/notification/:id", async (req, res) => { + try { + const notification = await R.findOne("notification", " id = ? ", [req.params.id]); + res.json({ + disableUrl: notification.disableUrl, + }); + } catch (error) { + res.status(500).send({ error: "Failed to retrieve notification" }); + } + }); + // Universal Route Handler, must be at the end of all express routes. app.get("*", async (_request, response) => { if (_request.originalUrl.startsWith("/upload/")) { diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 5d8334f5f..2c8e7d2e7 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -53,6 +53,14 @@ + +
+ +
+ + +
+
diff --git a/src/lang/en.json b/src/lang/en.json index 37c023ee4..08a3b1763 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1093,5 +1093,7 @@ "the smsplanet documentation": "the smsplanet documentation", "Phone numbers": "Phone numbers", "Sender name": "Sender name", - "smsplanetNeedToApproveName": "Needs to be approved in the client panel" + "smsplanetNeedToApproveName": "Needs to be approved in the client panel", + "Disable URL in Notification": "Disable URL in Notification", + "Disable URL": "Disable URL" }