diff options
| author | Hsiaoyi Hsu <[email protected]> | 2023-02-19 18:19:09 +0800 |
|---|---|---|
| committer | kunish <[email protected]> | 2023-02-19 18:39:27 +0800 |
| commit | 74cd574e731fe494758dd78d2f08db66ee6840b5 (patch) | |
| tree | be958852926cce8292baca8c01d25e7bdedbe738 /src | |
| parent | 61e5e67735f77921443f2326323226eb82e00b25 (diff) | |
fix: getLatencyTestUrl, encode healthcheckProvider name
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/proxies.ts | 11 | ||||
| -rw-r--r-- | src/components/proxies/ProxyGroup.tsx | 12 |
2 files changed, 17 insertions, 6 deletions
diff --git a/src/api/proxies.ts b/src/api/proxies.ts index 97ecd59..36aa05d 100644 --- a/src/api/proxies.ts +++ b/src/api/proxies.ts @@ -37,7 +37,7 @@ export async function requestDelayForProxy( latencyTestUrl = 'http://www.gstatic.com/generate_204' ) { const { url, init } = getURLAndInit(apiConfig); - const qs = `timeout=5000&url=${latencyTestUrl}`; + const qs = `timeout=5000&url=${encodeURIComponent(latencyTestUrl)}`; const fullURL = `${url}${endpoint}/${encodeURIComponent(name)}/delay?${qs}`; return await fetch(fullURL, init); } @@ -48,7 +48,7 @@ export async function requestDelayForProxyGroup( latencyTestUrl = 'http://www.gstatic.com/generate_202' ) { const { url, init } = getURLAndInit(apiConfig); - const qs = `url=${latencyTestUrl}&timeout=2000`; + const qs = `url=${encodeURIComponent(latencyTestUrl)}&timeout=2000`; const fullUrl = `${url}/group/${encodeURIComponent(name)}/delay?${qs}`; return await fetch(fullUrl, init); } @@ -65,11 +65,14 @@ export async function fetchProviderProxies(config) { export async function updateProviderByName(config, name) { const { url, init } = getURLAndInit(config); const options = { ...init, method: 'PUT' }; - return await fetch(url + '/providers/proxies/' + name, options); + return await fetch(url + '/providers/proxies/' + encodeURIComponent(name), options); } export async function healthcheckProviderByName(config, name) { const { url, init } = getURLAndInit(config); const options = { ...init, method: 'GET' }; - return await fetch(url + '/providers/proxies/' + name + '/healthcheck', options); + return await fetch( + url + '/providers/proxies/' + encodeURIComponent(name) + '/healthcheck', + options + ); } diff --git a/src/components/proxies/ProxyGroup.tsx b/src/components/proxies/ProxyGroup.tsx index cc290d0..fb97e28 100644 --- a/src/components/proxies/ProxyGroup.tsx +++ b/src/components/proxies/ProxyGroup.tsx @@ -4,7 +4,12 @@ import { useQuery } from 'react-query'; import * as proxiesAPI from '~/api/proxies'; import { fetchVersion } from '~/api/version'; -import { getCollapsibleIsOpen, getHideUnavailableProxies, getProxySortBy } from '~/store/app'; +import { + getCollapsibleIsOpen, + getHideUnavailableProxies, + getLatencyTestUrl, + getProxySortBy, +} from '~/store/app'; import { fetchProxies, getProxies, switchProxy } from '~/store/proxies'; import Button from '../Button'; @@ -34,6 +39,7 @@ function ProxyGroupImpl({ type, now, isOpen, + latencyTestUrl, apiConfig, dispatch, }) { @@ -69,7 +75,7 @@ function ProxyGroupImpl({ setIsTestingLatency(true); try { if (version.meta === true) { - await proxiesAPI.requestDelayForProxyGroup(apiConfig, name); + await proxiesAPI.requestDelayForProxyGroup(apiConfig, name, latencyTestUrl); await dispatch(fetchProxies(apiConfig)); } else { await requestDelayForProxies(apiConfig, all); @@ -113,6 +119,7 @@ export const ProxyGroup = connect((s, { name, delay }) => { const collapsibleIsOpen = getCollapsibleIsOpen(s); const proxySortBy = getProxySortBy(s); const hideUnavailableProxies = getHideUnavailableProxies(s); + const latencyTestUrl = getLatencyTestUrl(s); const group = proxies[name]; const { all, type, now } = group; @@ -125,5 +132,6 @@ export const ProxyGroup = connect((s, { name, delay }) => { type, now, isOpen: collapsibleIsOpen[`proxyGroup:${name}`], + latencyTestUrl, }; })(ProxyGroupImpl); |
