- system.ts: extract streamOperation helper; add streamSystemReset export - SecurityCenterView: replace single update button with update/reset descriptions table; shared dialog driven by operationType ref Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
53 行
1.5 KiB
TypeScript
53 行
1.5 KiB
TypeScript
const BASE = import.meta.env.VITE_API_BASE_URL ?? '/api'
|
|
|
|
export interface DeploymentStatus {
|
|
mode: 'PUBLIC' | 'PRIVATE'
|
|
tenantRegisterEnabled: boolean
|
|
services: Record<string, { enabled: boolean; baseUrl: string | null }>
|
|
}
|
|
|
|
export async function getDeploymentStatus(): Promise<DeploymentStatus> {
|
|
const res = await fetch(`${BASE}/private/deployment/status`)
|
|
const json = await res.json()
|
|
return json.data as DeploymentStatus
|
|
}
|
|
|
|
async function streamOperation(
|
|
path: string,
|
|
onLine: (line: string) => void,
|
|
signal?: AbortSignal,
|
|
): Promise<void> {
|
|
const token = localStorage.getItem('token') ?? ''
|
|
const res = await fetch(`${BASE}${path}`, {
|
|
method: 'POST',
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
signal,
|
|
})
|
|
if (!res.ok) {
|
|
const text = await res.text()
|
|
throw new Error(text || `HTTP ${res.status}`)
|
|
}
|
|
const reader = res.body!.getReader()
|
|
const decoder = new TextDecoder()
|
|
let buf = ''
|
|
while (true) {
|
|
const { done, value } = await reader.read()
|
|
if (done) break
|
|
buf += decoder.decode(value, { stream: true })
|
|
const lines = buf.split('\n')
|
|
buf = lines.pop() ?? ''
|
|
for (const line of lines) {
|
|
onLine(line)
|
|
}
|
|
}
|
|
if (buf) onLine(buf)
|
|
}
|
|
|
|
export function streamSystemUpdate(onLine: (line: string) => void, signal?: AbortSignal) {
|
|
return streamOperation('/system/update', onLine, signal)
|
|
}
|
|
|
|
export function streamSystemReset(onLine: (line: string) => void, signal?: AbortSignal) {
|
|
return streamOperation('/system/reset', onLine, signal)
|
|
}
|