增加代理展示

This commit is contained in:
yml2213
2026-07-10 00:21:07 +08:00
parent cd2d02c86e
commit baec2ab0fb
5 changed files with 40 additions and 5 deletions
+2 -1
View File
@@ -55,13 +55,14 @@ def create_account_check_batch(
if not accounts:
raise HTTPException(status_code=400, detail="没有识别到有效账号")
proxy_config = db.query(ProxyConfigModel).first()
proxy_config = db.query(ProxyConfigModel).first() if req.use_proxy else None
runner = account_check_registry.create(
accounts=accounts,
created_by=current.id,
concurrency=req.concurrency,
max_login_retries=req.max_login_retries,
max_total_time=req.max_total_time,
use_proxy=req.use_proxy,
proxy_config=proxy_config,
)
thread = threading.Thread(target=runner.run, daemon=True)
+2
View File
@@ -175,6 +175,7 @@ class AccountCheckBatchRequest(BaseModel):
concurrency: int = Field(3, ge=1, le=10)
max_login_retries: int = Field(0, ge=0, le=50)
max_total_time: float = Field(300, ge=0, le=3600)
use_proxy: bool = False
class AccountCheckItemOut(BaseModel):
@@ -195,6 +196,7 @@ class AccountCheckBatchOut(BaseModel):
concurrency: int
max_login_retries: int
max_total_time: float
use_proxy: bool
total: int
finished_count: int
running_count: int
+14 -2
View File
@@ -93,6 +93,7 @@ class AccountCheckBatch:
concurrency: int
max_login_retries: int
max_total_time: float
use_proxy: bool
items: list[AccountCheckItemState]
status: str = "pending"
message: str = "等待开始"
@@ -146,7 +147,12 @@ class AccountCheckRunner:
def _create_proxy_fetcher(self) -> ProxyFetcher | None:
"""按全局代理配置创建 API 代理获取器。"""
if not self.proxy_config or not self.proxy_config.enabled or not self.proxy_config.api_url:
if (
not self.batch.use_proxy
or not self.proxy_config
or not self.proxy_config.enabled
or not self.proxy_config.api_url
):
return None
wl_platform = "xiequ"
@@ -169,9 +175,12 @@ class AccountCheckRunner:
def _resolve_static_proxy(self) -> tuple[dict[str, str] | None, str]:
"""解析静态代理;API 代理由 DouyuLogin 内部通过 proxy_fetcher 获取。"""
if not self.proxy_config or not self.proxy_config.enabled:
if not self.batch.use_proxy:
return None, ""
if not self.proxy_config or not self.proxy_config.enabled:
return None, "代理不可用: 未启用代理配置"
if self.proxy_config.http or self.proxy_config.https:
proxy_url = self.proxy_config.http or self.proxy_config.https
return {"http": proxy_url, "https": proxy_url}, ""
@@ -261,6 +270,7 @@ class AccountCheckRunner:
"concurrency": self.batch.concurrency,
"max_login_retries": self.batch.max_login_retries,
"max_total_time": self.batch.max_total_time,
"use_proxy": self.batch.use_proxy,
"total": len(self.batch.items),
"finished_count": finished_count,
"running_count": running_count,
@@ -338,6 +348,7 @@ class AccountCheckRegistry:
concurrency: int,
max_login_retries: int,
max_total_time: float,
use_proxy: bool = False,
proxy_config: Optional[ProxyConfigModel] = None,
) -> AccountCheckRunner:
batch_id = uuid.uuid4().hex[:12]
@@ -348,6 +359,7 @@ class AccountCheckRegistry:
concurrency=max(1, min(int(concurrency or 1), 10)),
max_login_retries=normalized_retries,
max_total_time=max(0.0, float(max_total_time or 0)),
use_proxy=bool(use_proxy),
items=[
AccountCheckItemState(
line=account.line,