// Public REST: whether the radio player should auto-play on load. Reads the // radio_auto_play website setting (the key the admin radio settings page // writes), falling back to the legacy radio_autoplay alias if present. Booleans // are stored as the strings '1' / '0'. Returns { autoplay: boolean }. import { apiJson } from "@/lib/api"; import { prisma } from "@/lib/prisma"; export const dynamic = "force-dynamic"; const AUTOPLAY_KEYS = ["radio_auto_play", "radio_autoplay"]; function truthy(value: string | undefined): boolean { if (value === undefined) return false; const s = value.trim().toLowerCase(); return s === "1" || s === "true"; } export async function GET(_req: Request) { try { const rows = await prisma.websiteSetting.findMany({ where: { key: { in: AUTOPLAY_KEYS } }, select: { key: true, value: true }, }); const map: Record = {}; for (const row of rows) { map[row.key] = row.value; } // Prefer the canonical key the settings page uses; fall back to the alias. const autoplay = truthy(map.radio_auto_play ?? map.radio_autoplay); return apiJson({ autoplay }); } catch { // DB unavailable — default to no autoplay rather than a 500. return apiJson({ autoplay: false }, { status: 200 }); } }