website/server/api/policies.ts
kittentm d40666b878
Some checks failed
ci / ci (22, debian-trixie) (push) Failing after 33s
?
2026-07-20 22:46:51 +02:00

56 lines
1.5 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
export default defineEventHandler(async () => {
const gameRulesDir = path.resolve(process.cwd(), 'public/policy/game-rules')
const baseRules = [
{ id: 'general', name: 'General Rules' },
{ id: 'conduct', name: 'Code of Conduct' },
{ id: 'privacy', name: 'Privacy Policy' }
]
const games: Array<{ id: string, name: string, version: string }> = []
try {
if (fs.existsSync(gameRulesDir)) {
const folders = await fs.promises.readdir(gameRulesDir)
for (const folder of folders) {
const folderPath = path.join(gameRulesDir, folder)
if (!folderPath.startsWith(gameRulesDir)) {
continue
}
const stat = await fs.promises.stat(folderPath)
if (stat.isDirectory()) {
const metadataPath = path.join(folderPath, 'metadata.json')
if (fs.existsSync(metadataPath)) {
try {
const metaContent = await fs.promises.readFile(metadataPath, 'utf-8')
const parsedMeta = JSON.parse(metaContent)
games.push({
id: folder,
name: parsedMeta.name || folder,
version: parsedMeta.version || '1.0.0'
})
} catch (jsonError) {
console.error(`Malformed metadata.json in ${folder}:`, jsonError)
}
}
}
}
}
} catch (error) {
console.error('Error scanning public policy tree:', error)
}
return {
baseRules,
games
}
})