refactor: clean upload pipeline and restore draco delivery

This commit is contained in:
Tom Boullay
2026-04-29 16:29:32 +02:00
parent 097b8f6486
commit 498765db61
32 changed files with 769 additions and 215 deletions
+9 -2
View File
@@ -3,11 +3,17 @@ import { NextRequest } from 'next/server'
import { sanitizeFilename } from './sanitize'
import { ALL_ALLOWED_EXTENSIONS, MODEL_EXTENSIONS, MAX_FILE_SIZE, TEXTURE_EXTENSIONS } from './constants'
import { getTextureNamingError } from './asset-naming'
import type { ParsedFile } from './types'
import type { GitModelMode, ParsedFile } from './types'
interface ParsedUpload {
folderName: string
files: ParsedFile[]
gitModelMode: GitModelMode
}
function parseGitModelMode(value: FormDataEntryValue | null): GitModelMode {
if (value === 'draco-glb' || value === 'keep-gltf') return value
throw new Error('Mode Git invalide')
}
export async function parseMultiUpload(req: NextRequest): Promise<ParsedUpload> {
@@ -15,6 +21,7 @@ export async function parseMultiUpload(req: NextRequest): Promise<ParsedUpload>
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 gitModelMode = parseGitModelMode(formData.get('gitModelMode'))
const rawFiles = formData.getAll('files')
const fileTypes = formData.getAll('fileTypes').filter((value): value is string => typeof value === 'string')
@@ -95,5 +102,5 @@ export async function parseMultiUpload(req: NextRequest): Promise<ParsedUpload>
throw new Error('Un seul fichier model.gltf est autorise')
}
return { folderName: safeFolderName, files: parsed }
return { folderName: safeFolderName, files: parsed, gitModelMode }
}