refactor: strengthen upload boundary types
This commit is contained in:
+4
-3
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user