fix: harden upload resilience and contracts

This commit is contained in:
Tom Boullay
2026-05-12 23:49:30 +02:00
parent 101af23418
commit 606df93b69
19 changed files with 479 additions and 159 deletions
+9 -1
View File
@@ -19,8 +19,16 @@ function parseGitModelMode(value: FormDataEntryValue | null): GitModelMode {
export async function parseMultiUpload(req: NextRequest): Promise<ParsedUpload> {
const formData = await req.formData()
const folderValue = formData.get('folderName')
const folderName = typeof folderValue === 'string' ? folderValue.trim() || 'assets' : 'assets'
if (typeof folderValue !== 'string' || folderValue.trim() === '') {
throw new Error('Nom de dossier manquant')
}
const folderName = folderValue.trim()
const safeFolderName = sanitizeFilename(folderName).replace(/[^a-zA-Z0-9-_]/g, '-')
if (!safeFolderName) {
throw new Error('Nom de dossier invalide')
}
const gitModelMode = parseGitModelMode(formData.get('gitModelMode'))
const rawFiles = formData.getAll('files')