import { promises as fs } from "node:fs"; import path from "node:path"; import { withAdmin } from "@/lib/api-handler"; import { apiError, apiOk } from "@/lib/api-response"; import { PERMS } from "@/lib/permissions"; const EXTERNAL_TEXTS_PATH = path.join(process.cwd(), "public/nitro-assets/gamedata/ExternalTexts.json"); /** GET - Read badge name/desc from ExternalTexts.json */ export const GET = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request) => { const code = request.nextUrl.searchParams.get("code")?.toUpperCase(); if (!code) return apiError("Missing code", 400); try { const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, "utf-8"); const texts: Record = JSON.parse(raw); const name = texts[`badge_name_${code}`] ?? texts[`${code}_badge_name`] ?? ""; const desc = texts[`badge_desc_${code}`] ?? texts[`${code}_badge_desc`] ?? ""; return apiOk({ name, desc }); } catch { return apiError("Failed to read ExternalTexts.json", 500); } });