增加另一个登录接口
This commit is contained in:
@@ -60,6 +60,7 @@ async def create_batch(
|
||||
log_queue=log_queue,
|
||||
loop=loop,
|
||||
concurrency=req.concurrency,
|
||||
api_strategy=req.api_strategy,
|
||||
)
|
||||
|
||||
batch_id = runner.batch_id
|
||||
|
||||
@@ -127,6 +127,7 @@ class LoginBatchRequest(BaseModel):
|
||||
max_login_retries: int = 0 # 登录整体重试次数,0=无限重试直到成功(后端兜底 20 次)
|
||||
max_total_time: float = 300 # 单账号登录总时长上限(秒),0=不限制
|
||||
concurrency: int = 3 # 并发数,1-10
|
||||
api_strategy: str = "wgapi" # 接口策略: wgapi(新版)或 iframe(旧版备选)
|
||||
|
||||
|
||||
class LoginTaskOut(BaseModel):
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ interface CreateBatchParams {
|
||||
concurrency?: number;
|
||||
max_login_retries?: number;
|
||||
max_total_time?: number;
|
||||
api_strategy?: string;
|
||||
}
|
||||
|
||||
export const loginApi = {
|
||||
|
||||
@@ -51,12 +51,16 @@ export default function LoginTasksPage() {
|
||||
const v = localStorage.getItem('login_max_login_retries');
|
||||
return v !== null ? Math.max(0, Number(v) || 0) : 0;
|
||||
});
|
||||
const [apiStrategy, setApiStrategy] = useState(() => {
|
||||
return localStorage.getItem('login_api_strategy') || 'wgapi';
|
||||
});
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
|
||||
// 值变化时自动持久化
|
||||
useEffect(() => { localStorage.setItem('login_concurrency', String(concurrency)); }, [concurrency]);
|
||||
useEffect(() => { localStorage.setItem('login_max_total_time', String(maxTotalTime)); }, [maxTotalTime]);
|
||||
useEffect(() => { localStorage.setItem('login_max_login_retries', String(maxLoginRetries)); }, [maxLoginRetries]);
|
||||
useEffect(() => { localStorage.setItem('login_api_strategy', apiStrategy); }, [apiStrategy]);
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
|
||||
const { logs, connected: wsConnected, connect: connectLogs } = useWebSocketLogs();
|
||||
const { can } = usePermissions();
|
||||
@@ -156,6 +160,7 @@ export default function LoginTasksPage() {
|
||||
concurrency,
|
||||
max_login_retries: maxLoginRetries,
|
||||
max_total_time: maxTotalTime,
|
||||
api_strategy: apiStrategy,
|
||||
});
|
||||
setBatchId(result.batch_id);
|
||||
message.success(`已创建登录任务,共 ${result.count} 个账号`);
|
||||
@@ -342,7 +347,7 @@ export default function LoginTasksPage() {
|
||||
标签选中 {accounts.filter((a) => selectedTags.includes((a.tag || '').trim())).length} 个
|
||||
</span>
|
||||
)}
|
||||
<Tooltip title={`登录设置(并发 ${concurrency},超时 ${maxTotalTime || '∞'}s,重试 ${maxLoginRetries || '∞'})`}>
|
||||
<Tooltip title={`登录设置(接口 ${apiStrategy},并发 ${concurrency},超时 ${maxTotalTime || '∞'}s,重试 ${maxLoginRetries || '∞'})`}>
|
||||
<Button
|
||||
icon={<SettingOutlined />}
|
||||
onClick={() => setSettingsOpen(true)}
|
||||
@@ -435,6 +440,7 @@ export default function LoginTasksPage() {
|
||||
setConcurrency(3);
|
||||
setMaxTotalTime(300);
|
||||
setMaxLoginRetries(0);
|
||||
setApiStrategy('wgapi');
|
||||
}}
|
||||
>
|
||||
恢复默认
|
||||
@@ -445,6 +451,20 @@ export default function LoginTasksPage() {
|
||||
]}
|
||||
>
|
||||
<Form layout="vertical" style={{ marginTop: 8 }}>
|
||||
<Form.Item
|
||||
label="登录接口"
|
||||
tooltip="选择登录使用的接口版本。wgapi 为新版(推荐),iframe 为旧版备选。"
|
||||
>
|
||||
<Select
|
||||
value={apiStrategy}
|
||||
onChange={setApiStrategy}
|
||||
style={{ width: 200 }}
|
||||
options={[
|
||||
{ value: 'wgapi', label: 'wgapi(新版,推荐)' },
|
||||
{ value: 'iframe', label: 'iframe(旧版备选)' },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="并发数"
|
||||
tooltip="同时登录的账号数。1 为顺序执行,最多 10。"
|
||||
|
||||
Reference in New Issue
Block a user