import { useState } from 'react' import { TestTube, CheckCircle, XCircle, Loader2, Save, Server, Plus, X } from 'lucide-react' import { Card, CardHeader, CardTitle, CardContent, Button, Input } from '../components/common' import { useConfig } from '../hooks/useConfig' export default function S2AConfig() { const { config, updateS2AConfig, updatePoolingConfig, testConnection, isConnected, } = useConfig() const [testing, setTesting] = useState(false) const [testResult, setTestResult] = useState(null) const [saved, setSaved] = useState(false) // Local form state - S2A 连接 const [s2aApiBase, setS2aApiBase] = useState(config.s2a.apiBase) const [s2aAdminKey, setS2aAdminKey] = useState(config.s2a.adminKey) // Local form state - 入库设置 const [poolingConcurrency, setPoolingConcurrency] = useState(config.pooling.concurrency) const [poolingPriority, setPoolingPriority] = useState(config.pooling.priority) const [groupIds, setGroupIds] = useState(config.pooling.groupIds || []) const [newGroupId, setNewGroupId] = useState('') const handleTestConnection = async () => { // Save first updateS2AConfig({ apiBase: s2aApiBase, adminKey: s2aAdminKey }) setTesting(true) setTestResult(null) // Wait a bit for the client to be recreated await new Promise((resolve) => setTimeout(resolve, 100)) const result = await testConnection() setTestResult(result) setTesting(false) } const handleSave = () => { updateS2AConfig({ apiBase: s2aApiBase, adminKey: s2aAdminKey }) updatePoolingConfig({ concurrency: poolingConcurrency, priority: poolingPriority, groupIds: groupIds, }) setSaved(true) setTimeout(() => setSaved(false), 2000) } const handleAddGroupId = () => { const id = parseInt(newGroupId, 10) if (!isNaN(id) && !groupIds.includes(id)) { setGroupIds([...groupIds, id]) setNewGroupId('') } } const handleRemoveGroupId = (id: number) => { setGroupIds(groupIds.filter(g => g !== id)) } return (
{/* Header */}

S2A 配置

配置 S2A 号池连接和入库参数

{/* S2A Connection */} S2A 连接配置
{isConnected ? ( 已连接 ) : ( 未连接 )}
setS2aApiBase(e.target.value)} hint="S2A 服务的 API 地址,例如 http://localhost:8080" /> setS2aAdminKey(e.target.value)} hint="S2A 管理密钥,可在 S2A 后台 Settings 页面获取" />
{testResult !== null && ( {testResult ? '连接成功' : '连接失败'} )}
{/* Pooling Settings */} 入库默认设置
setPoolingConcurrency(Number(e.target.value))} hint="账号的默认并发请求数" /> setPoolingPriority(Number(e.target.value))} hint="账号的默认优先级,数值越大优先级越高" />
{/* Group IDs */}
{groupIds.map(id => ( {id} ))} {groupIds.length === 0 && ( 未设置分组 )}
setNewGroupId(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleAddGroupId()} />

入库时账号将被分配到这些分组

{/* Info */}

配置说明:

  • S2A API 地址是您部署的 S2A 服务的完整 URL
  • Admin API Key 用于管理账号池,具有完全权限
  • 入库默认设置会应用到新入库的账号
  • 分组 ID 用于将账号归类到指定分组
) }