All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Bouton PDF blanc par chapitre avec numéro de page (ChapterHeader) - Badges morceaux plus visibles (bordure, poids, hover) dans ChapterHeader et SongBadges - PDF viewer : page cible + panneau signets ouverts par défaut (BookPdfReader) - Config YAML : pdfFile dans book, chapterPages pour le mapping chapitre→page - Admin book : section PDF du livre avec chemin éditable et sauvegarde - Git sync automatique : chaque sauvegarde admin commit+push en prod (ADMIN_GIT_SYNC=true) - Docker : git installé en prod, volumes pour .git/site/content/public Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { writeFile, mkdir } from 'node:fs/promises'
|
|
import { join, dirname } from 'node:path'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const formData = await readMultipartFormData(event)
|
|
|
|
if (!formData || formData.length === 0) {
|
|
throw createError({ statusCode: 400, statusMessage: 'No files provided' })
|
|
}
|
|
|
|
const publicDir = join(process.cwd(), 'public')
|
|
const uploaded: string[] = []
|
|
|
|
for (const file of formData) {
|
|
if (!file.filename || !file.data) continue
|
|
|
|
// Sanitize filename
|
|
const safeName = file.filename.replace(/[^a-zA-Z0-9._-]/g, '_')
|
|
|
|
// Determine subdirectory from content type
|
|
let subdir = 'uploads'
|
|
const type = file.type ?? ''
|
|
if (type.startsWith('image/')) subdir = 'images'
|
|
else if (type.startsWith('audio/')) subdir = 'audio'
|
|
else if (type === 'application/pdf') subdir = 'pdf'
|
|
|
|
const targetDir = join(publicDir, subdir)
|
|
await mkdir(targetDir, { recursive: true })
|
|
|
|
const targetPath = join(targetDir, safeName)
|
|
await writeFile(targetPath, file.data)
|
|
|
|
uploaded.push(`/${subdir}/${safeName}`)
|
|
}
|
|
|
|
if (uploaded.length > 0) {
|
|
gitSyncContent(`Upload média : ${uploaded.join(', ')}`, uploaded.map(f => `public${f}`))
|
|
}
|
|
|
|
return { ok: true, files: uploaded }
|
|
})
|