diff --git a/src/components/proxies/ProxyLatency.tsx b/src/components/proxies/ProxyLatency.tsx
index a617a62..29036d5 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?: any;
+ number?: number;
color: string;
};
export function ProxyLatency({ number, color }: ProxyLatencyProps) {
return (
- {typeof number === 'number' ? (number !== 0 ? number + ' ms' : ' ') : number}
+ {typeof number === 'number' && number !== 0 ? number + ' ms' : ' '}
);
}
diff --git a/src/store/proxies.tsx b/src/store/proxies.tsx
index e7b4f61..5f4c0aa 100644
--- a/src/store/proxies.tsx
+++ b/src/store/proxies.tsx
@@ -270,13 +270,12 @@ 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) {
- var delay: any = res.statusText;
- } else {
- var { delay } = await res.json();
+ error = res.statusText;
}
- const delayNext = { ...getDelay(getState()), [name]: { number: delay } };
+ const { delay } = await res.json();
+ const delayNext = { ...getDelay(getState()), [name]: { error, number: delay } };
dispatch('requestDelayForProxyOnce', (s) => {
s.proxies.delay = delayNext;
@@ -292,19 +291,33 @@ 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());
- let delayClear = getDelay(getState())
+ const proxyDedupMap = new Map();
+ const providerDedupMap = new Map();
- for (var name of names) {
- delayClear[name] = { number: "- ms" }
- }
-
- dispatch('clearDelayBeforeTest', (s) => {
- s.proxies.delay = delayClear;
+ 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;
+ }
});
-
- 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 70b97db..b0b457e 100644
--- a/src/store/types.ts
+++ b/src/store/types.ts
@@ -41,7 +41,7 @@ export type ProxyItem = {
};
export type ProxyDelayItem = {
- number?: any;
+ number?: number;
};
export type ProxiesMapping = Record;