refactor: 收口跨平台重复业务实现
This commit is contained in:
@@ -16,7 +16,6 @@ from sqlalchemy.orm import Session, object_session
|
||||
|
||||
from core.douyu import DouyuLogin, create_login_api_strategy
|
||||
from core.douyu.login import AccountLike
|
||||
from core.douyu.proxy_fetcher import ProxyFetcher
|
||||
|
||||
from ..models import Account as AccountModel
|
||||
from ..models import LoginTask
|
||||
@@ -31,6 +30,7 @@ from .account_lifecycle import on_ck_verdict, on_login_success, sync_status
|
||||
from .cookie_check_service import check_douyu_cookie
|
||||
from .douyu_service import LOGIN_ATTEMPT_IN_FLIGHT_STATUSES
|
||||
from .login_failure import classify_failure, failure_kind_label, is_account_fault
|
||||
from .proxy_service import build_proxy_runtime
|
||||
|
||||
CHECK_STATUS_MESSAGES = {
|
||||
"account_cancelled": "账号已注销",
|
||||
@@ -265,34 +265,11 @@ class LoginBatchRunner:
|
||||
self._completed = 0
|
||||
|
||||
# 共享代理获取器(无池,每次取新代理)
|
||||
self._shared_proxy_fetcher = None
|
||||
proxy_config = self.proxy_config
|
||||
if proxy_config and proxy_config.enabled and proxy_config.api_url:
|
||||
wl_platform = "xiequ"
|
||||
wl_credentials = None
|
||||
if proxy_config.whitelist_enabled:
|
||||
wl_platform = (
|
||||
getattr(proxy_config, "whitelist_platform", None) or "xiequ"
|
||||
)
|
||||
wl_credentials = getattr(proxy_config, "whitelist_credentials", None)
|
||||
# 向后兼容
|
||||
if (
|
||||
not wl_credentials
|
||||
and proxy_config.whitelist_uid
|
||||
and proxy_config.whitelist_ukey
|
||||
):
|
||||
wl_platform = "xiequ"
|
||||
wl_credentials = {
|
||||
"uid": proxy_config.whitelist_uid,
|
||||
"ukey": proxy_config.whitelist_ukey,
|
||||
}
|
||||
|
||||
self._shared_proxy_fetcher = ProxyFetcher(
|
||||
api_url=proxy_config.api_url,
|
||||
whitelist_platform=wl_platform,
|
||||
whitelist_credentials=wl_credentials,
|
||||
stop_event=self._stop,
|
||||
)
|
||||
self._proxy_runtime = build_proxy_runtime(
|
||||
self.proxy_config,
|
||||
stop_event=self._stop,
|
||||
)
|
||||
self._shared_proxy_fetcher = self._proxy_runtime.api_fetcher
|
||||
|
||||
def stop(self):
|
||||
self._stop.set()
|
||||
@@ -369,10 +346,13 @@ class LoginBatchRunner:
|
||||
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}, f"使用静态代理: {proxy_url}"
|
||||
if self._proxy_runtime.static_proxies:
|
||||
proxy_url = (
|
||||
self._proxy_runtime.static_proxies.get("https")
|
||||
or self._proxy_runtime.static_proxies.get("http")
|
||||
or ""
|
||||
)
|
||||
return self._proxy_runtime.static_proxies, f"使用静态代理: {proxy_url}"
|
||||
|
||||
# API代理:由 DouyuLogin 通过 proxy_fetcher 内部管理
|
||||
return None, ""
|
||||
|
||||
Reference in New Issue
Block a user