diff options
| author | kunish <[email protected]> | 2023-01-27 02:56:42 +0800 |
|---|---|---|
| committer | kunish <[email protected]> | 2023-01-27 15:13:28 +0800 |
| commit | 48e37a055984a3b895cecfb6a74e5654f05b818f (patch) | |
| tree | 7905e663bb4c9e00da3f9d0c5ff04c9562937267 /src/api | |
| parent | 11704b9be37c7442ae5c7585e15ed16ef27849ae (diff) | |
chore: optimize development workflow
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/configs.ts | 23 | ||||
| -rw-r--r-- | src/api/connections.ts | 7 | ||||
| -rw-r--r-- | src/api/logs.ts | 6 | ||||
| -rw-r--r-- | src/api/proxies.ts | 11 | ||||
| -rw-r--r-- | src/api/rule-provider.ts | 9 | ||||
| -rw-r--r-- | src/api/rules.ts | 9 | ||||
| -rw-r--r-- | src/api/traffic.ts | 4 | ||||
| -rw-r--r-- | src/api/version.ts | 4 |
8 files changed, 27 insertions, 46 deletions
diff --git a/src/api/configs.ts b/src/api/configs.ts index 3734958..ff62ce7 100644 --- a/src/api/configs.ts +++ b/src/api/configs.ts @@ -1,6 +1,6 @@ -import { getURLAndInit } from 'src/misc/request-helper'; -import { ClashGeneralConfig, TunPartial } from 'src/store/types'; -import { ClashAPIConfig } from 'src/types'; +import { getURLAndInit } from '~/misc/request-helper'; +import { ClashGeneralConfig, TunPartial } from '~/store/types'; +import { ClashAPIConfig } from '~/types'; const endpoint = '/configs'; const updateGeoDatabasesFileEndpoint = '/configs/geo'; @@ -24,34 +24,25 @@ 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' }); } -export async function reloadConfigFile( - apiConfig: ClashAPIConfig -) { +export async function reloadConfigFile(apiConfig: ClashAPIConfig) { const { url, init } = getURLAndInit(apiConfig); const body = '{"path": "", "payload": ""}'; return await fetch(url + endpoint + '?force=true', { ...init, body, method: 'PUT' }); } -export async function updateGeoDatabasesFile( - apiConfig: ClashAPIConfig -) { +export async function updateGeoDatabasesFile(apiConfig: ClashAPIConfig) { const { url, init } = getURLAndInit(apiConfig); const body = '{"path": "", "payload": ""}'; return await fetch(url + updateGeoDatabasesFileEndpoint, { ...init, body, method: 'POST' }); } -export async function flushFakeIPPool( - apiConfig: ClashAPIConfig -) { +export async function flushFakeIPPool(apiConfig: ClashAPIConfig) { const { url, init } = getURLAndInit(apiConfig); return await fetch(url + flushFakeIPPoolEndpoint, { ...init, method: 'POST' }); } diff --git a/src/api/connections.ts b/src/api/connections.ts index cedb227..ba0d834 100644 --- a/src/api/connections.ts +++ b/src/api/connections.ts @@ -1,4 +1,4 @@ -import { ClashAPIConfig } from 'src/types'; +import { ClashAPIConfig } from '~/types'; import { buildWebSocketURL, getURLAndInit } from '../misc/request-helper'; @@ -53,10 +53,7 @@ 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/logs.ts b/src/api/logs.ts index 044a31b..db37bcd 100644 --- a/src/api/logs.ts +++ b/src/api/logs.ts @@ -1,6 +1,6 @@ -import { pad0 } from 'src/misc/utils'; -import { Log } from 'src/store/types'; -import { LogsAPIConfig } from 'src/types'; +import { pad0 } from '~/misc/utils'; +import { Log } from '~/store/types'; +import { LogsAPIConfig } from '~/types'; import { buildLogsWebSocketURL, getURLAndInit } from '../misc/request-helper'; diff --git a/src/api/proxies.ts b/src/api/proxies.ts index 079106b..97ecd59 100644 --- a/src/api/proxies.ts +++ b/src/api/proxies.ts @@ -46,11 +46,11 @@ export async function requestDelayForProxyGroup( apiConfig, name, latencyTestUrl = 'http://www.gstatic.com/generate_202' - ) { - const {url, init } = getURLAndInit(apiConfig); +) { + const { url, init } = getURLAndInit(apiConfig); const qs = `url=${latencyTestUrl}&timeout=2000`; const fullUrl = `${url}/group/${encodeURIComponent(name)}/delay?${qs}`; - return await fetch(fullUrl,init); + return await fetch(fullUrl, init); } export async function fetchProviderProxies(config) { @@ -71,8 +71,5 @@ export async function updateProviderByName(config, name) { 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 ec9fa7b..14d9917 100644 --- a/src/api/rule-provider.ts +++ b/src/api/rule-provider.ts @@ -1,5 +1,5 @@ -import { getURLAndInit } from 'src/misc/request-helper'; -import { ClashAPIConfig } from 'src/types'; +import { getURLAndInit } from '~/misc/request-helper'; +import { ClashAPIConfig } from '~/types'; export type RuleProvider = RuleProviderAPIItem & { idx: number }; @@ -31,10 +31,7 @@ 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 b57b0e3..3edb8d4 100644 --- a/src/api/rules.ts +++ b/src/api/rules.ts @@ -1,6 +1,7 @@ import invariant from 'invariant'; -import { getURLAndInit } from 'src/misc/request-helper'; -import { ClashAPIConfig } from 'src/types'; + +import { getURLAndInit } from '~/misc/request-helper'; +import { ClashAPIConfig } from '~/types'; // const endpoint = '/rules'; @@ -12,9 +13,7 @@ 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 cd18aac..34e9c91 100644 --- a/src/api/traffic.ts +++ b/src/api/traffic.ts @@ -1,4 +1,4 @@ -import { ClashAPIConfig } from '$src/types'; +import { ClashAPIConfig } from '~/types'; import { buildWebSocketURL, getURLAndInit } from '../misc/request-helper'; @@ -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); diff --git a/src/api/version.ts b/src/api/version.ts index f3cb320..6c29125 100644 --- a/src/api/version.ts +++ b/src/api/version.ts @@ -1,5 +1,5 @@ -import { getURLAndInit } from 'src/misc/request-helper'; -import { ClashAPIConfig } from 'src/types'; +import { getURLAndInit } from '~/misc/request-helper'; +import { ClashAPIConfig } from '~/types'; type VersionData = { version?: string; |
