fix: harden upload resilience and contracts
This commit is contained in:
+9
-1
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user