initiation librodrome

This commit is contained in:
Yvv
2026-02-20 12:55:10 +01:00
commit 35e2897a73
208 changed files with 18951 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
export default defineEventHandler(async () => {
const data = await readYaml<{ messages: any[] }>('messages.yml')
const published = data.messages
.filter(m => m.published)
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
return published
})

View File

@@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const body = await readBody<{ author: string; email?: string; text: string }>(event)
if (!body.author?.trim() || !body.text?.trim()) {
throw createError({ statusCode: 400, statusMessage: 'Nom et message requis' })
}
const data = await readYaml<{ messages: any[] }>('messages.yml')
const maxId = data.messages.reduce((max, m) => Math.max(max, m.id || 0), 0)
data.messages.push({
id: maxId + 1,
author: body.author.trim(),
email: body.email?.trim() || '',
text: body.text.trim(),
published: false,
createdAt: new Date().toISOString(),
})
await writeYaml('messages.yml', data)
return { ok: true }
})