File size: 1,220 Bytes
f91a684 3bda374 f91a684 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /**
* osClient.ts
* -----------
* Fetches Operating System topic data from the Go backend.
*/
const API_BASE = '';
export interface OSSection {
section_no: number;
section: string;
topic_count: number;
level: string;
}
export interface OSTopic {
id: string;
section: string;
topic: string;
type: string;
subtopic?: string;
content: Record<string, any>;
}
/**
* Fetches all OS sections (grouped, deduplicated list).
*/
export async function fetchOSSections(): Promise<OSSection[]> {
const res = await fetch(`${API_BASE}/api/os/sections`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
if (!res.ok) throw new Error(`OS sections fetch failed: ${res.status}`);
const data = await res.json();
return data.sections ?? [];
}
/**
* Fetches all topics for a given OS section number.
*/
export async function fetchOSSectionContent(sectionNo: number): Promise<{ section: string; topics: OSTopic[] }> {
const res = await fetch(`${API_BASE}/api/os/sections/${sectionNo}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
if (!res.ok) throw new Error(`OS section content fetch failed: ${res.status}`);
return res.json();
}
|