chore: add upload timing logs
This commit is contained in:
@@ -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<string, unknown>) {
|
||||
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<string, unknown>) => {
|
||||
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<ReturnType<typeof uploadGit>>
|
||||
|
||||
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<ReturnType<typeof uploadDrive>>
|
||||
|
||||
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<ReturnType<typeof stageUpload>>
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user