From 48c8f01d2fba1e4ff7ca814bca66aeb1eeee35db Mon Sep 17 00:00:00 2001 From: divocat Date: Tue, 7 Oct 2025 20:34:38 +0300 Subject: [PATCH] fix: correct proxy string label displaying on dashboard --- fe-app-podkop/src/helpers/index.ts | 1 + fe-app-podkop/src/helpers/splitProxyString.ts | 7 +++++++ .../src/podkop/methods/getDashboardSections.ts | 12 +++++++----- .../src/validators/tests/validateDomain.test.js | 14 +++++++------- fe-app-podkop/src/validators/validateDomain.ts | 6 +++--- .../resources/view/podkop/configSection.js | 6 +----- .../luci-static/resources/view/podkop/main.js | 10 +++++++++- 7 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 fe-app-podkop/src/helpers/splitProxyString.ts diff --git a/fe-app-podkop/src/helpers/index.ts b/fe-app-podkop/src/helpers/index.ts index 242f2e7..43c8879 100644 --- a/fe-app-podkop/src/helpers/index.ts +++ b/fe-app-podkop/src/helpers/index.ts @@ -7,3 +7,4 @@ export * from './maskIP'; export * from './getProxyUrlName'; export * from './onMount'; export * from './getClashApiUrl'; +export * from './splitProxyString'; diff --git a/fe-app-podkop/src/helpers/splitProxyString.ts b/fe-app-podkop/src/helpers/splitProxyString.ts new file mode 100644 index 0000000..9426e8b --- /dev/null +++ b/fe-app-podkop/src/helpers/splitProxyString.ts @@ -0,0 +1,7 @@ +export function splitProxyString(str: string) { + return str + .split('\n') + .map((line) => line.trim()) + .filter((line) => !line.startsWith('//')) + .filter(Boolean); +} diff --git a/fe-app-podkop/src/podkop/methods/getDashboardSections.ts b/fe-app-podkop/src/podkop/methods/getDashboardSections.ts index c101926..6507775 100644 --- a/fe-app-podkop/src/podkop/methods/getDashboardSections.ts +++ b/fe-app-podkop/src/podkop/methods/getDashboardSections.ts @@ -1,7 +1,7 @@ import { Podkop } from '../types'; import { getConfigSections } from './getConfigSections'; import { getClashProxies } from '../../clash'; -import { getProxyUrlName } from '../../helpers'; +import { getProxyUrlName, splitProxyString } from '../../helpers'; interface IGetDashboardSectionsResponse { success: boolean; @@ -35,6 +35,11 @@ export async function getDashboardSections(): Promise proxy.code === `${section['.name']}-out`, ); + const activeConfigs = splitProxyString(section.proxy_string); + + const proxyDisplayName = + getProxyUrlName(activeConfigs?.[0]) || outbound?.value?.name || ''; + return { withTagSelect: false, code: outbound?.code || section['.name'], @@ -42,10 +47,7 @@ export async function getDashboardSections(): Promise { }); describe.each(dotTLDTests)( - 'Dot TLD toggle: %s', - (_desc, domain, allowDotTLD, expected) => { - it(`"${domain}" with allowDotTLD=${allowDotTLD} → valid=${expected}`, () => { - const res = validateDomain(domain, allowDotTLD); - expect(res.valid).toBe(expected); - }); - }, + 'Dot TLD toggle: %s', + (_desc, domain, allowDotTLD, expected) => { + it(`"${domain}" with allowDotTLD=${allowDotTLD} → valid=${expected}`, () => { + const res = validateDomain(domain, allowDotTLD); + expect(res.valid).toBe(expected); + }); + }, ); }); diff --git a/fe-app-podkop/src/validators/validateDomain.ts b/fe-app-podkop/src/validators/validateDomain.ts index d4ff863..14e1f24 100644 --- a/fe-app-podkop/src/validators/validateDomain.ts +++ b/fe-app-podkop/src/validators/validateDomain.ts @@ -1,11 +1,11 @@ import { ValidationResult } from './types'; export function validateDomain( - domain: string, - allowDotTLD = false + domain: string, + allowDotTLD = false, ): ValidationResult { const domainRegex = - /^(?=.{1,253}(?:\/|$))(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+(?:[a-zA-Z]{2,}|xn--[a-zA-Z0-9-]{1,59}[a-zA-Z0-9])(?:\/[^\s]*)?$/; + /^(?=.{1,253}(?:\/|$))(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+(?:[a-zA-Z]{2,}|xn--[a-zA-Z0-9-]{1,59}[a-zA-Z0-9])(?:\/[^\s]*)?$/; if (allowDotTLD) { const dotTLD = /^\.[a-zA-Z]{2,}$/; diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/configSection.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/configSection.js index bc49dc7..c44e389 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/configSection.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/configSection.js @@ -130,11 +130,7 @@ function createConfigSection(section) { } try { - const activeConfigs = value - .split('\n') - .map((line) => line.trim()) - .filter((line) => !line.startsWith('//')) - .filter(Boolean); + const activeConfigs = main.splitProxyString(value); if (!activeConfigs.length) { return _( diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js index d417fca..7d09f99 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js @@ -771,6 +771,11 @@ function getClashWsUrl() { return `ws://${hostname}:9090`; } +// src/helpers/splitProxyString.ts +function splitProxyString(str) { + return str.split("\n").map((line) => line.trim()).filter((line) => !line.startsWith("//")).filter(Boolean); +} + // src/clash/methods/createBaseApiRequest.ts async function createBaseApiRequest(fetchFn) { try { @@ -899,6 +904,8 @@ async function getDashboardSections() { const outbound = proxies.find( (proxy) => proxy.code === `${section[".name"]}-out` ); + const activeConfigs = splitProxyString(section.proxy_string); + const proxyDisplayName = getProxyUrlName(activeConfigs?.[0]) || outbound?.value?.name || ""; return { withTagSelect: false, code: outbound?.code || section[".name"], @@ -906,7 +913,7 @@ async function getDashboardSections() { outbounds: [ { code: outbound?.code || section[".name"], - displayName: getProxyUrlName(section.proxy_string) || outbound?.value?.name || "", + displayName: proxyDisplayName, latency: outbound?.value?.history?.[0]?.delay || 0, type: outbound?.value?.type || "", selected: true @@ -1897,6 +1904,7 @@ return baseclass.extend({ onMount, parseValueList, renderDashboard, + splitProxyString, triggerLatencyGroupTest, triggerLatencyProxyTest, triggerProxySelector,