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, updateProxy,
setProxyGroupByProxyName, setProxyGroupByProxyName,
delayTestByProxyGroupName, delayTestByProxyGroupName,
updateProxyProviderByProviderName, updateProviderByProviderName,
healthCheckByProviderName,
} = useProxies() } = useProxies()
const [collapsedMap, setCollapsedMap] = createSignal<Record<string, boolean>>( const [collapsedMap, setCollapsedMap] = createSignal<Record<string, boolean>>(
@ -33,9 +34,14 @@ export default () => {
delayTestByProxyGroupName(name) delayTestByProxyGroupName(name)
} }
const onHealthCheckClick = (e: MouseEvent, name: string) => {
e.stopPropagation()
healthCheckByProviderName(name)
}
const onUpdateProviderClick = (e: MouseEvent, name: string) => { const onUpdateProviderClick = (e: MouseEvent, name: string) => {
e.stopPropagation() e.stopPropagation()
updateProxyProviderByProviderName(name) updateProviderByProviderName(name)
} }
return ( return (
@ -112,14 +118,22 @@ export default () => {
</div> </div>
</div> </div>
<div>
<button <button
class="btn btn-circle btn-sm" class="btn btn-circle btn-sm mr-2"
onClick={(e) => onClick={(e) =>
onUpdateProviderClick(e, proxyProvider.name) onUpdateProviderClick(e, proxyProvider.name)
} }
> >
<IconReload /> <IconReload />
</button> </button>
<button
class="btn btn-circle btn-sm"
onClick={(e) => onHealthCheckClick(e, proxyProvider.name)}
>
<IconBrandSpeedtest />
</button>
</div>
</div> </div>
) )
const content = ( 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`, `group/${proxyGroupName}/delay?url=https%3A%2F%2Fwww.gstatic.com%2Fgenerate_204&timeout=2000`,
) )
.json() .json()
const dMap = delayMap()
Object.entries(data).forEach(([name, time]) => { setDelayMap({ ...delayMap(), ...data })
dMap[name] = time
})
setDelayMap({ ...dMap })
} }
const updateProxyProviderByProviderName = async ( const updateProviderByProviderName = async (proxyProviderName: string) => {
proxyProviderName: string, await request.put(`providers/proxies/${proxyProviderName}`)
) => { await updateProxy()
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() await updateProxy()
} }
@ -89,6 +89,7 @@ export function useProxies() {
delayMap, delayMap,
updateProxy, updateProxy,
setProxyGroupByProxyName, setProxyGroupByProxyName,
updateProxyProviderByProviderName, updateProviderByProviderName,
healthCheckByProviderName,
} }
} }