mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix mihomo api
This commit is contained in:
parent
e9df76f1e6
commit
4fa96accd6
@ -24,6 +24,7 @@
|
|||||||
"@mihomo-party/sysproxy": "^1.0.1",
|
"@mihomo-party/sysproxy": "^1.0.1",
|
||||||
"@nextui-org/react": "^2.4.6",
|
"@nextui-org/react": "^2.4.6",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
|
"dayjs": "^1.11.12",
|
||||||
"electron-updater": "^6.2.1",
|
"electron-updater": "^6.2.1",
|
||||||
"framer-motion": "^11.3.19",
|
"framer-motion": "^11.3.19",
|
||||||
"next-themes": "^0.3.0",
|
"next-themes": "^0.3.0",
|
||||||
|
|||||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@ -23,6 +23,9 @@ importers:
|
|||||||
axios:
|
axios:
|
||||||
specifier: ^1.7.2
|
specifier: ^1.7.2
|
||||||
version: 1.7.2
|
version: 1.7.2
|
||||||
|
dayjs:
|
||||||
|
specifier: ^1.11.12
|
||||||
|
version: 1.11.12
|
||||||
electron-updater:
|
electron-updater:
|
||||||
specifier: ^6.2.1
|
specifier: ^6.2.1
|
||||||
version: 6.2.1
|
version: 6.2.1
|
||||||
@ -2318,6 +2321,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-t/Ygsytq+R995EJ5PZlD4Cu56sWa8InXySaViRzw9apusqsOO2bQP+SbYzAhR0pFKoB+43lYy8rWban9JSuXnA==}
|
resolution: {integrity: sha512-t/Ygsytq+R995EJ5PZlD4Cu56sWa8InXySaViRzw9apusqsOO2bQP+SbYzAhR0pFKoB+43lYy8rWban9JSuXnA==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
|
|
||||||
|
dayjs@1.11.12:
|
||||||
|
resolution: {integrity: sha512-Rt2g+nTbLlDWZTwwrIXjy9MeiZmSDI375FvZs72ngxx8PDC6YXOeR3q5LAuPzjZQxhiWdRKac7RKV+YyQYfYIg==}
|
||||||
|
|
||||||
debug@4.3.6:
|
debug@4.3.6:
|
||||||
resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==}
|
resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==}
|
||||||
engines: {node: '>=6.0'}
|
engines: {node: '>=6.0'}
|
||||||
@ -7520,6 +7526,8 @@ snapshots:
|
|||||||
es-errors: 1.3.0
|
es-errors: 1.3.0
|
||||||
is-data-view: 1.0.1
|
is-data-view: 1.0.1
|
||||||
|
|
||||||
|
dayjs@1.11.12: {}
|
||||||
|
|
||||||
debug@4.3.6:
|
debug@4.3.6:
|
||||||
dependencies:
|
dependencies:
|
||||||
ms: 2.1.2
|
ms: 2.1.2
|
||||||
|
|||||||
@ -27,72 +27,82 @@ export const getAxios = async (force: boolean = false): Promise<AxiosInstance> =
|
|||||||
|
|
||||||
export async function mihomoVersion(): Promise<IMihomoVersion> {
|
export async function mihomoVersion(): Promise<IMihomoVersion> {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.get('/version').catch((e) => {
|
return (await instance.get('/version').catch(() => {
|
||||||
return e.response.data
|
return { version: '-' }
|
||||||
})
|
})) as IMihomoVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoConfig = async (): Promise<IMihomoConfig> => {
|
export const mihomoConfig = async (): Promise<IMihomoConfig> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.get('/configs').catch((e) => {
|
return (await instance.get('/configs').catch(() => {
|
||||||
return e.response.data
|
return {}
|
||||||
})
|
})) as IMihomoConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
export const patchMihomoConfig = async (patch: Partial<IMihomoConfig>): Promise<void> => {
|
export const patchMihomoConfig = async (patch: Partial<IMihomoConfig>): Promise<void> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.patch('/configs', patch).catch((e) => {
|
return (await instance.patch('/configs', patch).catch((e) => {
|
||||||
return e.response.data
|
return e.response.data
|
||||||
})
|
})) as Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoConnections = async (): Promise<IMihomoConnectionsInfo> => {
|
export const mihomoConnections = async (): Promise<IMihomoConnectionsInfo> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.get('/connections').catch((e) => {
|
return (await instance.get('/connections').catch(() => {
|
||||||
return e.response.data
|
return { downloadTotal: 0, uploadTotal: 0, connections: [], memory: 0 }
|
||||||
})
|
})) as IMihomoConnectionsInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoCloseConnection = async (id: string): Promise<void> => {
|
export const mihomoCloseConnection = async (id: string): Promise<void> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.delete(`/connections/${encodeURIComponent(id)}`).catch((e) => {
|
return (await instance.delete(`/connections/${encodeURIComponent(id)}`).catch((e) => {
|
||||||
return e.response.data
|
return e.response.data
|
||||||
})
|
})) as Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoCloseAllConnections = async (): Promise<void> => {
|
export const mihomoCloseAllConnections = async (): Promise<void> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.delete('/connections').catch((e) => {
|
return (await instance.delete('/connections').catch((e) => {
|
||||||
return e.response.data
|
return e.response.data
|
||||||
})
|
})) as Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoRules = async (): Promise<IMihomoRulesInfo> => {
|
export const mihomoRules = async (): Promise<IMihomoRulesInfo> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.get('/rules').catch((e) => {
|
return (await instance.get('/rules').catch(() => {
|
||||||
return e.response.data
|
return { rules: [] }
|
||||||
})
|
})) as IMihomoRulesInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoProxies = async (): Promise<IMihomoProxies> => {
|
export const mihomoProxies = async (): Promise<IMihomoProxies> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.get('/proxies').catch((e) => {
|
return (await instance.get('/proxies').catch(() => {
|
||||||
return e.response.data
|
return { proxies: {} }
|
||||||
})
|
})) as IMihomoProxies
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoChangeProxy = async (group: string, proxy: string): Promise<IMihomoProxy> => {
|
export const mihomoChangeProxy = async (group: string, proxy: string): Promise<IMihomoProxy> => {
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance.put(`/proxies/${encodeURIComponent(group)}`, { name: proxy }).catch((e) => {
|
return (await instance.put(`/proxies/${encodeURIComponent(group)}`, { name: proxy }).catch(() => {
|
||||||
return e.response.data
|
return {
|
||||||
})
|
alive: false,
|
||||||
|
extra: {},
|
||||||
|
history: [],
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
tfo: false,
|
||||||
|
type: 'Shadowsocks',
|
||||||
|
udp: false,
|
||||||
|
xudp: false
|
||||||
|
}
|
||||||
|
})) as IMihomoProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mihomoProxyDelay = async (proxy: string, url?: string): Promise<IMihomoDelay> => {
|
export const mihomoProxyDelay = async (proxy: string, url?: string): Promise<IMihomoDelay> => {
|
||||||
const appConfig = getAppConfig()
|
const appConfig = getAppConfig()
|
||||||
const { delayTestUrl, delayTestTimeout } = appConfig
|
const { delayTestUrl, delayTestTimeout } = appConfig
|
||||||
const instance = await getAxios()
|
const instance = await getAxios()
|
||||||
return instance
|
return (await instance
|
||||||
.get(`/proxies/${encodeURIComponent(proxy)}/delay`, {
|
.get(`/proxies/${encodeURIComponent(proxy)}/delay`, {
|
||||||
params: {
|
params: {
|
||||||
url: url || delayTestUrl || 'https://www.gstatic.com/generate_204',
|
url: url || delayTestUrl || 'https://www.gstatic.com/generate_204',
|
||||||
@ -101,7 +111,7 @@ export const mihomoProxyDelay = async (proxy: string, url?: string): Promise<IMi
|
|||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
return e.response.data
|
return e.response.data
|
||||||
})
|
})) as IMihomoDelay
|
||||||
}
|
}
|
||||||
|
|
||||||
export const startMihomoTraffic = (): void => {
|
export const startMihomoTraffic = (): void => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user