fix(config): speedtest timeout config

This commit is contained in:
Zephyruso 2023-09-06 11:17:00 +08:00
parent 6c1f49480d
commit 5f1e77320d
6 changed files with 20 additions and 15 deletions

View File

@ -66,6 +66,6 @@ export default {
lg: 'Large size', lg: 'Large size',
switchEndpoint: 'Switch Endpoint', switchEndpoint: 'Switch Endpoint',
switchLanguage: 'Switch Language', switchLanguage: 'Switch Language',
requestTimeoutDuration: 'Request Timeout Duration', speedtestTimeoutDuration: 'Speedtest Timeout Duration',
closedConnections: 'Closed Connections', closedConnections: 'Closed Connections',
} }

View File

@ -66,6 +66,6 @@ export default {
lg: '超大尺寸', lg: '超大尺寸',
switchEndpoint: '切换后端', switchEndpoint: '切换后端',
switchLanguage: '切换语言', switchLanguage: '切换语言',
requestTimeoutDuration: '请求超时时间', speedtestTimeoutDuration: '测速超时时间',
closedConnections: '已关闭连接', closedConnections: '已关闭连接',
} }

View File

@ -30,7 +30,6 @@ import {
proxiesPreviewType, proxiesPreviewType,
renderInTwoColumn, renderInTwoColumn,
renderProxiesInSamePage, renderProxiesInSamePage,
requestTimeoutDuration,
setAutoCloseConns, setAutoCloseConns,
setAutoSwitchTheme, setAutoSwitchTheme,
setFavDayTheme, setFavDayTheme,
@ -39,11 +38,12 @@ import {
setProxiesPreviewType, setProxiesPreviewType,
setRenderInTwoColumn, setRenderInTwoColumn,
setRenderProxiesInSamePage, setRenderProxiesInSamePage,
setRequestTimeoutDuration,
setSelectedEndpoint, setSelectedEndpoint,
setSpeedtestTimeoutDuration,
setTableSize, setTableSize,
setTwemoji, setTwemoji,
setUrlForLatencyTest, setUrlForLatencyTest,
speedtestTimeoutDuration,
tableSize, tableSize,
urlForLatencyTest, urlForLatencyTest,
useRequest, useRequest,
@ -234,14 +234,14 @@ const ConfigForm = () => {
<div> <div>
<ConfigTitle> <ConfigTitle>
{t('requestTimeoutDuration')} ({t('ms')}) {t('speedtestTimeoutDuration')} ({t('ms')})
</ConfigTitle> </ConfigTitle>
<input <input
type="number" type="number"
class="input input-bordered w-full max-w-md" class="input input-bordered w-full max-w-md"
value={requestTimeoutDuration()} value={speedtestTimeoutDuration()}
onChange={(e) => setRequestTimeoutDuration(Number(e.target.value))} onChange={(e) => setSpeedtestTimeoutDuration(Number(e.target.value))}
/> />
</div> </div>

View File

@ -76,9 +76,9 @@ export const tableSizeClassName = (size: TAILWINDCSS_SIZE) => {
return className return className
} }
export const [requestTimeoutDuration, setRequestTimeoutDuration] = export const [speedtestTimeoutDuration, setSpeedtestTimeoutDuration] =
makePersisted(createSignal(10000), { makePersisted(createSignal(2000), {
name: 'requestTimeoutDuration', name: 'speedtestTimeoutDuration',
storage: localStorage, storage: localStorage,
}) })

View File

@ -1,5 +1,10 @@
import { createSignal } from 'solid-js' import { createSignal } from 'solid-js'
import { autoCloseConns, urlForLatencyTest, useRequest } from '~/signals' import {
autoCloseConns,
speedtestTimeoutDuration,
urlForLatencyTest,
useRequest,
} from '~/signals'
import type { Proxy, ProxyNode, ProxyProvider } from '~/types' import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
type ProxyInfo = { type ProxyInfo = {
@ -93,7 +98,7 @@ export const useProxies = () => {
.get(`group/${proxyGroupName}/delay`, { .get(`group/${proxyGroupName}/delay`, {
searchParams: { searchParams: {
url: urlForLatencyTest(), url: urlForLatencyTest(),
timeout: 2000, timeout: speedtestTimeoutDuration(),
}, },
}) })
.json() .json()
@ -121,7 +126,9 @@ export const useProxies = () => {
} }
const healthCheckByProviderName = async (providerName: string) => { const healthCheckByProviderName = async (providerName: string) => {
await request.get(`providers/proxies/${providerName}/healthcheck`) await request.get(`providers/proxies/${providerName}/healthcheck`, {
timeout: 20 * 1000,
})
await updateProxies() await updateProxies()
} }

View File

@ -1,7 +1,6 @@
import { makePersisted } from '@solid-primitives/storage' import { makePersisted } from '@solid-primitives/storage'
import ky from 'ky' import ky from 'ky'
import { createSignal } from 'solid-js' import { createSignal } from 'solid-js'
import { requestTimeoutDuration } from '~/signals/config'
export const [selectedEndpoint, setSelectedEndpoint] = makePersisted( export const [selectedEndpoint, setSelectedEndpoint] = makePersisted(
createSignal(''), createSignal(''),
@ -27,7 +26,6 @@ export const useRequest = () => {
return ky.create({ return ky.create({
prefixUrl: e?.url, prefixUrl: e?.url,
timeout: requestTimeoutDuration(),
headers: { Authorization: e?.secret ? `Bearer ${e.secret}` : '' }, headers: { Authorization: e?.secret ? `Bearer ${e.secret}` : '' },
}) })
} }