diff --git a/package.json b/package.json index 89267c15..accdc06d 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@types/json-schema": "^7.0.15", "ahooks": "^3.7.11", "axios": "^1.6.8", + "axios-tauri-api-adapter": "^0.2.1", "dayjs": "1.11.5", "i18next": "^23.11.3", "lodash-es": "^4.17.21", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c812713..345484f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,6 +49,9 @@ importers: axios: specifier: ^1.6.8 version: 1.6.8 + axios-tauri-api-adapter: + specifier: ^0.2.1 + version: 0.2.1 dayjs: specifier: 1.11.5 version: 1.11.5 @@ -1599,6 +1602,13 @@ packages: integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==, } + axios-tauri-api-adapter@0.2.1: + resolution: + { + integrity: sha512-XuC6rDl8yOUrctN1nUe5fngPhmq+zhkUvKZVRCUOrlSn5UdLYH0OjrLJl7h8DQdxcAzZw0Oiw+PQFNOBuL42hg==, + } + engines: { node: ">=16", pnpm: ">=7" } + axios@1.6.8: resolution: { @@ -1646,6 +1656,12 @@ packages: engines: { node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7 } hasBin: true + build-url-ts@6.1.7: + resolution: + { + integrity: sha512-KU8hfHxEpBTvoJA4XLiL88JiJN6U0SIVtnXKMSKgxf2T+bP3tDlzd/WIl/dthi+01YXeS49yUxkL3JXyqPdIAw==, + } + callsites@3.1.0: resolution: { @@ -2114,6 +2130,12 @@ packages: integrity: sha512-/sXbVCWayk6GDVg3ctOX6nxaVj7So40FcFAnWlWGNAB1LpYKcV5Cd10APjPjW80O7zYW2MsjBV4zZ7IZO5fVow==, } + http-status-codes@2.3.0: + resolution: + { + integrity: sha512-RJ8XvFvpPM/Dmc5SV+dC4y5PCeOhT3x1Hq0NU3rjGeg5a/CqlhZ7uudknPwZFz4aeAXDcbAyaeP7GAo9lvngtA==, + } + https-proxy-agent@5.0.1: resolution: { @@ -2888,6 +2910,12 @@ packages: integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==, } + querystringify@2.2.0: + resolution: + { + integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==, + } + react-dom@18.3.1: resolution: { @@ -3049,6 +3077,12 @@ packages: integrity: sha512-z3tJrAs2kIs1AqIIy6pzHmAHlF1hWQ+OdY4/hv+Wxe35EhyLKcajL33iUEn3ScxtFox9nUvRufR/Zre8Q08H/g==, } + requires-port@1.0.0: + resolution: + { + integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==, + } + reselect@4.1.8: resolution: { @@ -3347,6 +3381,12 @@ packages: peerDependencies: browserslist: ">= 4.21.0" + url-parse@1.5.10: + resolution: + { + integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==, + } + vfile-message@4.0.2: resolution: { @@ -4406,6 +4446,16 @@ snapshots: asynckit@0.4.0: {} + axios-tauri-api-adapter@0.2.1: + dependencies: + "@tauri-apps/api": 1.5.4 + axios: 1.6.8 + build-url-ts: 6.1.7 + http-status-codes: 2.3.0 + url-parse: 1.5.10 + transitivePeerDependencies: + - debug + axios@1.6.8: dependencies: follow-redirects: 1.15.6 @@ -4437,6 +4487,8 @@ snapshots: node-releases: 2.0.14 update-browserslist-db: 1.0.15(browserslist@4.23.0) + build-url-ts@6.1.7: {} + callsites@3.1.0: {} camelcase@6.3.0: {} @@ -4713,6 +4765,8 @@ snapshots: html-url-attributes@3.0.0: {} + http-status-codes@2.3.0: {} + https-proxy-agent@5.0.1: dependencies: agent-base: 6.0.2 @@ -5230,6 +5284,8 @@ snapshots: end-of-stream: 1.4.4 once: 1.4.0 + querystringify@2.2.0: {} + react-dom@18.3.1(react@18.3.1): dependencies: loose-envify: 1.4.0 @@ -5339,6 +5395,8 @@ snapshots: unified: 11.0.4 vfile: 6.0.1 + requires-port@1.0.0: {} + reselect@4.1.8: {} resize-observer-polyfill@1.5.1: {} @@ -5512,6 +5570,11 @@ snapshots: escalade: 3.1.2 picocolors: 1.0.0 + url-parse@1.5.10: + dependencies: + querystringify: 2.2.0 + requires-port: 1.0.0 + vfile-message@4.0.2: dependencies: "@types/unist": 3.0.2 diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 0f6c98ad..f4cb4516 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -38,6 +38,10 @@ "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEQyOEMyRjBCQkVGOUJEREYKUldUZnZmbStDeStNMHU5Mmo1N24xQXZwSVRYbXA2NUpzZE5oVzlqeS9Bc0t6RVV4MmtwVjBZaHgK" }, "allowlist": { + "http": { + "all": true, + "scope": ["http://**", "http://**"] + }, "shell": { "all": true }, diff --git a/src/services/api.ts b/src/services/api.ts index bded6e32..42e6bcd8 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -1,3 +1,4 @@ +import axiosTauriApiAdapter from "axios-tauri-api-adapter"; import axios, { AxiosInstance } from "axios"; import { getClashInfo } from "./cmds"; @@ -25,6 +26,7 @@ export const getAxios = async (force: boolean = false) => { } catch {} axiosIns = axios.create({ + adapter: axiosTauriApiAdapter, baseURL: `http://${server}`, headers: secret ? { Authorization: `Bearer ${secret}` } : {}, timeout: 15000,