fix: correct proxy string label displaying on dashboard

This commit is contained in:
divocat
2025-10-07 20:34:38 +03:00
parent 72b2a34af9
commit 48c8f01d2f
7 changed files with 35 additions and 21 deletions

View File

@@ -7,3 +7,4 @@ export * from './maskIP';
export * from './getProxyUrlName';
export * from './onMount';
export * from './getClashApiUrl';
export * from './splitProxyString';

View File

@@ -0,0 +1,7 @@
export function splitProxyString(str: string) {
return str
.split('\n')
.map((line) => line.trim())
.filter((line) => !line.startsWith('//'))
.filter(Boolean);
}

View File

@@ -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<IGetDashboardSectionsRespo
(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'],
@@ -42,10 +47,7 @@ export async function getDashboardSections(): Promise<IGetDashboardSectionsRespo
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,

View File

@@ -52,12 +52,12 @@ describe('validateDomain', () => {
});
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);
});
},
);
});

View File

@@ -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,}$/;

View File

@@ -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 _(

View File

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