From 1019527d8c1623d87802249ee9147dd8ae14cd62 Mon Sep 17 00:00:00 2001 From: happy game Date: Mon, 28 Apr 2025 23:29:53 +0800 Subject: [PATCH] feat: Adjust default friendly name --- src/lang/en.json | 1 + src/pages/EditMonitor.vue | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index c32bebaae..8388f636f 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -64,6 +64,7 @@ "Expected Value": "Expected Value", "Json Query Expression": "Json Query Expression", "Friendly Name": "Friendly Name", + "defaultFriendlyName": "New Monitor", "URL": "URL", "Hostname": "Hostname", "Host URL": "Host URL", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index fe19b32a9..10d944270 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -1162,16 +1162,18 @@ export default { return this.monitor.hostname; } if (this.monitor.url) { - try { - const url = new URL(this.monitor.url); - return url.hostname; - } catch (e) { - // Handle invalid URL, maybe return a generic placeholder or empty string - return this.$t("My Monitor"); + if (this.monitor.url !== "http://" && this.monitor.url !== "https://") { + // Ensure monitor without a URL is not affected by invisible URL. + try { + const url = new URL(this.monitor.url); + return url.hostname; + } catch (e) { + return this.monitor.url.replace(/https?:\/\//, ""); + } } } // Default placeholder if neither hostname nor URL is available - return this.$t("My Monitor"); + return this.$t("defaultFriendlyName"); }, ipRegex() { @@ -1717,7 +1719,6 @@ message HealthCheckResponse { this.processing = true; - // Use defaultFriendlyName if Friendly Name is empty if (!this.monitor.name) { this.monitor.name = this.defaultFriendlyName; }