78f4aa83e0
- Extract API helpers from UploadZone into lib/upload-api.ts (FormData builder, checkFolderDiffs, uploadDrive, uploadGit)
- Extract upload orchestration into hooks/useUploadOrchestrator.ts (UploadZone: 489 → 162 lines)
- Extract file diff classification into lib/diff-files.ts (from git route)
- Extract shared SVG icons into components/ui/icons.tsx (7 icons, 0 duplication)
- Extract shared modal wrapper into components/ui/Modal.tsx + ModalActions
- Extract DriveStatusLine sub-component from FolderCard
- Fix checkFolderDiffs silently swallowing auth/network errors (now throws)
- Fix type safety: remove as never casts, add isHttpError type guard, use discriminated union for validateFolder
- Fix nextcloud: cache getConfig, add max bound to findNextVersion, optimize mkdirRecursive (skip PROPFIND)
- Fix drive route: remove req.clone(), extend parseMultiUpload to return extra fields
- Fix commit message: model shown as unchanged with ↔️ on updates (not falsely marked as modified)
- Clean dead code: unused folderExists import, FileStatus/DriveStatus exports, ParsedFile.textureName, getConfig basePath
- Add security headers in next.config.ts (HSTS, X-Content-Type-Options, X-Frame-Options, etc.)
- Update README with new project structure
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
// ---------------------------------------------------------------------------
|
|
// Client-side folder validation
|
|
// ---------------------------------------------------------------------------
|
|
|
|
import { REQUIRED_TEXTURES, 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[] }
|
|
| { ok: false; errors: string[] }
|
|
|
|
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'
|
|
})
|
|
|
|
if (modelFiles.length === 0) {
|
|
return { ok: false, errors: ['model.glb ou model.gltf manquant (obligatoire)'] }
|
|
}
|
|
|
|
const textureFiles = files.filter((f) => {
|
|
const ext = f.name.slice(f.name.lastIndexOf('.')).toLowerCase()
|
|
return TEXTURE_EXT_ARRAY.includes(ext) && getTextureType(f.name) !== null
|
|
})
|
|
|
|
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 }
|
|
}
|