feature/image-reveal #10
1 changed files with 3 additions and 1 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
// CRUD des questions manuelles écrites en base (source 'manual').
|
// CRUD des questions manuelles écrites en base (source 'manual').
|
||||||
|
|
||||||
import { randomUUID } from "node:crypto"
|
import { randomUUID } from "node:crypto"
|
||||||
import { writeFile } from "node:fs/promises"
|
import { mkdir, writeFile } from "node:fs/promises"
|
||||||
import { extname, resolve } from "node:path"
|
import { extname, resolve } from "node:path"
|
||||||
import type { FastifyInstance } from "fastify"
|
import type { FastifyInstance } from "fastify"
|
||||||
import { desc, eq } from "drizzle-orm"
|
import { desc, eq } from "drizzle-orm"
|
||||||
|
|
@ -109,6 +109,8 @@ export async function adminRoutes(app: FastifyInstance) {
|
||||||
const safeExt = IMAGE_EXT.includes(ext) ? ext : ".jpg"
|
const safeExt = IMAGE_EXT.includes(ext) ? ext : ".jpg"
|
||||||
const name = `${randomUUID()}${safeExt}`
|
const name = `${randomUUID()}${safeExt}`
|
||||||
const buffer = await file.toBuffer()
|
const buffer = await file.toBuffer()
|
||||||
|
// Crée le dossier si besoin (résilient s'il a été supprimé après le démarrage).
|
||||||
|
await mkdir(resolve(env.uploadsDir), { recursive: true })
|
||||||
await writeFile(resolve(env.uploadsDir, name), buffer)
|
await writeFile(resolve(env.uploadsDir, name), buffer)
|
||||||
return { url: `/uploads/${name}` }
|
return { url: `/uploads/${name}` }
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue