mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 03:26:51 +03:00
fix: correct proxy string label displaying on dashboard
This commit is contained in:
@@ -7,3 +7,4 @@ export * from './maskIP';
|
||||
export * from './getProxyUrlName';
|
||||
export * from './onMount';
|
||||
export * from './getClashApiUrl';
|
||||
export * from './splitProxyString';
|
||||
|
||||
7
fe-app-podkop/src/helpers/splitProxyString.ts
Normal file
7
fe-app-podkop/src/helpers/splitProxyString.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function splitProxyString(str: string) {
|
||||
return str
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => !line.startsWith('//'))
|
||||
.filter(Boolean);
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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,}$/;
|
||||
|
||||
@@ -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 _(
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user