CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (push) Canceled after 0s
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
// Duenner Client fuer DOC-10s Backend-Voraussetzung
|
|
// (dms/internal/folderapi) — enthaelt keine eigene Baum-/Sortierlogik.
|
|
import { withCaller } from "./caller";
|
|
import { apiFetch } from "./http";
|
|
|
|
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<T>(path: string): Promise<T> {
|
|
const res = await apiFetch(`${apiBase()}${path}`);
|
|
if (!res.ok) {
|
|
throw new Error(`Anfrage fehlgeschlagen (${res.status})`);
|
|
}
|
|
return res.json();
|
|
}
|
|
|
|
export function fetchChildren(folderID: string | null): Promise<FolderDTO[]> {
|
|
return get(folderID ? `/folders/${encodeURIComponent(folderID)}/children` : "/folders/children");
|
|
}
|
|
|
|
export function fetchBreadcrumb(folderID: string): Promise<FolderDTO[]> {
|
|
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<DocumentDTO[]> {
|
|
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(withCaller(base + query));
|
|
}
|