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
+11 -8
View File
@@ -3,20 +3,22 @@
import { useState, useRef, useCallback } from 'react'
import { getErrorMessage } from '@/lib/guards'
import type { FolderEntry } from '@/lib/client-types'
import type { FileDiff } from '@/lib/types'
import type { DriveAction, FileDiff, GitModelMode } from '@/lib/types'
import { checkFolderDiffs, stageUpload, uploadDrive, uploadGit } from '@/lib/upload-api'
import type { CheckResult } from '@/lib/upload-api'
type UploadLogDetails = Record<string, string | number | boolean | undefined>
function formatElapsed(startedAt: number) {
return `${((performance.now() - startedAt) / 1000).toFixed(1)}s`
}
function logUpload(level: 'INFO' | 'ERROR', step: string, action: string, startedAt: number, details?: Record<string, unknown>) {
function logUpload(level: 'INFO' | 'ERROR', step: string, action: string, startedAt: number, details?: UploadLogDetails) {
const log = level === 'ERROR' ? console.error : console.info
log(`[${level}] ${step} -> ${action} | Timer: ${formatElapsed(startedAt)}`, details || '')
}
function startTimedLog(step: string, action: string, details?: Record<string, unknown>) {
function startTimedLog(step: string, action: string, details?: UploadLogDetails) {
const startedAt = performance.now()
logUpload('INFO', step, `${action} started`, startedAt, details)
@@ -24,7 +26,7 @@ function startTimedLog(step: string, action: string, details?: Record<string, un
logUpload('INFO', step, `${action} running`, startedAt, details)
}, 10_000)
return (status: 'done' | 'failed' | 'cancelled' = 'done', extra?: Record<string, unknown>) => {
return (status: 'done' | 'failed' | 'cancelled' = 'done', extra?: UploadLogDetails) => {
window.clearInterval(interval)
logUpload(status === 'failed' ? 'ERROR' : 'INFO', step, `${action} ${status}`, startedAt, { ...details, ...extra })
}
@@ -122,7 +124,7 @@ export function useUploadOrchestrator({
if (controller.signal.aborted) break
const folderEntry = currentEntries[i]
const driveAction = checkResultRef.current.exists ? 'replace' : 'new'
const driveAction: DriveAction = checkResultRef.current.exists ? 'replace' : 'new'
const stagingId = stagingIdRef.current
if (!stagingId) {
updateEntry(i, { status: 'error', error: 'Preparation serveur introuvable' })
@@ -148,7 +150,7 @@ export function useUploadOrchestrator({
driveResult = await uploadDrive(
stagingId,
secretRef.current,
driveAction as 'new' | 'replace',
driveAction,
controller.signal,
)
endDriveLog(driveResult.success ? 'done' : 'failed', { error: driveResult.error })
@@ -176,7 +178,7 @@ export function useUploadOrchestrator({
}
}, [updateEntry, pushGit])
const handleUpload = useCallback(async () => {
const handleUpload = useCallback(async (gitModelMode: GitModelMode) => {
if (uploadActionRef.current || isChecking || isUploading) return
if (!secretRef.current.trim()) {
@@ -199,11 +201,12 @@ export function useUploadOrchestrator({
folderName: folder.folderName,
files: 1 + folder.textures.length,
modelSize: folder.modelFile.size,
gitModelMode,
})
let staged: Awaited<ReturnType<typeof stageUpload>>
try {
staged = await stageUpload(folder, secretRef.current, controller.signal)
staged = await stageUpload(folder, gitModelMode, secretRef.current, controller.signal)
endStageLog('done', { stagingId: staged.stagingId, filesCount: staged.filesCount })
} catch (err) {
endStageLog(controller.signal.aborted ? 'cancelled' : 'failed', {