refactor: simplify upload rules and remove destination flow

This commit is contained in:
Tom Boullay
2026-04-24 16:23:02 +02:00
parent 61a0146545
commit 944959fc22
20 changed files with 2033 additions and 217 deletions
+9 -21
View File
@@ -2,17 +2,11 @@
// Client-side folder validation
// ---------------------------------------------------------------------------
import { REQUIRED_TEXTURES, TEXTURE_EXTENSIONS } from '@/lib/constants'
import { TEXTURE_EXTENSIONS } from '@/lib/constants'
import type { TextureFile } from '@/lib/client-types'
const TEXTURE_EXT_ARRAY = [...TEXTURE_EXTENSIONS]
function getTextureType(filename: string): string | null {
const name = filename.toLowerCase().replace(/\.[^.]+$/, '')
if ((REQUIRED_TEXTURES as readonly string[]).includes(name)) return name
return null
}
/** Discriminated union: either valid (with model) or invalid (with errors). */
export type ValidationResult =
| { ok: true; model: File; textures: TextureFile[]; warnings: string[] }
@@ -20,39 +14,33 @@ export type ValidationResult =
export function validateFolder(files: File[]): ValidationResult {
const textures: TextureFile[] = []
const warnings: string[] = []
const errors: string[] = []
const modelFiles = files.filter((f) => {
const name = f.name.toLowerCase()
return name === 'model.glb' || name === 'model.gltf'
return name === 'model.glb'
})
if (modelFiles.length === 0) {
return { ok: false, errors: ['model.glb ou model.gltf manquant (obligatoire)'] }
return { ok: false, errors: ['model.glb manquant (obligatoire)'] }
}
if (modelFiles.length > 1) {
return { ok: false, errors: ['Un seul fichier model.glb est autorise'] }
}
const textureFiles = files.filter((f) => {
const ext = f.name.slice(f.name.lastIndexOf('.')).toLowerCase()
return TEXTURE_EXT_ARRAY.includes(ext) && getTextureType(f.name) !== null
return TEXTURE_EXT_ARRAY.includes(ext)
})
for (const tf of textureFiles) {
textures.push({ name: tf.name, file: tf })
}
const foundTextures = new Set(
textures.map((t) => t.name.toLowerCase().replace(/\.[^.]+$/, '')),
)
for (const req of REQUIRED_TEXTURES) {
if (!foundTextures.has(req)) {
warnings.push(`${req}.webp/png/jpg manquant`)
}
}
if (errors.length > 0) {
return { ok: false, errors }
}
return { ok: true, model: modelFiles[0], textures, warnings }
return { ok: true, model: modelFiles[0], textures, warnings: [] }
}