feat: implement JSON backup export functionality with improved download handling
All checks were successful
Publish Container / publish (push) Successful in 3m25s

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Marco 2026-04-24 14:16:15 +02:00
commit bf333c4a00
7 changed files with 96 additions and 5 deletions

View file

@ -86,6 +86,39 @@ window.workTrackerPreferences = {
}
};
window.workTrackerDownloads = {
async downloadFromUrl(url) {
const response = await fetch(url, {
credentials: "same-origin"
});
if (!response.ok) {
throw new Error(`Download failed with status ${response.status}`);
}
const blob = await response.blob();
const contentDisposition = response.headers.get("content-disposition") || "";
const fileNameMatch = /filename\*=UTF-8''([^;]+)|filename="?([^";]+)"?/i.exec(contentDisposition);
const fileName = decodeURIComponent(fileNameMatch?.[1] || fileNameMatch?.[2] || "worktracker-backup.json");
const objectUrl = URL.createObjectURL(blob);
try {
const anchor = document.createElement("a");
anchor.href = objectUrl;
anchor.download = fileName;
anchor.rel = "noopener";
anchor.style.display = "none";
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
}
finally {
URL.revokeObjectURL(objectUrl);
}
}
};
window.workTrackerDateInput = (() => {
const listeners = new WeakMap();