OPC # 0001: Extract OPC into standalone repo
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
const BASE_URL = import.meta.env.VITE_API_URL ?? '';
|
||||
|
||||
export type ServiceStatus = 'running' | 'stopped' | 'unhealthy' | 'unknown';
|
||||
|
||||
export interface InfraService {
|
||||
name: string;
|
||||
container: string;
|
||||
status: ServiceStatus;
|
||||
ports: string[];
|
||||
uptime?: string;
|
||||
}
|
||||
|
||||
export interface InfraStatusResponse {
|
||||
services: InfraService[];
|
||||
checkedAt: string;
|
||||
}
|
||||
|
||||
export async function getInfraStatus(): Promise<InfraStatusResponse> {
|
||||
const res = await fetch(`${BASE_URL}/api/infra/status`);
|
||||
if (!res.ok) throw new Error('Failed to fetch infra status');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function infraServiceAction(
|
||||
service: string,
|
||||
action: 'start' | 'stop' | 'restart'
|
||||
): Promise<void> {
|
||||
const res = await fetch(`${BASE_URL}/api/infra/${service}/${action}`, { method: 'POST' });
|
||||
if (!res.ok) throw new Error(`Failed to ${action} ${service}`);
|
||||
}
|
||||
|
||||
export function streamComposeUp(onLine: (line: string) => void, onDone: () => void): EventSource {
|
||||
const src = new EventSource(`${BASE_URL}/api/infra/compose/up/stream`);
|
||||
src.onmessage = (e) => onLine(e.data);
|
||||
src.onerror = () => { onDone(); src.close(); };
|
||||
return src;
|
||||
}
|
||||
|
||||
export function streamComposeDown(onLine: (line: string) => void, onDone: () => void): EventSource {
|
||||
const src = new EventSource(`${BASE_URL}/api/infra/compose/down/stream`);
|
||||
src.onmessage = (e) => onLine(e.data);
|
||||
src.onerror = () => { onDone(); src.close(); };
|
||||
return src;
|
||||
}
|
||||
Reference in New Issue
Block a user