// download-flags.ts — Lädt circle-flags SVGs für alle Teams aus TLA_TO_ISO2. // Ausführung: npx tsx scripts/download-flags.ts import { TLA_TO_ISO2 } from "../lib/flags"; import * as fs from "fs"; import * as path from "path"; const BASE = "https://hatscripts.github.io/circle-flags/flags"; const OUT = path.join(__dirname, "..", "public", "flags"); async function main() { const codes = Object.values(TLA_TO_ISO2); const unique = [...new Set(codes)]; console.log(`Lade ${unique.length} Flaggen (${codes.length} Team-Codes)...`); if (!fs.existsSync(OUT)) fs.mkdirSync(OUT, { recursive: true }); let ok = 0; let failed = 0; for (const iso2 of unique) { const url = `${BASE}/${iso2}.svg`; try { const res = await fetch(url, { headers: { "User-Agent": "circle-flags-download/1.0" }, }); if (!res.ok) { console.warn(` ❌ ${iso2}: HTTP ${res.status}`); failed++; continue; } const svg = await res.text(); // Prüfen: keine leere/Fehler-SVG (<10 Bytes = kaputt) if (svg.trim().length < 10) { console.warn(` ❌ ${iso2}: leere SVG (${svg.length} Bytes)`); failed++; continue; } fs.writeFileSync(path.join(OUT, `${iso2}.svg`), svg); ok++; } catch (err) { console.warn(` ❌ ${iso2}: ${err instanceof Error ? err.message : err}`); failed++; } } console.log(`\n✅ ${ok} OK, ❌ ${failed} fehlgeschlagen`); if (failed > 0) process.exit(1); } main();