添加虎牙自动注册
This commit is contained in:
@@ -0,0 +1,284 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Button, Card, Col, Input, InputNumber, message, Row, Space, Statistic, Table, Tag, Typography,
|
||||
} from 'antd';
|
||||
import type { TableProps } from 'antd';
|
||||
import { DownloadOutlined, PlayCircleOutlined, ReloadOutlined, StopOutlined } from '@ant-design/icons';
|
||||
import { huyaApi, type HuyaAutoRegisterBatch, type HuyaAutoRegisterItem } from '../api/modules';
|
||||
import { formatTime } from '../utils/time';
|
||||
import { getErrorMessage } from '../utils/error';
|
||||
|
||||
const { TextArea } = Input;
|
||||
const { Text, Title } = Typography;
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
pending: '等待',
|
||||
sending: '发码',
|
||||
waiting: '等待验证码',
|
||||
logging: '保存',
|
||||
success: '成功',
|
||||
error: '失败',
|
||||
stopped: '已停止',
|
||||
};
|
||||
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
pending: 'default',
|
||||
sending: 'processing',
|
||||
waiting: 'processing',
|
||||
logging: 'processing',
|
||||
success: 'success',
|
||||
error: 'error',
|
||||
stopped: 'warning',
|
||||
};
|
||||
|
||||
const RUNNING_STATUS = new Set(['pending', 'running']);
|
||||
|
||||
export default function HuyaRegisterPage() {
|
||||
const [text, setText] = useState('');
|
||||
const [tag, setTag] = useState('');
|
||||
const [concurrency, setConcurrency] = useState(1);
|
||||
const [waitSeconds, setWaitSeconds] = useState(180);
|
||||
const [pollInterval, setPollInterval] = useState(5);
|
||||
const [batch, setBatch] = useState<HuyaAutoRegisterBatch | null>(null);
|
||||
const [starting, setStarting] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [stopping, setStopping] = useState(false);
|
||||
|
||||
const batchId = batch?.batch_id || '';
|
||||
const isRunning = !!batch && RUNNING_STATUS.has(batch.status);
|
||||
|
||||
const refreshBatch = useCallback(async () => {
|
||||
if (!batchId) return;
|
||||
setRefreshing(true);
|
||||
try {
|
||||
const data = await huyaApi.getAutoRegisterBatch(batchId);
|
||||
setBatch(data);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
}, [batchId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isRunning || !batchId) return undefined;
|
||||
const timer = window.setInterval(() => {
|
||||
refreshBatch();
|
||||
}, 2000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [batchId, isRunning, refreshBatch]);
|
||||
|
||||
const successRows = useMemo(
|
||||
() => (batch?.items || []).filter((item) => item.status === 'success' && item.cookie),
|
||||
[batch],
|
||||
);
|
||||
|
||||
const handleStart = async () => {
|
||||
if (!text.trim()) {
|
||||
message.warning('请先粘贴手机号池');
|
||||
return;
|
||||
}
|
||||
setStarting(true);
|
||||
try {
|
||||
const data = await huyaApi.startAutoRegister({
|
||||
text,
|
||||
tag: tag.trim(),
|
||||
concurrency,
|
||||
wait_seconds: waitSeconds,
|
||||
poll_interval: pollInterval,
|
||||
});
|
||||
setBatch(data);
|
||||
message.success('自动注册批次已启动');
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setStarting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleStop = async () => {
|
||||
if (!batchId) return;
|
||||
setStopping(true);
|
||||
try {
|
||||
const result = await huyaApi.stopAutoRegisterBatch(batchId);
|
||||
message.success(result.message);
|
||||
refreshBatch();
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setStopping(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportSuccess = () => {
|
||||
if (successRows.length === 0) {
|
||||
message.warning('当前批次没有可导出的成功 CK');
|
||||
return;
|
||||
}
|
||||
const body = successRows.map((item) => `${item.phone}----${item.cookie}`).join('\n');
|
||||
const blob = new Blob([body], { type: 'text/plain;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `huya-register-${batchId || 'success'}.txt`;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const columns: TableProps<HuyaAutoRegisterItem>['columns'] = [
|
||||
{ title: '行', dataIndex: 'line', width: 64 },
|
||||
{ title: '手机号', dataIndex: 'phone', width: 150 },
|
||||
{ title: '平台', dataIndex: 'provider', width: 90 },
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 110,
|
||||
render: (status: string) => (
|
||||
<Tag color={STATUS_COLORS[status] || 'default'}>
|
||||
{STATUS_LABELS[status] || status}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{ title: '验证码', dataIndex: 'code', width: 100 },
|
||||
{ title: '轮询', dataIndex: 'attempts', width: 80 },
|
||||
{
|
||||
title: '账号',
|
||||
width: 160,
|
||||
render: (_, item) => item.uid || (item.account_id ? `#${item.account_id}` : '-'),
|
||||
},
|
||||
{
|
||||
title: 'Cookie',
|
||||
dataIndex: 'cookie_preview',
|
||||
width: 220,
|
||||
ellipsis: true,
|
||||
render: (value: string) => value || '-',
|
||||
},
|
||||
{
|
||||
title: '消息',
|
||||
dataIndex: 'message',
|
||||
ellipsis: true,
|
||||
render: (value: string) => value || '-',
|
||||
},
|
||||
{
|
||||
title: '完成时间',
|
||||
dataIndex: 'finished_at',
|
||||
width: 170,
|
||||
render: (value: string | null) => formatTime(value),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
||||
<Title level={3} style={{ margin: 0 }}>虎牙自动注册</Title>
|
||||
|
||||
<Card title="手机号池">
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
<TextArea
|
||||
rows={9}
|
||||
value={text}
|
||||
onChange={(event) => setText(event.target.value)}
|
||||
placeholder="手机号----短信查询URL"
|
||||
disabled={isRunning}
|
||||
/>
|
||||
<Row gutter={[12, 12]}>
|
||||
<Col xs={24} md={8}>
|
||||
<Text type="secondary">标签</Text>
|
||||
<Input
|
||||
value={tag}
|
||||
onChange={(event) => setTag(event.target.value)}
|
||||
placeholder="注册批次"
|
||||
disabled={isRunning}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={8} md={4}>
|
||||
<Text type="secondary">并发</Text>
|
||||
<InputNumber
|
||||
min={1}
|
||||
max={5}
|
||||
value={concurrency}
|
||||
onChange={(value) => setConcurrency(Number(value || 1))}
|
||||
disabled={isRunning}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={8} md={4}>
|
||||
<Text type="secondary">等待秒数</Text>
|
||||
<InputNumber
|
||||
min={15}
|
||||
max={600}
|
||||
value={waitSeconds}
|
||||
onChange={(value) => setWaitSeconds(Number(value || 180))}
|
||||
disabled={isRunning}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={8} md={4}>
|
||||
<Text type="secondary">轮询间隔</Text>
|
||||
<InputNumber
|
||||
min={1}
|
||||
max={30}
|
||||
value={pollInterval}
|
||||
onChange={(value) => setPollInterval(Number(value || 5))}
|
||||
disabled={isRunning}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={4}>
|
||||
<Space style={{ width: '100%', paddingTop: 22 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlayCircleOutlined />}
|
||||
loading={starting}
|
||||
disabled={isRunning}
|
||||
onClick={handleStart}
|
||||
>
|
||||
开始
|
||||
</Button>
|
||||
<Button
|
||||
danger
|
||||
icon={<StopOutlined />}
|
||||
loading={stopping}
|
||||
disabled={!isRunning}
|
||||
onClick={handleStop}
|
||||
>
|
||||
停止
|
||||
</Button>
|
||||
</Space>
|
||||
</Col>
|
||||
</Row>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="批次结果"
|
||||
extra={(
|
||||
<Space>
|
||||
<Button icon={<ReloadOutlined />} loading={refreshing} disabled={!batchId} onClick={refreshBatch}>
|
||||
刷新
|
||||
</Button>
|
||||
<Button icon={<DownloadOutlined />} disabled={successRows.length === 0} onClick={handleExportSuccess}>
|
||||
导出成功 CK
|
||||
</Button>
|
||||
</Space>
|
||||
)}
|
||||
>
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||
<Col xs={12} md={4}><Statistic title="总数" value={batch?.total || 0} /></Col>
|
||||
<Col xs={12} md={4}><Statistic title="成功" value={batch?.success_count || 0} /></Col>
|
||||
<Col xs={12} md={4}><Statistic title="失败" value={batch?.failed_count || 0} /></Col>
|
||||
<Col xs={12} md={4}><Statistic title="运行中" value={batch?.running_count || 0} /></Col>
|
||||
<Col xs={12} md={4}><Statistic title="停止" value={batch?.stopped_count || 0} /></Col>
|
||||
<Col xs={12} md={4}><Statistic title="批次" value={batch?.batch_id || '-'} /></Col>
|
||||
</Row>
|
||||
<Table
|
||||
rowKey="line"
|
||||
columns={columns}
|
||||
dataSource={batch?.items || []}
|
||||
loading={refreshing && !isRunning}
|
||||
pagination={{ pageSize: 20, showSizeChanger: true }}
|
||||
scroll={{ x: 1280 }}
|
||||
/>
|
||||
</Card>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user