Skip to content

Commit

Permalink
fix(config): speedtest timeout config
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso authored and Zephyruso committed Sep 6, 2023
1 parent 6c1f494 commit 5f1e773
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ export default {
lg: 'Large size',
switchEndpoint: 'Switch Endpoint',
switchLanguage: 'Switch Language',
requestTimeoutDuration: 'Request Timeout Duration',
speedtestTimeoutDuration: 'Speedtest Timeout Duration',
closedConnections: 'Closed Connections',
}
2 changes: 1 addition & 1 deletion src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ export default {
lg: '超大尺寸',
switchEndpoint: '切换后端',
switchLanguage: '切换语言',
requestTimeoutDuration: '请求超时时间',
speedtestTimeoutDuration: '测速超时时间',
closedConnections: '已关闭连接',
}
10 changes: 5 additions & 5 deletions src/pages/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
proxiesPreviewType,
renderInTwoColumn,
renderProxiesInSamePage,
requestTimeoutDuration,
setAutoCloseConns,
setAutoSwitchTheme,
setFavDayTheme,
Expand All @@ -39,11 +38,12 @@ import {
setProxiesPreviewType,
setRenderInTwoColumn,
setRenderProxiesInSamePage,
setRequestTimeoutDuration,
setSelectedEndpoint,
setSpeedtestTimeoutDuration,
setTableSize,
setTwemoji,
setUrlForLatencyTest,
speedtestTimeoutDuration,
tableSize,
urlForLatencyTest,
useRequest,
Expand Down Expand Up @@ -234,14 +234,14 @@ const ConfigForm = () => {

<div>
<ConfigTitle>
{t('requestTimeoutDuration')} ({t('ms')})
{t('speedtestTimeoutDuration')} ({t('ms')})
</ConfigTitle>

<input
type="number"
class="input input-bordered w-full max-w-md"
value={requestTimeoutDuration()}
onChange={(e) => setRequestTimeoutDuration(Number(e.target.value))}
value={speedtestTimeoutDuration()}
onChange={(e) => setSpeedtestTimeoutDuration(Number(e.target.value))}
/>
</div>

Expand Down
6 changes: 3 additions & 3 deletions src/signals/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export const tableSizeClassName = (size: TAILWINDCSS_SIZE) => {
return className
}

export const [requestTimeoutDuration, setRequestTimeoutDuration] =
makePersisted(createSignal(10000), {
name: 'requestTimeoutDuration',
export const [speedtestTimeoutDuration, setSpeedtestTimeoutDuration] =
makePersisted(createSignal(2000), {
name: 'speedtestTimeoutDuration',
storage: localStorage,
})

Expand Down
13 changes: 10 additions & 3 deletions src/signals/proxies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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'

type ProxyInfo = {
Expand Down Expand Up @@ -93,7 +98,7 @@ export const useProxies = () => {
.get(`group/${proxyGroupName}/delay`, {
searchParams: {
url: urlForLatencyTest(),
timeout: 2000,
timeout: speedtestTimeoutDuration(),
},
})
.json()
Expand Down Expand Up @@ -121,7 +126,9 @@ export const useProxies = () => {
}

const healthCheckByProviderName = async (providerName: string) => {
await request.get(`providers/proxies/${providerName}/healthcheck`)
await request.get(`providers/proxies/${providerName}/healthcheck`, {
timeout: 20 * 1000,
})
await updateProxies()
}

Expand Down
2 changes: 0 additions & 2 deletions src/signals/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { makePersisted } from '@solid-primitives/storage'
import ky from 'ky'
import { createSignal } from 'solid-js'
import { requestTimeoutDuration } from '~/signals/config'

export const [selectedEndpoint, setSelectedEndpoint] = makePersisted(
createSignal(''),
Expand All @@ -27,7 +26,6 @@ export const useRequest = () => {

return ky.create({
prefixUrl: e?.url,
timeout: requestTimeoutDuration(),
headers: { Authorization: e?.secret ? `Bearer ${e.secret}` : '' },
})
}
Expand Down

0 comments on commit 5f1e773

Please sign in to comment.