website/server/api/policies.ts
kittentm 5ccb1fb7d1
All checks were successful
ci / ci (22, debian-trixie) (push) Successful in 28s
add service agreement
2026-07-24 20:56:01 +02:00

57 lines
1.6 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' },
{ id: 'service', name: 'Network Service Agreement' }
]
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
}
})