增加代理展示

This commit is contained in:
yml2213
2026-07-10 00:21:07 +08:00
parent cd2d02c86e
commit baec2ab0fb
5 changed files with 40 additions and 5 deletions
+2 -1
View File
@@ -55,13 +55,14 @@ def create_account_check_batch(
if not accounts: if not accounts:
raise HTTPException(status_code=400, detail="没有识别到有效账号") raise HTTPException(status_code=400, detail="没有识别到有效账号")
proxy_config = db.query(ProxyConfigModel).first() proxy_config = db.query(ProxyConfigModel).first() if req.use_proxy else None
runner = account_check_registry.create( runner = account_check_registry.create(
accounts=accounts, accounts=accounts,
created_by=current.id, created_by=current.id,
concurrency=req.concurrency, concurrency=req.concurrency,
max_login_retries=req.max_login_retries, max_login_retries=req.max_login_retries,
max_total_time=req.max_total_time, max_total_time=req.max_total_time,
use_proxy=req.use_proxy,
proxy_config=proxy_config, proxy_config=proxy_config,
) )
thread = threading.Thread(target=runner.run, daemon=True) thread = threading.Thread(target=runner.run, daemon=True)
+2
View File
@@ -175,6 +175,7 @@ class AccountCheckBatchRequest(BaseModel):
concurrency: int = Field(3, ge=1, le=10) concurrency: int = Field(3, ge=1, le=10)
max_login_retries: int = Field(0, ge=0, le=50) max_login_retries: int = Field(0, ge=0, le=50)
max_total_time: float = Field(300, ge=0, le=3600) max_total_time: float = Field(300, ge=0, le=3600)
use_proxy: bool = False
class AccountCheckItemOut(BaseModel): class AccountCheckItemOut(BaseModel):
@@ -195,6 +196,7 @@ class AccountCheckBatchOut(BaseModel):
concurrency: int concurrency: int
max_login_retries: int max_login_retries: int
max_total_time: float max_total_time: float
use_proxy: bool
total: int total: int
finished_count: int finished_count: int
running_count: int running_count: int
+14 -2
View File
@@ -93,6 +93,7 @@ class AccountCheckBatch:
concurrency: int concurrency: int
max_login_retries: int max_login_retries: int
max_total_time: float max_total_time: float
use_proxy: bool
items: list[AccountCheckItemState] items: list[AccountCheckItemState]
status: str = "pending" status: str = "pending"
message: str = "等待开始" message: str = "等待开始"
@@ -146,7 +147,12 @@ class AccountCheckRunner:
def _create_proxy_fetcher(self) -> ProxyFetcher | None: def _create_proxy_fetcher(self) -> ProxyFetcher | None:
"""按全局代理配置创建 API 代理获取器。""" """按全局代理配置创建 API 代理获取器。"""
if not self.proxy_config or not self.proxy_config.enabled or not self.proxy_config.api_url: 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 return None
wl_platform = "xiequ" wl_platform = "xiequ"
@@ -169,9 +175,12 @@ class AccountCheckRunner:
def _resolve_static_proxy(self) -> tuple[dict[str, str] | None, str]: def _resolve_static_proxy(self) -> tuple[dict[str, str] | None, str]:
"""解析静态代理;API 代理由 DouyuLogin 内部通过 proxy_fetcher 获取。""" """解析静态代理;API 代理由 DouyuLogin 内部通过 proxy_fetcher 获取。"""
if not self.proxy_config or not self.proxy_config.enabled: if not self.batch.use_proxy:
return None, "" return None, ""
if not self.proxy_config or not self.proxy_config.enabled:
return None, "代理不可用: 未启用代理配置"
if self.proxy_config.http or self.proxy_config.https: if self.proxy_config.http or self.proxy_config.https:
proxy_url = 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}, "" return {"http": proxy_url, "https": proxy_url}, ""
@@ -261,6 +270,7 @@ class AccountCheckRunner:
"concurrency": self.batch.concurrency, "concurrency": self.batch.concurrency,
"max_login_retries": self.batch.max_login_retries, "max_login_retries": self.batch.max_login_retries,
"max_total_time": self.batch.max_total_time, "max_total_time": self.batch.max_total_time,
"use_proxy": self.batch.use_proxy,
"total": len(self.batch.items), "total": len(self.batch.items),
"finished_count": finished_count, "finished_count": finished_count,
"running_count": running_count, "running_count": running_count,
@@ -338,6 +348,7 @@ class AccountCheckRegistry:
concurrency: int, concurrency: int,
max_login_retries: int, max_login_retries: int,
max_total_time: float, max_total_time: float,
use_proxy: bool = False,
proxy_config: Optional[ProxyConfigModel] = None, proxy_config: Optional[ProxyConfigModel] = None,
) -> AccountCheckRunner: ) -> AccountCheckRunner:
batch_id = uuid.uuid4().hex[:12] batch_id = uuid.uuid4().hex[:12]
@@ -348,6 +359,7 @@ class AccountCheckRegistry:
concurrency=max(1, min(int(concurrency or 1), 10)), concurrency=max(1, min(int(concurrency or 1), 10)),
max_login_retries=normalized_retries, max_login_retries=normalized_retries,
max_total_time=max(0.0, float(max_total_time or 0)), max_total_time=max(0.0, float(max_total_time or 0)),
use_proxy=bool(use_proxy),
items=[ items=[
AccountCheckItemState( AccountCheckItemState(
line=account.line, line=account.line,
+2
View File
@@ -101,6 +101,7 @@ export interface AccountCheckBatchRequest {
concurrency?: number; concurrency?: number;
max_login_retries?: number; max_login_retries?: number;
max_total_time?: number; max_total_time?: number;
use_proxy?: boolean;
} }
export interface AccountCheckItem { export interface AccountCheckItem {
@@ -121,6 +122,7 @@ export interface AccountCheckBatch {
concurrency: number; concurrency: number;
max_login_retries: number; max_login_retries: number;
max_total_time: number; max_total_time: number;
use_proxy: boolean;
total: number; total: number;
finished_count: number; finished_count: number;
running_count: number; running_count: number;
+20 -2
View File
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { import {
Button, Card, Col, Input, InputNumber, message, Popconfirm, Row, Space, Statistic, Table, Tag, Typography, Button, Card, Col, Input, InputNumber, message, Popconfirm, Row, Space, Statistic, Switch, Table, Tag, Typography,
} from 'antd'; } from 'antd';
import type { TableProps } from 'antd'; import type { TableProps } from 'antd';
import { DownloadOutlined, PlayCircleOutlined, ReloadOutlined, StopOutlined } from '@ant-design/icons'; import { DownloadOutlined, PlayCircleOutlined, ReloadOutlined, StopOutlined } from '@ant-design/icons';
@@ -88,6 +88,7 @@ export default function AccountCheckPage() {
const [concurrency, setConcurrency] = useState(() => readStoredNumber('account_check_concurrency', 3)); const [concurrency, setConcurrency] = useState(() => readStoredNumber('account_check_concurrency', 3));
const [maxTotalTime, setMaxTotalTime] = useState(() => readStoredNumber('account_check_max_total_time', 300)); const [maxTotalTime, setMaxTotalTime] = useState(() => readStoredNumber('account_check_max_total_time', 300));
const [maxLoginRetries, setMaxLoginRetries] = useState(() => readStoredNumber('account_check_max_login_retries', 0)); const [maxLoginRetries, setMaxLoginRetries] = useState(() => readStoredNumber('account_check_max_login_retries', 0));
const [useProxy, setUseProxy] = useState(() => localStorage.getItem('account_check_use_proxy') === 'true');
const [batch, setBatch] = useState<AccountCheckBatch | null>(null); const [batch, setBatch] = useState<AccountCheckBatch | null>(null);
const [starting, setStarting] = useState(false); const [starting, setStarting] = useState(false);
const [refreshing, setRefreshing] = useState(false); const [refreshing, setRefreshing] = useState(false);
@@ -141,6 +142,10 @@ export default function AccountCheckPage() {
localStorage.setItem('account_check_max_login_retries', String(maxLoginRetries)); localStorage.setItem('account_check_max_login_retries', String(maxLoginRetries));
}, [maxLoginRetries]); }, [maxLoginRetries]);
useEffect(() => {
localStorage.setItem('account_check_use_proxy', String(useProxy));
}, [useProxy]);
useEffect(() => { useEffect(() => {
if (restoredBatchRef.current) return; if (restoredBatchRef.current) return;
restoredBatchRef.current = true; restoredBatchRef.current = true;
@@ -178,6 +183,7 @@ export default function AccountCheckPage() {
concurrency, concurrency,
max_total_time: maxTotalTime, max_total_time: maxTotalTime,
max_login_retries: maxLoginRetries, max_login_retries: maxLoginRetries,
use_proxy: useProxy,
}); });
setBatch(data); setBatch(data);
localStorage.setItem(BATCH_STORAGE_KEY, data.batch_id); localStorage.setItem(BATCH_STORAGE_KEY, data.batch_id);
@@ -290,7 +296,19 @@ export default function AccountCheckPage() {
style={{ width: '100%' }} style={{ width: '100%' }}
/> />
</Col> </Col>
<Col xs={24} md={12}> <Col xs={12} md={4}>
<Text type="secondary"></Text>
<div style={{ height: 32, display: 'flex', alignItems: 'center' }}>
<Switch
checked={useProxy}
checkedChildren="开"
unCheckedChildren="关"
onChange={setUseProxy}
disabled={isRunning}
/>
</div>
</Col>
<Col xs={24} md={8}>
<Space wrap> <Space wrap>
<Button <Button
type="primary" type="primary"