refactor: 移除API Key输入框,统一使用.env配置

This commit is contained in:
jiawei.chen 2026-07-08 17:52:19 +08:00
parent 1ba4f90818
commit 57dcdbbb37

View File

@ -18,7 +18,6 @@ export default function ReposView() {
const [scanningBranches, setScanningBranches] = useState(false)
const [branchDetected, setBranchDetected] = useState(false)
const [detectingLatest, setDetectingLatest] = useState(false)
const [apiKey, setApiKey] = useState('')
const [expandedRepo, setExpandedRepo] = useState<string | null>(null)
const [currentTaskId, setCurrentTaskId] = useState<string | null>(null)
const [actionLabel, setActionLabel] = useState('')
@ -29,7 +28,6 @@ export default function ReposView() {
const [feShowBranchPicker, setFeShowBranchPicker] = useState(false)
const [feScanningBranches, setFeScanningBranches] = useState(false)
const [feBranchDetected, setFeBranchDetected] = useState(false)
const [feApiKey, setFeApiKey] = useState('')
const [feTaskId, setFeTaskId] = useState<string | null>(null)
const [feRunning, setFeRunning] = useState(false)
const [feLogs, setFeLogs] = useState<{ts:string;level:string;msg:string}[]>([])
@ -49,7 +47,7 @@ export default function ReposView() {
const endpoints: Record<string, string> = { analyze: `/api/repos/${repoId}/analyze`, generate: `/api/repos/${repoId}/generate`, diff: `/api/repos/${repoId}/diff`, full: `/api/repos/${repoId}/full` }
const endpoint = endpoints[mode]
if (!endpoint) return
const res = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ api_key: apiKey, test_types: ['smoke', 'unit', 'integration'] }) })
const res = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ api_key: '', test_types: ['smoke', 'unit', 'integration'] }) })
const task = await res.json(); setCurrentTaskId(task.id); connect(task.id)
}
@ -95,7 +93,7 @@ export default function ReposView() {
const scanRepo = async () => {
if (!url) return; setActionLabel('扫描仓库')
const res = await fetch('/api/repos', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url, branch, api_key: apiKey }) })
const res = await fetch('/api/repos', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url, branch }) })
const task = await res.json(); setCurrentTaskId(task.id); connect(task.id)
}
@ -188,8 +186,7 @@ export default function ReposView() {
<button className="underline ml-1" onClick={() => setBranch(latestBranch)} style={{ color: 'rgb(var(--color-accent))' }}>切换到此分支</button>
</div>
)}
<input type="password" placeholder="API Key *必填" value={apiKey} onChange={e => setApiKey(e.target.value)} className="w-48 px-3 py-2 rounded-lg text-sm outline-none" style={{ backgroundColor: 'rgb(var(--color-page))', borderColor: !apiKey ? 'rgb(var(--color-error))' : 'rgb(var(--color-border))', borderWidth: !apiKey ? '2px' : '1px', color: 'rgb(var(--color-text-primary))' }} />
<button onClick={scanRepo} disabled={running || !url || !apiKey} className="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium bg-[rgb(var(--color-accent))] text-white hover:bg-[rgb(var(--color-accent-hover))] transition-colors disabled:opacity-50" style={{ opacity: running || !url || !apiKey ? 0.5 : 1 }}><Plus className="w-4 h-4" />扫描</button>
<button onClick={scanRepo} disabled={running || !url} className="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium bg-[rgb(var(--color-accent))] text-white hover:bg-[rgb(var(--color-accent-hover))] transition-colors disabled:opacity-50" style={{ opacity: running || !url ? 0.5 : 1 }}><Plus className="w-4 h-4" />扫描</button>
</div>
</div>
@ -257,7 +254,6 @@ export default function ReposView() {
<button className="underline ml-1" onClick={() => setFeBranch(feLatestBranch)} style={{ color: 'rgb(var(--color-accent))' }}>切换</button>
</div>
)}
<input type="password" placeholder="API Key *必填" value={feApiKey} onChange={e => setFeApiKey(e.target.value)} className="w-48 px-3 py-2 rounded-lg text-sm outline-none" style={{ backgroundColor: 'rgb(var(--color-page))', borderColor: !feApiKey ? 'rgb(var(--color-error))' : 'rgb(var(--color-border))', borderWidth: !feApiKey ? '2px' : '1px', color: 'rgb(var(--color-text-primary))' }} />
<button onClick={async () => {
if (!feUrl) return
setFeRunning(true)
@ -265,7 +261,7 @@ export default function ReposView() {
setFeLogs([])
const res = await fetch('/api/repos/fix-ui', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: feUrl, branch: feBranch, api_key: feApiKey }),
body: JSON.stringify({ url: feUrl, branch: feBranch }),
})
const task = await res.json()
setFeTaskId(task.id)
@ -276,7 +272,7 @@ export default function ReposView() {
if (data.level !== 'PING') setFeLogs(prev => [...prev.slice(-200), data])
}
es.onerror = () => { setFeRunning(false); setFeActionLabel('') }
}} disabled={feRunning || !feUrl || !feApiKey} className="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium bg-[rgb(var(--color-accent-amber))] text-white hover:opacity-90 transition-colors disabled:opacity-50" style={{ opacity: feRunning || !feUrl || !feApiKey ? 0.5 : 1 }}>
}} disabled={feRunning || !feUrl} className="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium bg-[rgb(var(--color-accent-amber))] text-white hover:opacity-90 transition-colors disabled:opacity-50" style={{ opacity: feRunning || !feUrl ? 0.5 : 1 }}>
{feRunning ? <RefreshCw className="w-4 h-4 animate-spin" /> : <Wand2 className="w-4 h-4" />}
{feRunning ? feActionLabel : '检测并修复'}
</button>