export type Folder = { path: string; recursive: boolean; file_count: number }; export type BrowseEntry = { name: string; is_dir: boolean }; export type BrowseResp = { path: string; parent: string | null; entries: BrowseEntry[] }; export async function listFolders(): Promise { const r = await fetch('/api/folders'); if (!r.ok) throw new Error(await r.text()); return r.json(); } export async function addFolder(path: string, recursive: boolean): Promise { const r = await fetch('/api/folders', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path, recursive }), }); if (!r.ok) throw new Error(await r.text()); return r.json(); } export async function removeFolder(path: string): Promise { const r = await fetch('/api/folders', { method: 'DELETE', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path }), }); if (!r.ok) throw new Error(await r.text()); } export async function refreshFolder(path: string): Promise<{ file_count: number }> { const r = await fetch('/api/folders/refresh', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path }), }); if (!r.ok) throw new Error(await r.text()); return r.json(); } export async function browse(path?: string): Promise { const u = path ? `/api/browse?path=${encodeURIComponent(path)}` : '/api/browse'; const r = await fetch(u); if (!r.ok) throw new Error(await r.text()); return r.json(); } export type FileMeta = { rel: string; size: number }; export type FilesResp = { folder: string; recursive: boolean; files: FileMeta[] }; export async function listFiles(folder: string): Promise { const r = await fetch(`/api/files?path=${encodeURIComponent(folder)}`); if (!r.ok) throw new Error(await r.text()); return r.json(); }