32 lines
718 B
TypeScript
32 lines
718 B
TypeScript
// data.js (API слой)
|
|
// Типы ответов от сервера
|
|
interface HealthResponse {
|
|
status: string;
|
|
uptime_sec: number;
|
|
last_data_ms: number;
|
|
pipe_alive: boolean;
|
|
has_data: boolean;
|
|
latest: number;
|
|
server_time?: string;
|
|
stats: {
|
|
filled: number;
|
|
bytes_per_sec: number;
|
|
};
|
|
}
|
|
|
|
interface HistoryResponse {
|
|
bytes: number[];
|
|
}
|
|
|
|
export async function fetchHealth(): Promise<HealthResponse> {
|
|
const r = await fetch("/api/health");
|
|
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
return r.json();
|
|
}
|
|
|
|
export async function fetchHistory(): Promise<HistoryResponse> {
|
|
const r = await fetch("/api/history");
|
|
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
return r.json();
|
|
}
|