refactor: 收口跨平台重复业务实现
This commit is contained in:
@@ -17,6 +17,7 @@ from core.douyu.proxy_fetcher import ProxyFetcher
|
||||
from ..models import HuyaTask
|
||||
from ..models import ProxyConfig as ProxyConfigModel
|
||||
from .huya_service import cookie_value
|
||||
from .proxy_service import ProxyRuntime, build_proxy_runtime
|
||||
|
||||
# 绑定跳转与充值下单共用(bind 与 recharge 两个域都引用了 sourceId)
|
||||
HUYA_RECHARGE_SOURCE_ID = "yellowcarlist"
|
||||
@@ -51,12 +52,17 @@ class HuyaBatchRunnerCore:
|
||||
self._started = 0
|
||||
self._wss_sessions = threading.local()
|
||||
self._proxy_cfg = None
|
||||
self._proxy_runtime = ProxyRuntime()
|
||||
self._proxy_fetcher = None
|
||||
self._static_proxies = None
|
||||
if self.task_type == "exchange_goods":
|
||||
self._proxy_cfg = (
|
||||
db.query(ProxyConfigModel).first() if db is not None else None
|
||||
)
|
||||
self._proxy_runtime = build_proxy_runtime(
|
||||
self._proxy_cfg,
|
||||
stop_event=self._stop,
|
||||
)
|
||||
self._proxy_fetcher = self._create_proxy_fetcher()
|
||||
self._static_proxies = self._resolve_static_proxies()
|
||||
|
||||
@@ -144,38 +150,10 @@ class HuyaBatchRunnerCore:
|
||||
|
||||
def _create_proxy_fetcher(self) -> ProxyFetcher | None:
|
||||
"""兑换任务使用现有全局代理 API,每个账号任务取一个新出口。"""
|
||||
cfg = self._proxy_cfg
|
||||
if not cfg or not cfg.enabled or not cfg.api_url:
|
||||
return None
|
||||
platform = getattr(cfg, "whitelist_platform", None) or "xiequ"
|
||||
credentials = getattr(cfg, "whitelist_credentials", None)
|
||||
if (
|
||||
not credentials
|
||||
and getattr(cfg, "whitelist_uid", "")
|
||||
and getattr(cfg, "whitelist_ukey", "")
|
||||
):
|
||||
credentials = {
|
||||
"uid": cfg.whitelist_uid,
|
||||
"ukey": cfg.whitelist_ukey,
|
||||
}
|
||||
return ProxyFetcher(
|
||||
api_url=cfg.api_url,
|
||||
whitelist_platform=platform,
|
||||
whitelist_credentials=(
|
||||
credentials if getattr(cfg, "whitelist_enabled", False) else None
|
||||
),
|
||||
stop_event=self._stop,
|
||||
)
|
||||
return self._proxy_runtime.api_fetcher
|
||||
|
||||
def _resolve_static_proxies(self) -> dict[str, str] | None:
|
||||
cfg = self._proxy_cfg
|
||||
if not cfg or not cfg.enabled:
|
||||
return None
|
||||
http = str(getattr(cfg, "http", "") or "").strip()
|
||||
https = str(getattr(cfg, "https", "") or "").strip()
|
||||
if not http and not https:
|
||||
return None
|
||||
return {"http": http or https, "https": https or http}
|
||||
return self._proxy_runtime.static_proxies
|
||||
|
||||
def _exchange_proxies(self) -> tuple[dict[str, str] | None, str, str]:
|
||||
"""返回兑换任务的代理、来源和错误;其他任务不会调用这里。"""
|
||||
|
||||
Reference in New Issue
Block a user