summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorMatain <[email protected]>2022-06-12 23:57:53 +0800
committerMatain <[email protected]>2022-06-12 23:57:53 +0800
commita0fedebe3e03bda70b59881b0c49b87af6771a33 (patch)
tree4d7d087aa46a2b1cf39717e14ed4f805300897c2 /src/api
parent065069e5528f01c87e22b613913fb8e0df3b8d4a (diff)
Revert "Merge branch 'haishanh-master'"
This reverts commit e4e921e0b93f74bf126ca80cbb83f5e912f73a88, reversing changes made to a825925cc97d95762634d234ef06be1627a21fb1.
Diffstat (limited to 'src/api')
-rw-r--r--src/api/configs.ts5
-rw-r--r--src/api/connections.ts5
-rw-r--r--src/api/proxies.ts30
-rw-r--r--src/api/rule-provider.ts5
-rw-r--r--src/api/rules.ts4
-rw-r--r--src/api/traffic.ts2
6 files changed, 29 insertions, 22 deletions
diff --git a/src/api/configs.ts b/src/api/configs.ts
index 8a9b339..3734958 100644
--- a/src/api/configs.ts
+++ b/src/api/configs.ts
@@ -24,7 +24,10 @@ function configsPatchWorkaround(o: ClashConfigPartial) {
return o;
}
-export async function updateConfigs(apiConfig: ClashAPIConfig, o: ClashConfigPartial) {
+export async function updateConfigs(
+ apiConfig: ClashAPIConfig,
+ o: ClashConfigPartial
+) {
const { url, init } = getURLAndInit(apiConfig);
const body = JSON.stringify(configsPatchWorkaround(o));
return await fetch(url + endpoint, { ...init, body, method: 'PATCH' });
diff --git a/src/api/connections.ts b/src/api/connections.ts
index 6690f30..cedb227 100644
--- a/src/api/connections.ts
+++ b/src/api/connections.ts
@@ -53,7 +53,10 @@ function appendData(s: string) {
type UnsubscribeFn = () => void;
let wsState: number;
-export function fetchData(apiConfig: ClashAPIConfig, listener: unknown): UnsubscribeFn | void {
+export function fetchData(
+ apiConfig: ClashAPIConfig,
+ listener: unknown
+): UnsubscribeFn | void {
if (fetched || wsState === 1) {
if (listener) return subscribe(listener);
}
diff --git a/src/api/proxies.ts b/src/api/proxies.ts
index be09d7c..079106b 100644
--- a/src/api/proxies.ts
+++ b/src/api/proxies.ts
@@ -1,5 +1,3 @@
-import { ClashAPIConfig } from '$src/types';
-
import { getURLAndInit } from '../misc/request-helper';
const endpoint = '/proxies';
@@ -16,21 +14,16 @@ $ 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: ClashAPIConfig) {
+export async function fetchProxies(config) {
const { url, init } = getURLAndInit(config);
const res = await fetch(url + endpoint, init);
return await res.json();
}
-export async function requestToSwitchProxy(
- apiConfig: ClashAPIConfig,
- groupName: string,
- name: string
-) {
- const body = { name };
+export async function requestToSwitchProxy(apiConfig, name1, name2) {
+ const body = { name: name2 };
const { url, init } = getURLAndInit(apiConfig);
- const group = encodeURIComponent(groupName);
- const fullURL = `${url}${endpoint}/${group}`;
+ const fullURL = `${url}${endpoint}/${name1}`;
return await fetch(fullURL, {
...init,
method: 'PUT',
@@ -39,12 +32,12 @@ export async function requestToSwitchProxy(
}
export async function requestDelayForProxy(
- apiConfig: ClashAPIConfig,
- name: string,
+ apiConfig,
+ name,
latencyTestUrl = 'http://www.gstatic.com/generate_204'
) {
const { url, init } = getURLAndInit(apiConfig);
- const qs = `timeout=5000&url=${encodeURIComponent(latencyTestUrl)}`;
+ const qs = `timeout=5000&url=${latencyTestUrl}`;
const fullURL = `${url}${endpoint}/${encodeURIComponent(name)}/delay?${qs}`;
return await fetch(fullURL, init);
}
@@ -69,14 +62,17 @@ export async function fetchProviderProxies(config) {
return await res.json();
}
-export async function updateProviderByName(config: ClashAPIConfig, name: string) {
+export async function updateProviderByName(config, name) {
const { url, init } = getURLAndInit(config);
const options = { ...init, method: 'PUT' };
return await fetch(url + '/providers/proxies/' + name, options);
}
-export async function healthcheckProviderByName(config: ClashAPIConfig, name: string) {
+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/' + name + '/healthcheck',
+ options
+ );
}
diff --git a/src/api/rule-provider.ts b/src/api/rule-provider.ts
index 5ecd61e..ec9fa7b 100644
--- a/src/api/rule-provider.ts
+++ b/src/api/rule-provider.ts
@@ -31,7 +31,10 @@ function normalizeAPIResponse(data: RuleProviderAPIData) {
return { byName, names };
}
-export async function fetchRuleProviders(endpoint: string, apiConfig: ClashAPIConfig) {
+export async function fetchRuleProviders(
+ endpoint: string,
+ apiConfig: ClashAPIConfig
+) {
const { url, init } = getURLAndInit(apiConfig);
let data = { providers: {} };
diff --git a/src/api/rules.ts b/src/api/rules.ts
index 4d18c23..b57b0e3 100644
--- a/src/api/rules.ts
+++ b/src/api/rules.ts
@@ -12,7 +12,9 @@ type RuleAPIItem = {
proxy: string;
};
-function normalizeAPIResponse(json: { rules: Array<RuleAPIItem> }): Array<RuleItem> {
+function normalizeAPIResponse(json: {
+ rules: Array<RuleAPIItem>;
+}): Array<RuleItem> {
invariant(
json.rules && json.rules.length >= 0,
'there is no valid rules list in the rules API response'
diff --git a/src/api/traffic.ts b/src/api/traffic.ts
index aa9143c..cd18aac 100644
--- a/src/api/traffic.ts
+++ b/src/api/traffic.ts
@@ -27,7 +27,7 @@ const traffic = {
this.subscribers.forEach((f) => f(o));
},
- subscribe(listener: (x: any) => void) {
+ subscribe(listener: (x:any) => void) {
this.subscribers.push(listener);
return () => {
const idx = this.subscribers.indexOf(listener);