diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index c4962a6a..fdb50cb7 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -13,7 +13,8 @@ export default () => { updateProxy, setProxyGroupByProxyName, delayTestByProxyGroupName, - updateProxyProviderByProviderName, + updateProviderByProviderName, + healthCheckByProviderName, } = useProxies() const [collapsedMap, setCollapsedMap] = createSignal>( @@ -33,9 +34,14 @@ export default () => { delayTestByProxyGroupName(name) } + const onHealthCheckClick = (e: MouseEvent, name: string) => { + e.stopPropagation() + healthCheckByProviderName(name) + } + const onUpdateProviderClick = (e: MouseEvent, name: string) => { e.stopPropagation() - updateProxyProviderByProviderName(name) + updateProviderByProviderName(name) } return ( @@ -112,14 +118,22 @@ export default () => { - +
+ + +
) const content = ( diff --git a/src/signals/proxies.ts b/src/signals/proxies.ts index 1be968b1..0ae5fab3 100644 --- a/src/signals/proxies.ts +++ b/src/signals/proxies.ts @@ -65,19 +65,19 @@ export function useProxies() { `group/${proxyGroupName}/delay?url=https%3A%2F%2Fwww.gstatic.com%2Fgenerate_204&timeout=2000`, ) .json() - const dMap = delayMap() - Object.entries(data).forEach(([name, time]) => { - dMap[name] = time - }) + setDelayMap({ ...delayMap(), ...data }) + } - setDelayMap({ ...dMap }) + const updateProviderByProviderName = async (proxyProviderName: string) => { + await request.put(`providers/proxies/${proxyProviderName}`) + await updateProxy() } - const updateProxyProviderByProviderName = async ( - proxyProviderName: string, - ) => { - await request.put(`/providers/proxies/${proxyProviderName}`) + const healthCheckByProviderName = async (providerName: string) => { + await request.get(`providers/proxies/${providerName}/healthcheck`, { + timeout: 30 * 1000, // thie api was a little bit slow sometimes... + }) await updateProxy() } @@ -89,6 +89,7 @@ export function useProxies() { delayMap, updateProxy, setProxyGroupByProxyName, - updateProxyProviderByProviderName, + updateProviderByProviderName, + healthCheckByProviderName, } }