refactor: 收口跨平台重复业务实现

This commit is contained in:
yml
2026-11-13 20:35:38 +08:00
parent ad782e1954
commit f0abca3d58
25 changed files with 1386 additions and 724 deletions
+9 -34
View File
@@ -21,6 +21,7 @@ from core.douyu.proxy_fetcher import ProxyFetcher
from ..database import SessionLocal
from ..models import ProxyConfig as ProxyConfigModel
from .account_events_service import CATEGORY_AUTH, emit
from .proxy_service import build_proxy_runtime
def _now() -> datetime:
@@ -192,41 +193,16 @@ class AccountCheckRunner:
self.proxy_config = proxy_config
self._lock = threading.Lock()
self._stop = threading.Event()
self._proxy_runtime = build_proxy_runtime(
proxy_config,
enabled=self.batch.use_proxy,
stop_event=self._stop,
)
self._shared_proxy_fetcher = self._create_proxy_fetcher()
def _create_proxy_fetcher(self) -> ProxyFetcher | None:
"""按全局代理配置创建 API 代理获取器。"""
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"
wl_credentials = None
if self.proxy_config.whitelist_enabled:
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
):
wl_credentials = {
"uid": self.proxy_config.whitelist_uid,
"ukey": self.proxy_config.whitelist_ukey,
}
return ProxyFetcher(
api_url=self.proxy_config.api_url,
whitelist_platform=wl_platform,
whitelist_credentials=wl_credentials,
stop_event=self._stop,
)
return self._proxy_runtime.api_fetcher
def _resolve_static_proxy(self) -> tuple[dict[str, str] | None, str]:
"""解析静态代理;API 代理由 DouyuLogin 内部通过 proxy_fetcher 获取。"""
@@ -236,9 +212,8 @@ class AccountCheckRunner:
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}, ""
if self._proxy_runtime.static_proxies:
return self._proxy_runtime.static_proxies, ""
if self._shared_proxy_fetcher:
return None, ""