import { Hono } from "hono"; import { listActiveAds, recordImpressions } from "../lib/ads"; const ads = new Hono(); // GET /api/ads?kind=band → active ad set for that slot (client rotates). ads.get("/", async (c) => { const kind = c.req.query("kind") === "casino" ? "casino" : "band"; const list = await listActiveAds(kind); // Expose only what the UI needs. return c.json( list.map((a) => ({ id: a.id, brand: a.brand, subtitle: a.subtitle, url: a.url, cta: a.cta, icon: a.icon, tone: a.tone, kind: a.kind, ownerIp: a.ownerIp, imageUrl: a.imageUrl, })) ); }); // POST /api/ads/impressions { ids: [...] } ads.post("/impressions", async (c) => { let body: { ids?: string[] } = {}; try { body = await c.req.json(); } catch { return c.json({ error: "JSON invalide" }, 400); } const ids = Array.isArray(body.ids) ? body.ids.filter((x) => typeof x === "string") : []; await recordImpressions(ids); return c.json({ ok: true, counted: ids.length }); }); export default ads;