mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-15 15:32:21 +08:00
fix: provider proxy delay check (#7456)
* refactor(proxy): support delay testing for provider-based proxies * style: remove debug console logs * docs: update changelog * feat(services): merge provider nodes into records in calcuProxies --------- Co-authored-by: Tunglies <tunglies.dev@outlook.com>
This commit is contained in:
@@ -217,11 +217,14 @@ export async function calcuProxies(): Promise<{
|
||||
all: global?.all?.map((item) => generateItem(item)) || [],
|
||||
}
|
||||
|
||||
// 原本的 records 拥有所有节点信息,新版本内核需要将 provider 的节点信息合并到 records 中, 同时兼容旧版本数据
|
||||
const records = { ...proxyRecord, ...providerMap }
|
||||
|
||||
return {
|
||||
global: _global as IProxyGroupItem,
|
||||
direct: direct as IProxyItem,
|
||||
groups,
|
||||
records: proxyRecord as Record<string, IProxyItem>,
|
||||
records: records as Record<string, IProxyItem>,
|
||||
proxies: (proxies as IProxyItem[]) ?? [],
|
||||
}
|
||||
}
|
||||
@@ -505,7 +508,7 @@ export async function saveWebdavConfig(
|
||||
|
||||
export async function listWebDavBackup() {
|
||||
const list: IWebDavFile[] = await invoke<IWebDavFile[]>('list_webdav_backup')
|
||||
list.map((item) => {
|
||||
list.forEach((item) => {
|
||||
item.filename = item.href.split('/').pop() as string
|
||||
})
|
||||
return list
|
||||
|
||||
+30
-9
@@ -1,4 +1,8 @@
|
||||
import { delayProxyByName, ProxyDelay } from 'tauri-plugin-mihomo-api'
|
||||
import {
|
||||
delayProxyByName,
|
||||
healthcheckNodeInProvider,
|
||||
type ProxyDelay,
|
||||
} from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import { debugLog } from '@/utils/debug'
|
||||
|
||||
@@ -198,10 +202,23 @@ class DelayManager {
|
||||
return -1
|
||||
}
|
||||
|
||||
// 统一延迟测试检测
|
||||
async unifiedDelayCheck(
|
||||
name: string,
|
||||
url: string,
|
||||
timeout: number,
|
||||
providerName?: string,
|
||||
) {
|
||||
if (providerName)
|
||||
return healthcheckNodeInProvider(providerName, name, url, timeout)
|
||||
return delayProxyByName(name, url, timeout)
|
||||
}
|
||||
|
||||
async checkDelay(
|
||||
name: string,
|
||||
group: string,
|
||||
timeout: number,
|
||||
providerName?: string,
|
||||
): Promise<DelayUpdate> {
|
||||
debugLog(
|
||||
`[DelayManager] 开始测试延迟,代理: ${name}, 组: ${group}, 超时: ${timeout}ms`,
|
||||
@@ -223,7 +240,7 @@ class DelayManager {
|
||||
|
||||
// 使用Promise.race来实现超时控制
|
||||
const result = await Promise.race([
|
||||
delayProxyByName(name, url, timeout),
|
||||
this.unifiedDelayCheck(name, url, timeout, providerName),
|
||||
timeoutPromise,
|
||||
])
|
||||
|
||||
@@ -250,25 +267,29 @@ class DelayManager {
|
||||
}
|
||||
|
||||
async checkListDelay(
|
||||
nameList: string[],
|
||||
proxies: IProxyItem[],
|
||||
group: string,
|
||||
timeout: number,
|
||||
concurrency = 36,
|
||||
) {
|
||||
debugLog(
|
||||
`[DelayManager] 批量测试延迟开始,组: ${group}, 数量: ${nameList.length}, 并发数: ${concurrency}`,
|
||||
`[DelayManager] 批量测试延迟开始,组: ${group}, 数量: ${proxies.length}, 并发数: ${concurrency}`,
|
||||
)
|
||||
const names = nameList.filter(Boolean)
|
||||
const names = proxies.map((p) => p.name)
|
||||
// 设置正在延迟测试中
|
||||
names.forEach((name) => this.setDelay(name, group, -2))
|
||||
names.forEach((name) => {
|
||||
this.setDelay(name, group, -2)
|
||||
})
|
||||
|
||||
let index = 0
|
||||
const startTime = Date.now()
|
||||
const listener = this.groupListenerMap.get(group)
|
||||
|
||||
const help = async (): Promise<void> => {
|
||||
const currName = names[index++]
|
||||
if (!currName) return
|
||||
const currProxy = proxies[index++]
|
||||
if (!currProxy) return
|
||||
const currName = currProxy.name
|
||||
const currProviderName = currProxy.provider
|
||||
|
||||
try {
|
||||
// 确保API调用前状态为测试中
|
||||
@@ -282,7 +303,7 @@ class DelayManager {
|
||||
)
|
||||
}
|
||||
|
||||
await this.checkDelay(currName, group, timeout)
|
||||
await this.checkDelay(currName, group, timeout, currProviderName)
|
||||
if (listener) {
|
||||
this.queueGroupNotification(group)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user