2026-05-21 14:47:10 +08:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 15:33:35 +08:00
|
|
|
async function streamOperation(
|
|
|
|
|
path: string,
|
2026-05-21 14:47:10 +08:00
|
|
|
onLine: (line: string) => void,
|
|
|
|
|
signal?: AbortSignal,
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
const token = localStorage.getItem('token') ?? ''
|
2026-05-22 15:33:35 +08:00
|
|
|
const res = await fetch(`${BASE}${path}`, {
|
2026-05-21 14:47:10 +08:00
|
|
|
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)
|
|
|
|
|
}
|
2026-05-22 15:33:35 +08:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|