From 799e61c92eef3091b6b266c8380ba268c592e922 Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Mon, 27 Apr 2026 23:11:16 +0200 Subject: [PATCH] chore: add upload timing logs --- hooks/useUploadOrchestrator.ts | 116 ++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 17 deletions(-) diff --git a/hooks/useUploadOrchestrator.ts b/hooks/useUploadOrchestrator.ts index e4a5547..2f45e25 100644 --- a/hooks/useUploadOrchestrator.ts +++ b/hooks/useUploadOrchestrator.ts @@ -10,6 +10,30 @@ import type { FileDiff } from '@/lib/types' import { checkFolderDiffs, stageUpload, uploadDrive, uploadGit } from '@/lib/upload-api' import type { CheckResult } from '@/lib/upload-api' +const UPLOAD_LOG_PREFIX = '[upload-gltf]' + +function formatElapsed(startedAt: number) { + return `${((performance.now() - startedAt) / 1000).toFixed(1)}s` +} + +function startTimedLog(label: string, details?: Record) { + const startedAt = performance.now() + console.info(`${UPLOAD_LOG_PREFIX} ${label} started`, details || '') + + const interval = window.setInterval(() => { + console.info(`${UPLOAD_LOG_PREFIX} ${label} still running`, { elapsed: formatElapsed(startedAt), ...details }) + }, 10_000) + + return (status: 'done' | 'failed' | 'cancelled' = 'done', extra?: Record) => { + window.clearInterval(interval) + console.info(`${UPLOAD_LOG_PREFIX} ${label} ${status}`, { + elapsed: formatElapsed(startedAt), + ...details, + ...extra, + }) + } +} + interface UseUploadOrchestratorParams { secret: string setSecretError: (err: string | null) => void @@ -58,12 +82,24 @@ export function useUploadOrchestrator({ return } - const gitResult = await uploadGit( - stagingId, - secretRef.current, - (pct) => updateEntry(index, { progress: 50 + Math.round(pct / 2) }), - signal, - ) + const folderName = entriesRef.current[index]?.folderName + const endGitLog = startTimedLog('Git upload', { folderName, stagingId }) + let gitResult: Awaited> + + try { + gitResult = await uploadGit( + stagingId, + secretRef.current, + (pct) => updateEntry(index, { progress: 50 + Math.round(pct / 2) }), + signal, + ) + endGitLog(gitResult.success ? 'done' : 'failed', { error: gitResult.error }) + } catch (err) { + endGitLog(signal?.aborted ? 'cancelled' : 'failed', { + error: err instanceof Error ? err.message : 'Erreur inconnue', + }) + throw err + } updateEntry(index, { status: gitResult.success ? 'success' : 'error', @@ -109,12 +145,27 @@ export function useUploadOrchestrator({ driveError: undefined, }) - const driveResult = await uploadDrive( + const endDriveLog = startTimedLog('Drive upload', { + folderName: folderEntry.folderName, stagingId, - secretRef.current, - driveAction as 'new' | 'replace', - controller.signal, - ) + action: driveAction, + }) + let driveResult: Awaited> + + try { + driveResult = await uploadDrive( + stagingId, + secretRef.current, + driveAction as 'new' | 'replace', + controller.signal, + ) + endDriveLog(driveResult.success ? 'done' : 'failed', { error: driveResult.error }) + } catch (err) { + endDriveLog(controller.signal.aborted ? 'cancelled' : 'failed', { + error: err instanceof Error ? err.message : 'Erreur inconnue', + }) + throw err + } if (!driveResult.success) { updateEntry(i, { driveStatus: 'error', driveError: driveResult.error }) @@ -155,14 +206,45 @@ export function useUploadOrchestrator({ abortRef.current = controller try { - const staged = await stageUpload(folder, secretRef.current, controller.signal) + const endStageLog = startTimedLog('Verification: staging upload', { + folderName: folder.folderName, + files: 1 + folder.textures.length, + modelSize: folder.modelFile.size, + }) + let staged: Awaited> + + try { + staged = await stageUpload(folder, secretRef.current, controller.signal) + endStageLog('done', { stagingId: staged.stagingId, filesCount: staged.filesCount }) + } catch (err) { + endStageLog(controller.signal.aborted ? 'cancelled' : 'failed', { + error: err instanceof Error ? err.message : 'Erreur inconnue', + }) + throw err + } + stagingIdRef.current = staged.stagingId - const check = await checkFolderDiffs( - staged.stagingId, - secretRef.current, - controller.signal, - ) + const endCheckLog = startTimedLog('Verification: GitHub diff check', { + folderName: folder.folderName, + stagingId: staged.stagingId, + }) + let check: CheckResult + + try { + check = await checkFolderDiffs( + staged.stagingId, + secretRef.current, + controller.signal, + ) + endCheckLog('done', { exists: check.exists, diffs: check.diffs.length }) + } catch (err) { + endCheckLog(controller.signal.aborted ? 'cancelled' : 'failed', { + error: err instanceof Error ? err.message : 'Erreur inconnue', + }) + throw err + } + checkResultRef.current = check if (check.exists) {