mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 05:15:35 +08:00
feat: health check for provider
This commit is contained in:
parent
b4fc1b4c98
commit
03dda3ccad
@ -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 = (
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user