TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1"use client";2import { ClientApiError } from "@/lib/client/api";34/** POST /api/arena/:id/export?format= and save the file through a temporary object URL. */5export async function downloadArenaExport(sessionId: string, format: "markdown" | "json"): Promise<string> {6 const res = await fetch(`/api/arena/${encodeURIComponent(sessionId)}/export?format=${format}`, { method: "POST", credentials: "same-origin" });7 if (!res.ok) {8 let err: { error?: { code?: string; message?: string } } = {};9 try {10 err = await res.json();11 } catch {12 /* ignore */13 }14 throw new ClientApiError(res.status, err.error?.code ?? "HTTP_ERROR", err.error?.message ?? `Export failed (${res.status})`);15 }16 const blob = await res.blob();17 const cd = res.headers.get("Content-Disposition") ?? "";18 const filename = res.headers.get("X-Filename") ?? /filename="([^"]+)"/.exec(cd)?.[1] ?? `arena.${format === "json" ? "json" : "md"}`;19 const url = URL.createObjectURL(blob);20 const a = document.createElement("a");21 a.href = url;22 a.download = filename;23 document.body.appendChild(a);24 a.click();25 a.remove();26 setTimeout(() => URL.revokeObjectURL(url), 2000);27 return filename;28}29