From 7a3285adaf29ecce08805079e370e62d55179f47 Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 15 Aug 2022 20:14:33 +0800 Subject: [PATCH] fix: web ui port value error --- src/components/setting/mods/web-ui-viewer.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/setting/mods/web-ui-viewer.tsx b/src/components/setting/mods/web-ui-viewer.tsx index 68b47a7..18b0bf3 100644 --- a/src/components/setting/mods/web-ui-viewer.tsx +++ b/src/components/setting/mods/web-ui-viewer.tsx @@ -76,8 +76,17 @@ const WebUIViewer = ({ handler, onError }: Props) => { if (url.includes("%port") || url.includes("%secret")) { if (!clashInfo) throw new Error("failed to get clash info"); + if (!clashInfo.server?.includes(":")) { + throw new Error( + `failed to parse server with status ${clashInfo.status}` + ); + } - url = url.replaceAll("%port", clashInfo.port || "9090"); + const port = clashInfo.server + .slice(clashInfo.server.indexOf(":") + 1) + .trim(); + + url = url.replaceAll("%port", port || "9090"); url = url.replaceAll("%secret", clashInfo.secret || ""); }