Files
projekt-plattform/viewer/src/lib/api.ts

34 lines
1.2 KiB
TypeScript

// Anbindung an den kleinen Server (server.mjs). Ersetzt die Tauri-Befehle `dev_roadmap` und `dev_klicktests` aus Kanonwerk.
export interface ProjectInfo { id: string; name: string; path: string }
/** Aktuell gewähltes Projekt (Index im Server); die App setzt es, bevor die Ansicht neu lädt */
export const session = { project: "0" };
async function get(path: string): Promise<Response> {
const r = await fetch(`/api/${path}${path.includes("?") ? "&" : "?"}project=${encodeURIComponent(session.project)}`, { cache: "no-store" });
return r;
}
export async function listProjects(): Promise<ProjectInfo[]> {
const r = await fetch("/api/projects", { cache: "no-store" });
if (!r.ok) throw new Error(await r.text());
return r.json();
}
export async function devRoadmap(): Promise<string> {
const r = await get("roadmap");
if (!r.ok) throw new Error(await r.text());
return r.text();
}
/** KLICKTESTS.md ist optional: fehlt sie, gibt es keinen Tests-Reiter */
export async function devKlicktests(): Promise<string> {
const r = await get("klicktests");
return r.ok ? r.text() : "";
}
export async function devReports(): Promise<{ file: string; text: string }[]> {
const r = await get("reports");
return r.ok ? r.json() : [];
}