// --------------------------------------------------------------------------- // Client-side folder validation // --------------------------------------------------------------------------- import { ASSET_EXTENSIONS, TEXTURE_EXTENSIONS } from '@/lib/constants' import type { TextureFile } from '@/lib/client-types' const SUPPORT_FILE_EXT_ARRAY = [...TEXTURE_EXTENSIONS, ...ASSET_EXTENSIONS] /** Discriminated union: either valid (with model) or invalid (with errors). */ export type ValidationResult = | { ok: true; model: File; textures: TextureFile[]; warnings: string[] } | { ok: false; errors: string[] } export function validateFolder(files: File[]): ValidationResult { const textures: TextureFile[] = [] const errors: string[] = [] const modelFiles = files.filter((f) => { const name = f.name.toLowerCase() return name === 'model.gltf' }) if (modelFiles.length === 0) { return { ok: false, errors: ['model.gltf manquant (obligatoire)'] } } if (modelFiles.length > 1) { return { ok: false, errors: ['Un seul fichier model.gltf est autorise'] } } const textureFiles = files.filter((f) => { const ext = f.name.slice(f.name.lastIndexOf('.')).toLowerCase() return SUPPORT_FILE_EXT_ARRAY.includes(ext) }) for (const tf of textureFiles) { textures.push({ name: tf.name, file: tf }) } if (errors.length > 0) { return { ok: false, errors } } return { ok: true, model: modelFiles[0], textures, warnings: [] } }