fin du refactp

This commit is contained in:
Tom Boullay
2026-04-14 14:27:50 +02:00
parent e9ae6ffc41
commit f9e15d5e1f
18 changed files with 826 additions and 476 deletions
+23
View File
@@ -0,0 +1,23 @@
// ---------------------------------------------------------------------------
// Client-side types — used by components and hooks (no Node.js Buffer)
// ---------------------------------------------------------------------------
export type FileStatus = 'pending' | 'uploading' | 'success' | 'error'
export interface TextureFile {
name: string
file: File
}
export interface FolderEntry {
folderName: string
modelFile: File
textures: TextureFile[]
status: FileStatus
progress: number
error?: string
filename?: string
modelUrl?: string
viewerOpen?: boolean
warnings: string[]
}
+11
View File
@@ -0,0 +1,11 @@
// ---------------------------------------------------------------------------
// Format bytes to human-readable string
// ---------------------------------------------------------------------------
export function formatBytes(bytes: number): string {
if (bytes === 0) return '0 B'
const k = 1024
const sizes = ['B', 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
}
+63
View File
@@ -0,0 +1,63 @@
// ---------------------------------------------------------------------------
// 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
}
export function validateFolder(files: File[]): {
model?: File
textures: TextureFile[]
errors: string[]
warnings: string[]
} {
const result: {
model?: File
textures: TextureFile[]
errors: string[]
warnings: string[]
} = {
textures: [],
errors: [],
warnings: [],
}
const modelFiles = files.filter((f) => {
const name = f.name.toLowerCase()
return name === 'model.glb' || name === 'model.gltf'
})
if (modelFiles.length === 0) {
result.errors.push('model.glb ou model.gltf manquant (obligatoire)')
} else {
result.model = modelFiles[0]
}
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) {
result.textures.push({ name: tf.name, file: tf })
}
const foundTextures = new Set(
result.textures.map((t) => t.name.toLowerCase().replace(/\.[^.]+$/, '')),
)
for (const req of REQUIRED_TEXTURES) {
if (!foundTextures.has(req)) {
result.warnings.push(`${req}.webp/png/jpg manquant`)
}
}
return result
}