feat: connect guarded asset import api

This commit is contained in:
simoleo89
2026-07-12 19:12:25 +02:00
parent 3497df9dfd
commit eb759f54bf
26 changed files with 2342 additions and 24 deletions
@@ -0,0 +1,28 @@
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<string, string> = 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)
}
})