feat(frontend): Export-Buttons fuer Voelker, Honigchargen (Modul 21)
CSV-Export in den Listen-Views (Voelker, Honigchargen) und PDF-Rueckverfolgbarkeitsbericht auf der Honigcharge-Detailseite. apiFetchBlob() im API-Client ergaenzt fuer authentifizierte Blob-Downloads (JWT im Authorization-Header statt Cookie).
This commit is contained in:
1 parent
c281d04b16
commit
ed108045af
6 files changed
+114
-9
No files matched your search
@@ -25,6 +25,39 @@ async function rawFetch(path: string, init: RequestInit): Promise<Response> {
|
||||
});
|
||||
}
|
||||
|
||||
export interface BlobDownload {
|
||||
blob: Blob;
|
||||
filename: string;
|
||||
}
|
||||
|
||||
function filenameFromContentDisposition(header: string | null, fallback: string): string {
|
||||
const match = header ? /filename="([^"]+)"/.exec(header) : null;
|
||||
return match?.[1] ?? fallback;
|
||||
}
|
||||
|
||||
export async function apiFetchBlob(path: string, fallbackFilename: string): Promise<BlobDownload> {
|
||||
let response = await rawFetch(path, {});
|
||||
|
||||
if (response.status === 401) {
|
||||
const refreshed = await refreshRequest();
|
||||
if (refreshed) {
|
||||
setAccessToken(refreshed.accessToken);
|
||||
response = await rawFetch(path, {});
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new ApiError(response.status, 'Export fehlgeschlagen');
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const filename = filenameFromContentDisposition(
|
||||
response.headers.get('Content-Disposition'),
|
||||
fallbackFilename,
|
||||
);
|
||||
return { blob, filename };
|
||||
}
|
||||
|
||||
export async function apiFetch<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
let response = await rawFetch(path, init);
|
||||
|
||||
|
||||
Reference in new issue
Block a user