修复虎牙注册续跑逻辑:默认从停止处继续,不重试已失败项

「继续未完成」只跑 pending/stopped;另提供「重试失败」可选重跑 error。避免大批量中途停止后把失败号全部再跑一遍。
This commit is contained in:
yml2213
2026-07-12 20:08:03 +08:00
parent e18b2c6e0c
commit 851d8c122b
5 changed files with 142 additions and 60 deletions
+70 -29
View File
@@ -145,12 +145,34 @@ export default function HuyaRegisterPage() {
const batchId = batch?.batch_id || '';
const isRunning = !!batch && batch.status === 'running';
const hasUnfinished = !!batch && (
(batch.failed_count || 0) + (batch.stopped_count || 0) > 0
|| (batch.items || []).some((item) => item.status !== 'success')
|| ((batch.success_count || 0) < (batch.total || 0))
);
const canRetry = !!batch && !isRunning && hasUnfinished
// 默认可「继续」的条目:未开始/已停止/中断中(不含 error、success
const resumableCount = useMemo(() => {
if (!batch?.items?.length) {
// 摘要无明细时:用 停止数 + (总数-成功-失败-停止) 估算未完成
const total = batch?.total || 0;
const success = batch?.success_count || 0;
const failed = batch?.failed_count || 0;
const stopped = batch?.stopped_count || 0;
return Math.max(0, stopped + (total - success - failed - stopped));
}
return batch.items.filter((item) => (
item.status === 'pending'
|| item.status === 'stopped'
|| item.status === 'sending'
|| item.status === 'waiting'
|| item.status === 'changing'
|| item.status === 'logging'
)).length;
}, [batch]);
const failedCount = useMemo(() => {
if (!batch?.items?.length) return batch?.failed_count || 0;
return batch.items.filter((item) => item.status === 'error').length;
}, [batch]);
const canContinue = !!batch && !isRunning && resumableCount > 0
&& (RETRYABLE_BATCH.has(batch.status) || batch.status === 'pending');
const canRetryFailed = !!batch && !isRunning && failedCount > 0
&& (RETRYABLE_BATCH.has(batch.status) || batch.status === 'pending');
const loadBatchById = useCallback(async (id: string) => {
@@ -257,13 +279,6 @@ export default function HuyaRegisterPage() {
[batch],
);
const retryableCount = useMemo(() => {
if (!batch?.items?.length) {
return (batch?.failed_count || 0) + (batch?.stopped_count || 0);
}
return batch.items.filter((item) => item.status !== 'success').length;
}, [batch]);
const handleStart = async () => {
if (!text.trim()) {
message.warning('请先粘贴手机号池');
@@ -309,20 +324,38 @@ export default function HuyaRegisterPage() {
}
};
const handleRetry = async () => {
const buildRetryPayload = (mode: 'continue' | 'retry_failed' | 'all_unfinished' = 'continue') => ({
mode,
concurrency,
wait_seconds: waitSeconds,
poll_interval: pollInterval,
password_prefix: passwordMode === 'random' ? (passwordPrefix.trim() || 'hy') : undefined,
fixed_password: passwordMode === 'fixed' ? fixedPassword.trim() : undefined,
use_proxy: useProxy,
});
const handleContinue = async () => {
if (!batchId) return;
setRetrying(true);
try {
const data = await huyaApi.retryAutoRegisterBatch(batchId, {
concurrency,
wait_seconds: waitSeconds,
poll_interval: pollInterval,
password_prefix: passwordMode === 'random' ? (passwordPrefix.trim() || 'hy') : undefined,
fixed_password: passwordMode === 'fixed' ? fixedPassword.trim() : undefined,
use_proxy: useProxy,
});
const data = await huyaApi.retryAutoRegisterBatch(batchId, buildRetryPayload('continue'));
setBatch(data);
message.success(`开始续跑 ${retryableCount}失败/未完成项`);
message.success(`从停止处继续,处理 ${resumableCount}未完成号码(跳过已成功/已失败)`);
loadHistory();
} catch (e: unknown) {
message.error(getErrorMessage(e));
} finally {
setRetrying(false);
}
};
const handleRetryFailed = async () => {
if (!batchId) return;
setRetrying(true);
try {
const data = await huyaApi.retryAutoRegisterBatch(batchId, buildRetryPayload('retry_failed'));
setBatch(data);
message.success(`已开始重试 ${failedCount} 条失败号码`);
loadHistory();
} catch (e: unknown) {
message.error(getErrorMessage(e));
@@ -484,13 +517,14 @@ export default function HuyaRegisterPage() {
try {
setRetrying(true);
const data = await huyaApi.retryAutoRegisterBatch(row.batch_id, {
mode: 'continue',
concurrency,
wait_seconds: waitSeconds,
poll_interval: pollInterval,
use_proxy: useProxy,
});
setBatch(data);
message.success('已开始续跑失败/未完成');
message.success('已从停止处继续未完成号码');
loadHistory();
} catch (e: unknown) {
message.error(getErrorMessage(e));
@@ -499,7 +533,7 @@ export default function HuyaRegisterPage() {
}
}}
>
</Button>
<Button
size="small"
@@ -670,10 +704,17 @@ export default function HuyaRegisterPage() {
<Button
icon={<RedoOutlined />}
loading={retrying}
disabled={!canRetry}
onClick={handleRetry}
disabled={!canContinue}
onClick={handleContinue}
>
{retryableCount > 0 ? ` (${retryableCount})` : ''}
{resumableCount > 0 ? ` (${resumableCount})` : ''}
</Button>
<Button
loading={retrying}
disabled={!canRetryFailed}
onClick={handleRetryFailed}
>
{failedCount > 0 ? ` (${failedCount})` : ''}
</Button>
<Button
icon={<DownloadOutlined />}
@@ -686,7 +727,7 @@ export default function HuyaRegisterPage() {
</Col>
</Row>
<Text type="secondary">
txt
txt
</Text>
</Space>
</Card>