This commit is contained in:
parent
4d0a0bd7b0
commit
d40666b878
6 changed files with 565 additions and 2 deletions
56
server/api/policies.ts
Normal file
56
server/api/policies.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
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
|
||||
}
|
||||
})
|
||||
Loading…
Reference in a new issue