first commit

This commit is contained in:
Nathan FONTEYNE 2026-07-08 11:05:21 +02:00
commit 244cdbedd7
44 changed files with 3386 additions and 0 deletions

24
public/js/api.js Normal file
View file

@ -0,0 +1,24 @@
async function apiFetch(path, options = {}) {
const res = await fetch(path, {
headers: { 'Content-Type': 'application/json' },
...options,
});
if (res.status === 401) {
window.location.href = '/auth/login?returnTo=' + encodeURIComponent(window.location.pathname);
return new Promise(() => {});
}
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body.message || body.error || `Request failed: ${res.status}`);
}
if (res.status === 204) return null;
return res.json();
}
const api = {
get: (path) => apiFetch(path),
post: (path, data) => apiFetch(path, { method: 'POST', body: JSON.stringify(data) }),
patch: (path, data) => apiFetch(path, { method: 'PATCH', body: JSON.stringify(data) }),
put: (path, data) => apiFetch(path, { method: 'PUT', body: JSON.stringify(data) }),
del: (path) => apiFetch(path, { method: 'DELETE' }),
};