Notes are saved as markdown pages in a Nextcloud collective via the Collectives OCS API (page metadata/creation) and WebDAV (content read/append), following the same npm-workspaces + session-auth architecture as CityTracker. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NvmYFQSMqs2N3q2zUDNTVn
20 lines
489 B
TypeScript
20 lines
489 B
TypeScript
export async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
|
|
const res = await fetch(path, {
|
|
...init,
|
|
credentials: "include",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
...init?.headers
|
|
}
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const body = await res.json().catch(() => ({}));
|
|
throw new Error(body.error ?? `Request failed (${res.status})`);
|
|
}
|
|
|
|
if (res.status === 204) {
|
|
return undefined as T;
|
|
}
|
|
return (await res.json()) as T;
|
|
}
|