增加另一个登录接口

This commit is contained in:
yml2213
2026-06-26 17:22:51 +08:00
parent f736ef4f4c
commit d7d7c0cbb0
12 changed files with 1739 additions and 73 deletions
+11 -1
View File
@@ -11,11 +11,18 @@ from typing import Optional
from sqlalchemy.orm import Session
from core.douyu import DouyuLogin
from core.douyu import DouyuLogin, WgapiLoginAPI, IframeLoginAPI
from core.douyu.proxy_fetcher import ProxyFetcher
from ..models import Account as AccountModel, LoginTask, ProxyConfig as ProxyConfigModel
def _create_api_strategy(strategy_name: str):
"""根据名称创建登录接口策略实例。"""
if strategy_name == "iframe":
return IframeLoginAPI()
return WgapiLoginAPI()
class LoginBatchRunner:
"""批量登录执行器,在线程中运行,通过 ThreadPoolExecutor 并发登录多个账号。"""
@@ -31,6 +38,7 @@ class LoginBatchRunner:
log_queue: Optional[asyncio.Queue] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
concurrency: int = 3,
api_strategy: str = "wgapi",
):
self.db = db
self.account_ids = account_ids
@@ -45,6 +53,7 @@ class LoginBatchRunner:
self.loop = loop
self.batch_id = uuid.uuid4().hex[:12]
self.concurrency = max(1, min(concurrency, 10)) # 限制 1-10
self.api_strategy = _create_api_strategy(api_strategy)
self._stop = threading.Event()
self._counter_lock = threading.Lock()
self._completed = 0
@@ -154,6 +163,7 @@ class LoginBatchRunner:
max_total_time=self.max_total_time,
proxy_fetcher=self._shared_proxy_fetcher,
stop_event=self._stop,
api_strategy=self.api_strategy,
)
result = loginer.login()