feat: enhance ADB path resolution and update HTTP request handling for improved flexibility

This commit is contained in:
Nixevol
2026-09-27 14:37:51 +08:00
parent 3449adb721
commit fdb1f73968
8 changed files with 373 additions and 20 deletions
+11 -4
View File
@@ -53,11 +53,11 @@ class HttpClient:
raise RuntimeError("接口没有返回数据")
return data
def request_data(self, method: str, url: str, token: str, device: DeviceProfile, body: dict | None):
def request_data(self, method: str, url: str, token: str, device: DeviceProfile, body: dict | None, query: dict | None = None):
headers = device.headers()
if token:
headers["apasstk"] = token
response = self._request(method, url, headers=headers, json=body)
response = self._request(method, url, headers, body or None, query)
payload = response.json()
if payload.get("code") != 200:
raise RuntimeError(f"{method} {url} -> {payload.get('code')} {payload.get('msg')}")
@@ -65,11 +65,18 @@ class HttpClient:
raise RuntimeError("接口没有返回数据")
return payload.get("data")
def _request(self, method: str, url: str, headers: dict, json: dict | None) -> httpx.Response:
def _request(self, method: str, url: str, headers: dict, body: dict | None, query: dict | None) -> httpx.Response:
last_error = None
options: dict = {"headers": headers}
if query:
options["params"] = query
if body:
options["json"] = body
elif method == "POST":
options["content"] = b""
for attempt in range(6):
try:
return self._client_locked().request(method, url, headers=headers, json=json)
return self._client_locked().request(method, url, **options)
except (httpx.HTTPError, TimeoutError, OSError) as exc:
last_error = exc
time.sleep(min(10, 1.5 * (attempt + 1)))