// Duenner Client fuer DOC-10s Backend-Voraussetzung // (dms/internal/folderapi) — enthaelt keine eigene Baum-/Sortierlogik. function apiBase(): string { const base = process.env.NEXT_PUBLIC_FOLDER_API_URL; if (!base) { throw new Error("NEXT_PUBLIC_FOLDER_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)"); } return base; } export interface FolderDTO { id: string; parent_folder_id: string | null; name: string; } export interface DocumentDTO { id: string; title: string; size_bytes: number | null; created_at: string; } async function get(path: string): Promise { const res = await fetch(`${apiBase()}${path}`); if (!res.ok) { throw new Error(`Anfrage fehlgeschlagen (${res.status})`); } return res.json(); } export function fetchChildren(folderID: string | null): Promise { return get(folderID ? `/folders/${encodeURIComponent(folderID)}/children` : "/folders/children"); } export function fetchBreadcrumb(folderID: string): Promise { return get(`/folders/${encodeURIComponent(folderID)}/breadcrumb`); } export interface DocumentSort { sort?: "title" | "created_at" | "size"; order?: "asc" | "desc"; } export function fetchDocuments(folderID: string | null, sort?: DocumentSort): Promise { const params = new URLSearchParams(); if (sort?.sort) params.set("sort", sort.sort); if (sort?.order) params.set("order", sort.order); const query = params.toString() ? `?${params.toString()}` : ""; const base = folderID ? `/folders/${encodeURIComponent(folderID)}/documents` : "/folders/documents"; return get(base + query); }