diff options
| author | Haishan <[email protected]> | 2022-06-12 00:35:19 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2022-06-12 00:35:19 +0800 |
| commit | 43e1ce6ceaea80af9ab758f34c070920458e3bcd (patch) | |
| tree | 0de46233967894a42673f39c9243e8d94d88d5da /src/api | |
| parent | 1174878e8c152f51db308646e6d7e4a7cc06e271 (diff) | |
Should encode proxy name in switch proxy API call url
ref #619
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/proxies.ts | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/api/proxies.ts b/src/api/proxies.ts index e11fd9e..69100c0 100644 --- a/src/api/proxies.ts +++ b/src/api/proxies.ts @@ -1,4 +1,7 @@ +import { ClashAPIConfig } from '$src/types'; + import { getURLAndInit } from '../misc/request-helper'; + const endpoint = '/proxies'; /* @@ -13,16 +16,21 @@ $ curl "http://127.0.0.1:8080/proxies/GLOBAL" -XPUT -d '{ "name": "Proxy" }' -i HTTP/1.1 204 No Content */ -export async function fetchProxies(config) { +export async function fetchProxies(config: ClashAPIConfig) { const { url, init } = getURLAndInit(config); const res = await fetch(url + endpoint, init); return await res.json(); } -export async function requestToSwitchProxy(apiConfig, name1, name2) { - const body = { name: name2 }; +export async function requestToSwitchProxy( + apiConfig: ClashAPIConfig, + groupName: string, + name: string +) { + const body = { name }; const { url, init } = getURLAndInit(apiConfig); - const fullURL = `${url}${endpoint}/${name1}`; + const group = encodeURIComponent(groupName); + const fullURL = `${url}${endpoint}/${group}`; return await fetch(fullURL, { ...init, method: 'PUT', @@ -31,8 +39,8 @@ export async function requestToSwitchProxy(apiConfig, name1, name2) { } export async function requestDelayForProxy( - apiConfig, - name, + apiConfig: ClashAPIConfig, + name: string, latencyTestUrl = 'http://www.gstatic.com/generate_204' ) { const { url, init } = getURLAndInit(apiConfig); @@ -41,7 +49,7 @@ export async function requestDelayForProxy( return await fetch(fullURL, init); } -export async function fetchProviderProxies(config) { +export async function fetchProviderProxies(config: ClashAPIConfig) { const { url, init } = getURLAndInit(config); const res = await fetch(url + '/providers/proxies', init); if (res.status === 404) { @@ -50,13 +58,13 @@ export async function fetchProviderProxies(config) { return await res.json(); } -export async function updateProviderByName(config, name) { +export async function updateProviderByName(config: ClashAPIConfig, name: string) { const { url, init } = getURLAndInit(config); const options = { ...init, method: 'PUT' }; return await fetch(url + '/providers/proxies/' + name, options); } -export async function healthcheckProviderByName(config, name) { +export async function healthcheckProviderByName(config: ClashAPIConfig, name: string) { const { url, init } = getURLAndInit(config); const options = { ...init, method: 'GET' }; return await fetch(url + '/providers/proxies/' + name + '/healthcheck', options); |
