(mode)
| 2423 | } |
| 2424 | |
| 2425 | async function exportAllIconsViaServer(mode) { |
| 2426 | const label = mode === "tft_rgb565" ? "TFT RGB565" : "U8g2 XBM"; |
| 2427 | setIconHint(`Exporting ${label} (server)…`); |
| 2428 | const payload = { |
| 2429 | mode, |
| 2430 | bg_color: mode === "tft_rgb565" ? bgColor : "#000000", |
| 2431 | icons: FILE_ICONS.map((ic) => ({ file: ic.file })), |
| 2432 | }; |
| 2433 | const res = await fetch(new URL("/api/icons/export", window.location.origin), { |
| 2434 | method: "POST", |
| 2435 | headers: { "Content-Type": "application/json" }, |
| 2436 | body: JSON.stringify(payload), |
| 2437 | }); |
| 2438 | let data = {}; |
| 2439 | try { |
| 2440 | data = await res.json(); |
| 2441 | } catch (_) { |
| 2442 | /* ignore */ |
| 2443 | } |
| 2444 | if (!res.ok) { |
| 2445 | const msg = |
| 2446 | typeof data.detail === "string" |
| 2447 | ? data.detail |
| 2448 | : Array.isArray(data.detail) |
| 2449 | ? data.detail.map((d) => (d && (d.msg || d.message)) || "").join(" ") |
| 2450 | : res.statusText || `HTTP ${res.status}`; |
| 2451 | throw new Error(msg || "Server error"); |
| 2452 | } |
| 2453 | if (!data.ok || typeof data.content !== "string") { |
| 2454 | throw new Error("Invalid server response."); |
| 2455 | } |
| 2456 | downloadText(data.filename, data.content); |
| 2457 | setIconHint("Exported (server): " + (data.filename || "")); |
| 2458 | } |
| 2459 | |
| 2460 | async function exportAllIconsTftRgb565Client() { |
| 2461 | setIconHint("Exporting TFT RGB565…"); |
no test coverage detected