Steuere das Herunterladen von Originalen je Rolle, benenne Dateien richtig und zeige HTML-Mails gesichert im Sandbox-Rahmen.
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 5m35s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 22s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
StommerandClaude Sonnet 5.5 committed 2026-10-22 14:22:35 +02:00
1 parent 0a5daf6713
commit 075525ee17
26 files changed
+494 -71

No files matched your search

+34 -24
View File
@@ -92,18 +92,48 @@ export async function fetchMailPart(elementId, context, suffix) {
return response.blob();
}
export async function downloadMailPart(elementId, context, suffix, filename) {
const blob = await fetchMailPart(elementId, context, suffix);
// The name the server gave the file (RFC 5987 form first), so a saved file keeps its real name.
export function nameFromDisposition(header, fallback) {
const text = header || "";
const star = /filename\*\s*=\s*UTF-8''([^;]+)/i.exec(text);
if (star) {
try {
return decodeURIComponent(star[1].trim());
} catch {
/* fall through to the plain name */
}
}
const plain = /filename\s*=\s*"([^"]+)"/i.exec(text) || /filename\s*=\s*([^;]+)/i.exec(text);
return plain ? plain[1].trim() : fallback;
}
export function saveBlob(blob, filename) {
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename || "nachricht.eml";
link.download = filename;
document.body.appendChild(link);
link.click();
link.remove();
setTimeout(() => URL.revokeObjectURL(url), 60000);
}
// Saves a document to the device. The server checks the download right of the role.
export async function saveDocument(path, context, fallbackName) {
const params = mailQuery(context);
params.set("save", "true");
const response = await fetch(`${path}?${params}`, { credentials: "include", headers: scopeHeaders() });
if (!response.ok) {
const data = await response.json().catch(() => null);
throw new Error(data?.detail || "Die Datei ist nicht verfügbar.");
}
saveBlob(await response.blob(), nameFromDisposition(response.headers.get("Content-Disposition"), fallbackName));
}
export async function downloadMailPart(elementId, context, suffix, filename) {
await saveDocument(`/api/v1/external-refs/${elementId}/mail/${suffix}`, context, filename || "nachricht.eml");
}
export async function fetchExternal(elementId, context) {
const params = new URLSearchParams();
if (context?.kind && context?.id) {
@@ -140,27 +170,7 @@ export async function fetchFile(elementId, context) {
}
export async function downloadFile(elementId, context, filename) {
const params = new URLSearchParams();
if (context?.kind && context?.id) {
params.set("context_kind", context.kind);
params.set("context_id", context.id);
}
const response = await fetch(`/api/v1/files/${elementId}/content?${params}`, {
credentials: "include",
headers: scopeHeaders(),
});
if (!response.ok) {
throw new Error("Die Datei ist nicht verfügbar.");
}
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename || "datei";
document.body.appendChild(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
await saveDocument(`/api/v1/files/${elementId}/content`, context, filename || "datei");
}
export async function fetchBlob(path) {