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
+8 -4
View File
@@ -24,10 +24,14 @@ class Adb:
raise RuntimeError(f"找不到 adb:{explicit}")
return cls(explicit)
name = "adb.exe" if os.name == "nt" else "adb"
path = REPO_ROOT / "tools" / "platform-tools" / name
if not path.is_file():
raise RuntimeError(f"项目内没有 adb:{path}")
return cls(str(path))
candidates = [
REPO_ROOT / "tools" / "platform-tools" / name,
REPO_ROOT / "vendor" / "platform-tools" / name,
]
for path in candidates:
if path.is_file():
return cls(str(path))
raise RuntimeError(f"项目内没有 adb:{candidates[0]}")
def list_devices(self) -> list[dict]:
proc = self._run(["devices", "-l"])
+9 -5
View File
@@ -10,6 +10,7 @@ from server.services.sessions import sessions
CLASSIFY_MAX_PAGES = 50
RECOMMEND_MAX_PAGES = 80
FIXED_SECTIONS = (
{"key": "trending", "name": "Trending Now", "note": "", "loading": True},
{"key": "new_releases", "name": "New Releases", "note": "", "loading": True},
{"key": "recommend", "name": "Recommend", "note": "", "loading": True},
)
@@ -25,7 +26,7 @@ class CatalogService:
return rows
def _categories(self, token: str, device: DeviceProfile) -> list[dict]:
data = http.request_data("POST", API_BASE + "/app/open/classifyv2", token, device, {})
data = http.request_data("GET", API_BASE + "/app/open/classifyv2", token, device, None)
rows = []
if isinstance(data, list):
for item in data:
@@ -72,14 +73,15 @@ class CatalogService:
f"type-{item['id']}",
item["label"],
"/app/open/classify_video",
"POST",
lambda page, type_id=item["id"]: {"page": page, "limit": 10, "type": type_id},
"GET",
lambda page, type_id=item["id"]: {"type": type_id, "page": page},
CLASSIFY_MAX_PAGES,
"",
)
for item in categories
]
jobs.append(("new_releases", "New Releases", "/app/open/orgin", "GET", None, 1, ""))
jobs.append(("trending", "Trending Now", "/app/open/orgin?class=trending_now", "GET", None, 1, ""))
jobs.append(("new_releases", "New Releases", "/app/open/orgin?class=new_releases", "GET", None, 1, ""))
jobs.append((
"recommend",
"Recommend",
@@ -148,7 +150,9 @@ class CatalogService:
page = 1
sent = False
while page <= max_pages:
data = http.request_data(method, API_BASE + path, token, device, body(page) if body else None)
query = body(page) if body and method == "GET" else None
payload = body(page) if body and method != "GET" else None
data = http.request_data(method, API_BASE + path, token, device, payload, query)
batch = data if isinstance(data, list) else []
if not batch and isinstance(data, dict) and isinstance(data.get("list"), list):
batch = data["list"]
+2
View File
@@ -62,8 +62,10 @@ class DeviceProfile:
"x-os-version": str(self.os_version),
"x-device-physical": physical,
"x-device-model": self.model,
"Accept-Encoding": "gzip",
"accept-language": self.language,
"accept-language-custom": self.language,
"http_accept_language_custom": self.language.lower(),
"x-os-name": "Android",
"x-device-brand": self.brand,
"x-device-id": self.device_id,
+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)))