feat: Adjust default friendly name

This commit is contained in:
happy game 2025-04-28 23:29:53 +08:00
parent 5a8e194b94
commit 1019527d8c
2 changed files with 10 additions and 8 deletions

View file

@ -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",

View file

@ -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;
}