import type { APIRoute } from "astro"; import { readdir, readFile } from "node:fs/promises"; import { join } from "node:path"; const MAPS_ROOT = join(process.env.REPO_ROOT ?? "/Users/ace/palacering", "palaces", "manglasabang", "palaceappsdata", "palacetravel", "maps"); export const GET: APIRoute = async () => { try { const entries = await readdir(MAPS_ROOT, { withFileTypes: true }); const maps = []; for (const entry of entries) { if (!entry.isDirectory()) continue; try { const meta = await readFile(join(MAPS_ROOT, entry.name, "meta.json"), "utf-8"); maps.push({ id: entry.name, ...JSON.parse(meta) }); } catch { /* skip dirs without meta.json */ } } return new Response(JSON.stringify(maps), { headers: { "Content-Type": "application/json" }, }); } catch { return new Response("[]", { headers: { "Content-Type": "application/json" } }); } };