parent
313a182a46
commit
49f0b9b50c
3 changed files with 18 additions and 31 deletions
|
@ -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 (
|
||||
<span className={s0.proxyLatency} style={{ color }}>
|
||||
{typeof number === 'number' && number !== 0 ? number + ' ms' : ' '}
|
||||
{typeof number === 'number' ? (number !== 0 ? number + ' ms' : ' ') : number}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<string, boolean>();
|
||||
const providerDedupMap = new Map<string, boolean>();
|
||||
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));
|
||||
};
|
||||
|
|
|
@ -41,7 +41,7 @@ export type ProxyItem = {
|
|||
};
|
||||
|
||||
export type ProxyDelayItem = {
|
||||
number?: number;
|
||||
number?: any;
|
||||
};
|
||||
|
||||
export type ProxiesMapping = Record<string, ProxyItem>;
|
||||
|
|
Loading…
Reference in a new issue