feat: health check for provider

This commit is contained in:
Zephyruso 2023-08-31 12:02:23 +08:00
parent b4fc1b4c98
commit 03dda3ccad
2 changed files with 36 additions and 21 deletions

View File

@ -13,7 +13,8 @@ export default () => {
updateProxy,
setProxyGroupByProxyName,
delayTestByProxyGroupName,
updateProxyProviderByProviderName,
updateProviderByProviderName,
healthCheckByProviderName,
} = useProxies()
const [collapsedMap, setCollapsedMap] = createSignal<Record<string, boolean>>(
@ -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 () => {
</div>
</div>
<button
class="btn btn-circle btn-sm"
onClick={(e) =>
onUpdateProviderClick(e, proxyProvider.name)
}
>
<IconReload />
</button>
<div>
<button
class="btn btn-circle btn-sm mr-2"
onClick={(e) =>
onUpdateProviderClick(e, proxyProvider.name)
}
>
<IconReload />
</button>
<button
class="btn btn-circle btn-sm"
onClick={(e) => onHealthCheckClick(e, proxyProvider.name)}
>
<IconBrandSpeedtest />
</button>
</div>
</div>
)
const content = (

View File

@ -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({ ...dMap })
setDelayMap({ ...delayMap(), ...data })
}
const updateProxyProviderByProviderName = async (
proxyProviderName: string,
) => {
await request.put(`/providers/proxies/${proxyProviderName}`)
const updateProviderByProviderName = async (proxyProviderName: string) => {
await request.put(`providers/proxies/${proxyProviderName}`)
await updateProxy()
}
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,
}
}