type: 收敛测试 schemas 与协议层类型

This commit is contained in:
yml2213
2026-08-30 20:35:08 +08:00
parent 92dc461e52
commit c891ac982e
26 changed files with 1846 additions and 882 deletions
+77 -30
View File
@@ -10,9 +10,10 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
from dataclasses import dataclass, field
from datetime import datetime, timezone
from types import SimpleNamespace
from typing import Optional
from typing import Optional, cast
from core.douyu import DouyuLogin, WgapiLoginAPI
from core.douyu.login import AccountLike
from core.douyu.proxy_fetcher import ProxyFetcher
from ..models import ProxyConfig as ProxyConfigModel
@@ -118,13 +119,15 @@ def parse_account_check_lines(text: str) -> list[AccountCheckInput]:
f"或 账号|密码|邮箱|邮箱密码"
)
accounts.append(AccountCheckInput(
line=line_no,
username=parts[0],
password=parts[1],
email=parts[2],
email_password=parts[3],
))
accounts.append(
AccountCheckInput(
line=line_no,
username=parts[0],
password=parts[1],
email=parts[2],
email_password=parts[3],
)
)
return accounts
@@ -158,9 +161,15 @@ class AccountCheckRunner:
wl_platform = "xiequ"
wl_credentials = None
if self.proxy_config.whitelist_enabled:
wl_platform = getattr(self.proxy_config, "whitelist_platform", None) or "xiequ"
wl_platform = (
getattr(self.proxy_config, "whitelist_platform", None) or "xiequ"
)
wl_credentials = getattr(self.proxy_config, "whitelist_credentials", None)
if not wl_credentials and self.proxy_config.whitelist_uid and self.proxy_config.whitelist_ukey:
if (
not wl_credentials
and self.proxy_config.whitelist_uid
and self.proxy_config.whitelist_ukey
):
wl_credentials = {
"uid": self.proxy_config.whitelist_uid,
"ukey": self.proxy_config.whitelist_ukey,
@@ -209,25 +218,38 @@ class AccountCheckRunner:
def _run_one(self, index: int, account: AccountCheckInput):
if self._stop.is_set():
self._set_item(index, status="stopped", message="已停止", finished_at=_now())
self._set_item(
index, status="stopped", message="已停止", finished_at=_now()
)
return
proxy_dict, proxy_error = self._resolve_static_proxy()
if proxy_error:
self._set_item(index, status="error", message=proxy_error, finished_at=_now())
self._set_item(
index, status="error", message=proxy_error, finished_at=_now()
)
return
self._set_item(index, status="running", message="检测中", started_at=_now(), finished_at=None)
self._set_item(
index,
status="running",
message="检测中",
started_at=_now(),
finished_at=None,
)
try:
result = DouyuLogin(
SimpleNamespace(
username=account.username,
password=account.password,
email=account.email,
email_password=account.email_password,
email_imap_server="",
email_imap_port=993,
email_imap_ssl=True,
cast(
AccountLike,
SimpleNamespace(
username=account.username,
password=account.password,
email=account.email,
email_password=account.email_password,
email_imap_server="",
email_imap_port=993,
email_imap_ssl=True,
),
),
proxy=proxy_dict,
max_login_retries=self.batch.max_login_retries,
@@ -237,15 +259,24 @@ class AccountCheckRunner:
api_strategy=WgapiLoginAPI(),
).check_account()
except Exception as exc:
self._set_item(index, status="error", message=f"检测异常: {exc}", finished_at=_now())
self._set_item(
index, status="error", message=f"检测异常: {exc}", finished_at=_now()
)
return
if self._stop.is_set() and not result.success:
self._set_item(index, status="stopped", message=result.message or "已停止", finished_at=_now())
self._set_item(
index,
status="stopped",
message=result.message or "已停止",
finished_at=_now(),
)
return
if result.success:
status = result.code if result.code in STATUS_LABELS else "account_auth_unknown"
status = (
result.code if result.code in STATUS_LABELS else "account_auth_unknown"
)
message = result.message or STATUS_LABELS.get(status, "认证状态未知")
else:
status = "error"
@@ -260,7 +291,9 @@ class AccountCheckRunner:
status: sum(1 for item in self.batch.items if item.status == status)
for status in STATUS_LABELS
}
running_count = sum(1 for item in self.batch.items if item.status in {"pending", "running"})
running_count = sum(
1 for item in self.batch.items if item.status in {"pending", "running"}
)
finished_count = len(self.batch.items) - running_count
return {
"batch_id": self.batch.batch_id,
@@ -296,7 +329,10 @@ class AccountCheckRunner:
if item.status != status:
continue
line = item.export_text
if status in {"error", "stopped", "account_auth_unknown"} and item.message:
if (
status in {"error", "stopped", "account_auth_unknown"}
and item.message
):
line = f"{line}----{item.message}"
lines.append(line)
content = "\n".join(lines)
@@ -309,7 +345,9 @@ class AccountCheckRunner:
def run(self):
"""线程入口。"""
self._set_batch(status="running", message="批次运行中", started_at=_now(), finished_at=None)
self._set_batch(
status="running", message="批次运行中", started_at=_now(), finished_at=None
)
try:
if self._shared_proxy_fetcher:
self._shared_proxy_fetcher.warmup_whitelist()
@@ -318,14 +356,21 @@ class AccountCheckRunner:
futures = []
for index, account in enumerate(self.accounts):
if self._stop.is_set():
self._set_item(index, status="stopped", message="已停止", finished_at=_now())
self._set_item(
index,
status="stopped",
message="已停止",
finished_at=_now(),
)
continue
futures.append(executor.submit(self._run_one, index, account))
for future in as_completed(futures):
future.result()
except Exception as exc:
self._set_batch(status="error", message=f"批次执行异常: {exc}", finished_at=_now())
self._set_batch(
status="error", message=f"批次执行异常: {exc}", finished_at=_now()
)
return
if self._stop.is_set():
@@ -370,7 +415,9 @@ class AccountCheckRegistry:
for account in accounts
],
)
runner = AccountCheckRunner(batch=batch, accounts=accounts, proxy_config=proxy_config)
runner = AccountCheckRunner(
batch=batch, accounts=accounts, proxy_config=proxy_config
)
with self._lock:
self._runners[batch_id] = runner
return runner