MCPcopy Create free account
hub / github.com/Donnadieu/Epstein-File-Explorer / triggerDownload

Function triggerDownload

client/src/components/export-button.tsx:17–30  ·  view source on GitHub ↗
(endpoint: string, format: "csv" | "json", filename: string)

Source from the content-addressed store, hash-verified

15}
16
17async function triggerDownload(endpoint: string, format: "csv" | "json", filename: string) {
18 const separator = endpoint.includes("?") ? "&" : "?";
19 const url = `${endpoint}${separator}format=${format}`;
20 const res = await fetch(url);
21 if (!res.ok) throw new Error("Export failed");
22 const blob = await res.blob();
23 const a = document.createElement("a");
24 a.href = URL.createObjectURL(blob);
25 a.download = `${filename}.${format}`;
26 document.body.appendChild(a);
27 a.click();
28 a.remove();
29 URL.revokeObjectURL(a.href);
30}
31
32export function ExportButton({ endpoint, filename, label = "Export" }: ExportButtonProps) {
33 const [isExporting, setIsExporting] = useState(false);

Callers 1

handleExportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected