This commit is contained in:
Team3
2026-09-27 21:36:33 +02:00
commit 498fe2220a
34 changed files with 3608 additions and 0 deletions

28
frontend/src/api.js Normal file
View File

@@ -0,0 +1,28 @@
async function req(pfad, opts = {}) {
const r = await fetch('/api' + pfad, {
headers: { 'content-type': 'application/json' },
...opts,
body: opts.body ? JSON.stringify(opts.body) : undefined,
})
if (!r.ok) {
let detail = r.statusText
try { detail = (await r.json()).detail || detail } catch { /* leer */ }
throw new Error(detail)
}
const ct = r.headers.get('content-type') || ''
return ct.includes('json') ? r.json() : r.text()
}
const e = encodeURIComponent
export const api = {
topics: () => req('/topics'),
anlegen: (name, hinweise = '') => req('/topics', { method: 'POST', body: { name, hinweise } }),
loeschen: (t) => req(`/topics/${e(t)}`, { method: 'DELETE' }),
start: (t) => req(`/topics/${e(t)}/start`, { method: 'POST' }),
pause: (t) => req(`/topics/${e(t)}/pause`, { method: 'POST' }),
reset: (t) => req(`/topics/${e(t)}/reset`, { method: 'POST' }),
state: (t) => req(`/topics/${e(t)}/state`),
guide: (t) => req(`/topics/${e(t)}/guide`),
guideMdUrl: (t) => `/api/topics/${e(t)}/guide.md`,
pdfUrl: (t) => `/api/topics/${e(t)}/buch.pdf`,
}