Stundenliste fürs Steuerbüro als CSV (0.10.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
@@ -35,6 +35,28 @@ export async function api<T = any>(pfad: string, methode = "GET", body?: unknown
|
||||
return j as T;
|
||||
}
|
||||
|
||||
/** Eine Datei vom Server holen und speichern lassen (Testversion: über das Speichern der Artifact-Seite). Gibt eine Meldung zurück. */
|
||||
export async function dateiSpeichern(pfad: string, dateiname: string): Promise<string> {
|
||||
const kopf: Record<string, string> = {};
|
||||
const test = lies(TEST_BENUTZER);
|
||||
if (test) kopf["x-test-benutzer"] = test;
|
||||
const r = await fetch(`/api/${pfad}`, { headers: kopf });
|
||||
if (!r.ok) {
|
||||
const j = await r.json().catch(() => ({}));
|
||||
throw new Error(j.fehler ?? `Fehler ${r.status}`);
|
||||
}
|
||||
const tv = (globalThis as { betriebTestversion?: { datei?(name: string, text: string): Promise<string> } }).betriebTestversion;
|
||||
// ignoreBOM: das BOM am Anfang muss mit, sonst zeigt Excel die Umlaute falsch
|
||||
if (tv?.datei) return tv.datei(dateiname, new TextDecoder("utf-8", { ignoreBOM: true }).decode(await r.arrayBuffer()));
|
||||
const url = URL.createObjectURL(await r.blob());
|
||||
const a = Object.assign(document.createElement("a"), { href: url, download: dateiname });
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 10000);
|
||||
return "";
|
||||
}
|
||||
|
||||
export const inhalt = document.getElementById("inhalt")!;
|
||||
export const huelle = document.getElementById("dialog-huelle")!;
|
||||
export const heute = () => new Date().toISOString().slice(0, 10);
|
||||
|
||||
Reference in New Issue
Block a user