Files
buchwerk/frontend/src/api.js
T
team3andClaude Fable 5.1 e06be9d50a Stopp nach der Gliederung als Häkchen neben „Buch erzeugen“
Das Häkchen steht im Lauf neben dem Startknopf und bei „Neue Version“
neben „Buch erzeugen“, nicht mehr im Anlegen-Formular. Es wird mit dem
Start gespeichert und ist sichtbar, solange die Gliederung aussteht.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-12 16:02:57 +02:00

36 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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()
}
// Pfade: /api/themen/<slug>/v<N>/… – die Version ist immer Teil der Adresse
const e = encodeURIComponent
const v = (slug, n) => `/themen/${e(slug)}/v${n}`
export const api = {
themen: () => req('/themen'),
anlegen: (name, hinweise = '', spezialisierung = '') => req('/themen', { method: 'POST', body: { name, hinweise, spezialisierung } }),
loeschen: (slug) => req(`/themen/${e(slug)}`, { method: 'DELETE' }),
versionAnlegen: (slug, eingaben) => req(`/themen/${e(slug)}/versionen`, { method: 'POST', body: eingaben }),
versionLoeschen: (slug, n) => req(v(slug, n), { method: 'DELETE' }),
state: (slug, n) => req(v(slug, n)),
start: (slug, n, body) => req(v(slug, n) + '/start', { method: 'POST', body }),
pause: (slug, n) => req(v(slug, n) + '/pause', { method: 'POST' }),
reset: (slug, n) => req(v(slug, n) + '/reset', { method: 'POST' }),
buch: (slug, n) => req(v(slug, n) + '/buch'),
position: (slug, n) => req(v(slug, n) + '/position'),
positionSetzen: (slug, n, daten) => req(v(slug, n) + '/position', { method: 'PUT', body: daten }),
buchMdUrl: (slug, n) => '/api' + v(slug, n) + '/buch.md',
pdfUrl: (slug, n) => '/api' + v(slug, n) + '/buch.pdf',
kernUrl: (slug, n) => '/api' + v(slug, n) + '/kern.md',
}