refactor: strengthen upload boundary types

This commit is contained in:
Tom Boullay
2026-04-27 17:21:44 +02:00
parent d049318a73
commit fd586f4185
7 changed files with 96 additions and 39 deletions
+4 -3
View File
@@ -19,12 +19,13 @@ export interface ParsedUpload {
*/
export async function parseMultiUpload(req: NextRequest): Promise<ParsedUpload> {
const formData = await req.formData()
const folderName = (formData.get('folderName') as string | null)?.trim() || 'assets'
const folderValue = formData.get('folderName')
const folderName = typeof folderValue === 'string' ? folderValue.trim() || 'assets' : 'assets'
const safeFolderName = sanitizeFilename(folderName).replace(/[^a-zA-Z0-9-_]/g, '-')
const rawFiles = formData.getAll('files')
const fileTypes = formData.getAll('fileTypes') as string[]
const textureNames = formData.getAll('textureNames') as string[]
const fileTypes = formData.getAll('fileTypes').filter((value): value is string => typeof value === 'string')
const textureNames = formData.getAll('textureNames').filter((value): value is string => typeof value === 'string')
// Collect extra string fields
const knownKeys = new Set(['folderName', 'files', 'fileTypes', 'textureNames'])