All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- HomeMessages : type pill (Réaction/Question/Suggestion/Retour) + sélecteur dans le formulaire (sans Réaction) - HomeMessages : white-space: pre-line sur les messages - Page /messages : type pill + white-space: pre-line (idem home) - Admin : badge type coloré + sélecteur d'édition + formulaire réponse - API : type et reply dans PUT ; readDataYaml/writeDataYaml (data/ volume Docker) - main.css : overrides light mode text-white/55, /75, /90 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
const EMPTY = { messages: [] as any[] }
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const id = Number(getRouterParam(event, 'id'))
|
|
|
|
if (!id || isNaN(id)) {
|
|
throw createError({ statusCode: 400, statusMessage: 'ID invalide' })
|
|
}
|
|
|
|
const body = await readBody<{
|
|
text?: string
|
|
published?: boolean
|
|
author?: string
|
|
type?: string
|
|
reply?: string | null
|
|
}>(event)
|
|
|
|
const data = await readDataYaml<{ messages: any[] }>('messages.yml', EMPTY)
|
|
|
|
const message = data.messages.find(m => m.id === id)
|
|
if (!message) {
|
|
throw createError({ statusCode: 404, statusMessage: 'Message non trouvé' })
|
|
}
|
|
|
|
if (body.text !== undefined) message.text = body.text
|
|
if (body.published !== undefined) message.published = body.published
|
|
if (body.author !== undefined) message.author = body.author
|
|
if (body.type !== undefined) message.type = body.type
|
|
if ('reply' in body) {
|
|
message.reply = body.reply
|
|
? { text: body.reply, publishedAt: new Date().toISOString() }
|
|
: null
|
|
}
|
|
|
|
await writeDataYaml('messages.yml', data)
|
|
|
|
return { ok: true }
|
|
})
|