From 49f0b9b50ca24c9b16e79d0a71f59a72aa511394 Mon Sep 17 00:00:00 2001 From: lyc8503 <36782264+lyc8503@users.noreply.github.com> Date: Sun, 12 Feb 2023 18:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=90=86=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E6=B5=8B=E9=80=9F=E6=97=B6=E7=9A=84=20UI=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=20(#741)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: lyc8503 --- src/components/proxies/ProxyLatency.tsx | 4 +-- src/store/proxies.tsx | 43 +++++++++---------------- src/store/types.ts | 2 +- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/components/proxies/ProxyLatency.tsx b/src/components/proxies/ProxyLatency.tsx index 29036d5..a617a62 100644 --- a/src/components/proxies/ProxyLatency.tsx +++ b/src/components/proxies/ProxyLatency.tsx @@ -3,14 +3,14 @@ import * as React from 'react'; import s0 from './ProxyLatency.module.scss'; type ProxyLatencyProps = { - number?: number; + number?: any; color: string; }; export function ProxyLatency({ number, color }: ProxyLatencyProps) { return ( - {typeof number === 'number' && number !== 0 ? number + ' ms' : ' '} + {typeof number === 'number' ? (number !== 0 ? number + ' ms' : ' ') : number} ); } diff --git a/src/store/proxies.tsx b/src/store/proxies.tsx index 5f4c0aa..e7b4f61 100644 --- a/src/store/proxies.tsx +++ b/src/store/proxies.tsx @@ -270,12 +270,13 @@ function requestDelayForProxyOnce(apiConfig: ClashAPIConfig, name: string) { return async (dispatch: DispatchFn, getState: GetStateFn) => { const latencyTestUrl = getLatencyTestUrl(getState()); const res = await proxiesAPI.requestDelayForProxy(apiConfig, name, latencyTestUrl); - let error = ''; + if (res.ok === false) { - error = res.statusText; + var delay: any = res.statusText; + } else { + var { delay } = await res.json(); } - const { delay } = await res.json(); - const delayNext = { ...getDelay(getState()), [name]: { error, number: delay } }; + const delayNext = { ...getDelay(getState()), [name]: { number: delay } }; dispatch('requestDelayForProxyOnce', (s) => { s.proxies.delay = delayNext; @@ -291,33 +292,19 @@ export function requestDelayForProxy(apiConfig: ClashAPIConfig, name: string) { export function requestDelayForProxies(apiConfig: ClashAPIConfig, names: string[]) { return async (dispatch: DispatchFn, getState: GetStateFn) => { - const proxies = getProxies(getState()); - const latencyTestUrl = getLatencyTestUrl(getState()); - const proxyDedupMap = new Map(); - const providerDedupMap = new Map(); + let delayClear = getDelay(getState()) - const works = names.map((name) => { - const p = proxies[name]; - if (!p.__provider) { - if (proxyDedupMap.get(name)) { - return undefined; - } else { - proxyDedupMap.set(name, true); - return proxiesAPI.requestDelayForProxy(apiConfig, name, latencyTestUrl); - } - } else if (p.__provider) { - // this one is from a proxy provider - if (providerDedupMap.get(p.__provider)) { - return undefined; - } else { - providerDedupMap.set(p.__provider, true); - return healthcheckProviderByNameInternal(apiConfig, p.__provider); - } - } else { - return undefined; - } + for (var name of names) { + delayClear[name] = { number: "- ms" } + } + + dispatch('clearDelayBeforeTest', (s) => { + s.proxies.delay = delayClear; }); + + const works = names.map((name) => requestDelayForProxy(apiConfig, name)(dispatch)) + await Promise.all(works); await dispatch(fetchProxies(apiConfig)); }; diff --git a/src/store/types.ts b/src/store/types.ts index b0b457e..70b97db 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -41,7 +41,7 @@ export type ProxyItem = { }; export type ProxyDelayItem = { - number?: number; + number?: any; }; export type ProxiesMapping = Record;