Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten - Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt, Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat, Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie, Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten, Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern - Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf, Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigabe anfordern - Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst - Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen - Bereich „Redaktion“, Benachrichtigungen im Portal - storage/.migrations-fingerprint nicht mehr ausliefern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
/**
|
|
* JSON-Anfragen an das Portal (außerhalb von Inertia-Seitenwechseln), mit
|
|
* CSRF-Schutz über das XSRF-TOKEN-Cookie von Laravel.
|
|
*/
|
|
function xsrfToken() {
|
|
const match = document.cookie.match(/(?:^|; )XSRF-TOKEN=([^;]*)/);
|
|
|
|
return match ? decodeURIComponent(match[1]) : '';
|
|
}
|
|
|
|
export class HttpError extends Error {
|
|
constructor(status, data) {
|
|
super(data?.message || `Anfrage fehlgeschlagen (${status})`);
|
|
this.status = status;
|
|
this.data = data ?? {};
|
|
}
|
|
|
|
/** Erste Fehlermeldung je Feld aus einer 422-Antwort. */
|
|
get fieldErrors() {
|
|
return Object.fromEntries(Object.entries(this.data.errors ?? {}).map(([key, messages]) => [key, messages[0]]));
|
|
}
|
|
}
|
|
|
|
export async function request(method, url, body, options = {}) {
|
|
const headers = {
|
|
Accept: 'application/json',
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
'X-XSRF-TOKEN': xsrfToken(),
|
|
};
|
|
|
|
let payload = body;
|
|
|
|
if (body !== undefined && !(body instanceof FormData)) {
|
|
headers['Content-Type'] = 'application/json';
|
|
payload = JSON.stringify(body);
|
|
}
|
|
|
|
const response = await fetch(url, { method, headers, body: payload, credentials: 'same-origin', keepalive: options.keepalive ?? false });
|
|
const data = response.headers.get('content-type')?.includes('application/json') ? await response.json() : null;
|
|
|
|
if (!response.ok) {
|
|
throw new HttpError(response.status, data);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
export const http = {
|
|
get: (url) => request('GET', url),
|
|
post: (url, body, options) => request('POST', url, body ?? {}, options),
|
|
put: (url, body) => request('PUT', url, body),
|
|
delete: (url, body) => request('DELETE', url, body),
|
|
};
|