mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-12-25 19:14:12 +08:00
chores for proxy latency check (#290)
* chore: update compatibility * chore: fix proxy related type declarations * chore: update latency test timeout
This commit is contained in:
parent
ce3065e22e
commit
173e2e228b
@ -131,9 +131,11 @@ export const updateProxyProviderAPI = (providerName: string) => {
|
||||
export const proxyProviderHealthCheckAPI = (providerName: string) => {
|
||||
const request = useRequest()
|
||||
|
||||
return request.get(`providers/proxies/${providerName}/healthcheck`, {
|
||||
timeout: 20 * 1000,
|
||||
})
|
||||
return request
|
||||
.get(`providers/proxies/${providerName}/healthcheck`, {
|
||||
timeout: 5 * 1000,
|
||||
})
|
||||
.json<Record<string, number>>()
|
||||
}
|
||||
|
||||
export const selectProxyInGroupAPI = (groupName: string, proxyName: string) => {
|
||||
@ -148,11 +150,18 @@ export const selectProxyInGroupAPI = (groupName: string, proxyName: string) => {
|
||||
|
||||
export const proxyLatencyTestAPI = (
|
||||
proxyName: string,
|
||||
provider: string,
|
||||
url: string,
|
||||
timeout: number,
|
||||
) => {
|
||||
const request = useRequest()
|
||||
|
||||
if (provider !== '') {
|
||||
return proxyProviderHealthCheckAPI(provider).then((latencyMap) => ({
|
||||
delay: latencyMap[proxyName],
|
||||
}))
|
||||
}
|
||||
|
||||
return request
|
||||
.get(`proxies/${proxyName}/delay`, {
|
||||
searchParams: {
|
||||
|
@ -49,7 +49,7 @@ export const ProxyNodeCard = (props: {
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
|
||||
void proxyLatencyTest(proxyName)
|
||||
void proxyLatencyTest(proxyName, proxyNode().provider)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
@ -127,7 +127,7 @@ export const tableSizeClassName = (size: TAILWINDCSS_SIZE) => {
|
||||
}
|
||||
|
||||
export const [latencyTestTimeoutDuration, setLatencyTestTimeoutDuration] =
|
||||
makePersisted(createSignal(2000), {
|
||||
makePersisted(createSignal(5000), {
|
||||
name: 'latencyTestTimeoutDuration',
|
||||
storage: localStorage,
|
||||
})
|
||||
|
@ -26,8 +26,12 @@ type ProxyInfo = {
|
||||
now: string
|
||||
xudp: boolean
|
||||
type: string
|
||||
provider: string
|
||||
}
|
||||
|
||||
export type ProxyWithProvider = Proxy & { provider?: string }
|
||||
export type ProxyNodeWithProvider = ProxyNode & { provider?: string }
|
||||
|
||||
const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap()
|
||||
const {
|
||||
map: proxyLatencyTestingMap,
|
||||
@ -46,29 +50,29 @@ const { map: updatingMap, setWithCallback: setUpdatingMap } =
|
||||
const [isAllProviderUpdating, setIsAllProviderUpdating] = createSignal(false)
|
||||
|
||||
// these signals should be global state
|
||||
const [proxies, setProxies] = createSignal<Proxy[]>([])
|
||||
const [proxyProviders, setProxyProviders] = createSignal<ProxyProvider[]>([])
|
||||
const [proxies, setProxies] = createSignal<ProxyWithProvider[]>([])
|
||||
const [proxyProviders, setProxyProviders] = createSignal<
|
||||
(ProxyProvider & { proxies: ProxyNodeWithProvider[] })[]
|
||||
>([])
|
||||
|
||||
const [latencyMap, setLatencyMap] = createSignal<Record<string, number>>({})
|
||||
const [proxyNodeMap, setProxyNodeMap] = createSignal<Record<string, ProxyInfo>>(
|
||||
{},
|
||||
)
|
||||
|
||||
const setProxiesInfo = (proxies: (Proxy | ProxyNode)[]) => {
|
||||
const setProxiesInfo = (
|
||||
proxies: (ProxyWithProvider | ProxyNodeWithProvider)[],
|
||||
) => {
|
||||
const newProxyNodeMap = { ...proxyNodeMap() }
|
||||
const newLatencyMap = { ...latencyMap() }
|
||||
|
||||
proxies.forEach((proxy) => {
|
||||
const { udp, xudp, type, now, name, provider = '' } = proxy
|
||||
|
||||
const latency =
|
||||
proxy.history.at(-1)?.delay || latencyQualityMap().NOT_CONNECTED
|
||||
|
||||
newProxyNodeMap[proxy.name] = {
|
||||
udp: proxy.udp,
|
||||
xudp: proxy.xudp,
|
||||
type: proxy.type,
|
||||
now: proxy.now,
|
||||
name: proxy.name,
|
||||
}
|
||||
newProxyNodeMap[proxy.name] = { udp, xudp, type, now, name, provider }
|
||||
newLatencyMap[proxy.name] = latency
|
||||
})
|
||||
|
||||
@ -96,9 +100,17 @@ export const useProxies = () => {
|
||||
(provider) =>
|
||||
provider.name !== 'default' && provider.vehicleType !== 'Compatible',
|
||||
)
|
||||
const allProxies: (Proxy | ProxyNode)[] = [
|
||||
|
||||
const allProxies = [
|
||||
...Object.values(proxies),
|
||||
...sortedProviders.flatMap((provider) => provider.proxies),
|
||||
...sortedProviders.flatMap((provider) =>
|
||||
provider.proxies
|
||||
.filter((proxy) => !(proxy.name in proxies))
|
||||
.map((proxy) => ({
|
||||
...proxy,
|
||||
provider: provider.name,
|
||||
})),
|
||||
),
|
||||
]
|
||||
|
||||
batch(() => {
|
||||
@ -132,10 +144,11 @@ export const useProxies = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const proxyLatencyTest = (proxyName: string) =>
|
||||
const proxyLatencyTest = (proxyName: string, provider: string) =>
|
||||
setProxyLatencyTestingMap(proxyName, async () => {
|
||||
const { delay } = await proxyLatencyTestAPI(
|
||||
proxyName,
|
||||
provider,
|
||||
urlForLatencyTest(),
|
||||
latencyTestTimeoutDuration(),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user