From d0c0852fbb69d1ee449e6b5abe0bc252bf7aa709 Mon Sep 17 00:00:00 2001 From: mofeng-git Date: Sun, 12 Apr 2026 09:49:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=20IPv6=20URL=20=E6=8B=BC=E6=8E=A5=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20#241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一处理 Settings 页面中的主机地址格式,避免 IPv6 场景下 RTSP 地址展示和重启后跳转 URL 因缺少方括号而失效。 Made-with: Cursor --- web/src/views/SettingsView.vue | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/web/src/views/SettingsView.vue b/web/src/views/SettingsView.vue index 80f0b038..a7746156 100644 --- a/web/src/views/SettingsView.vue +++ b/web/src/views/SettingsView.vue @@ -236,8 +236,16 @@ const rtspLocalConfig = ref({ username: '', password: '', }) + +function formatHostForUrl(hostname: string): string { + if (!hostname) return '127.0.0.1' + return hostname.includes(':') && !hostname.startsWith('[') + ? `[${hostname}]` + : hostname +} + const rtspStreamUrl = computed(() => { - const host = window.location.hostname || '127.0.0.1' + const host = formatHostForUrl(window.location.hostname || '127.0.0.1') const path = (rtspLocalConfig.value.path || 'live').trim().replace(/^\/+|\/+$/g, '') || 'live' const port = Number(rtspLocalConfig.value.port) || 8554 return `rtsp://${host}:${port}/${path}` @@ -1515,7 +1523,8 @@ async function restartServer() { const port = webServerConfig.value.https_enabled ? webServerConfig.value.https_port : webServerConfig.value.http_port - const newUrl = `${protocol}://${window.location.hostname}:${port}` + const host = formatHostForUrl(window.location.hostname || '127.0.0.1') + const newUrl = `${protocol}://${host}:${port}` window.location.href = newUrl }, 3000) } catch (e) {