summaryrefslogtreecommitdiff
path: root/src/api/proxies.ts
diff options
context:
space:
mode:
authorMatain <[email protected]>2022-06-12 23:34:56 +0800
committerMatain <[email protected]>2022-06-12 23:34:56 +0800
commitea5d7cf003eeef30cb7bbe789c6ba7f314bf1ce4 (patch)
treebff1bd7b0e8e8eb753d373b57f007bbe97f96c76 /src/api/proxies.ts
parent4fd2c8f646e48dd0c07d0c2041de52e9a4f8bc82 (diff)
parent38571da24ac54137564be5e41b7a409009e2ee10 (diff)
Merge branch 'master' of https://github.com/haishanh/yacd into haishanh-master
Diffstat (limited to 'src/api/proxies.ts')
-rw-r--r--src/api/proxies.ts30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/api/proxies.ts b/src/api/proxies.ts
index 079106b..be09d7c 100644
--- a/src/api/proxies.ts
+++ b/src/api/proxies.ts
@@ -1,3 +1,5 @@
+import { ClashAPIConfig } from '$src/types';
+
import { getURLAndInit } from '../misc/request-helper';
const endpoint = '/proxies';
@@ -14,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',
@@ -32,12 +39,12 @@ 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);
- 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);
}
@@ -62,17 +69,14 @@ 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
- );
+ return await fetch(url + '/providers/proxies/' + name + '/healthcheck', options);
}