fix: batch Git LFS uploads
This commit is contained in:
@@ -10,27 +10,26 @@ 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>) {
|
||||
function logUpload(level: 'INFO' | 'ERROR', step: string, action: string, startedAt: number, details?: Record<string, unknown>) {
|
||||
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>) {
|
||||
const startedAt = performance.now()
|
||||
console.info(`${UPLOAD_LOG_PREFIX} ${label} started`, details || '')
|
||||
logUpload('INFO', step, `${action} started`, startedAt, details)
|
||||
|
||||
const interval = window.setInterval(() => {
|
||||
console.info(`${UPLOAD_LOG_PREFIX} ${label} still running`, { elapsed: formatElapsed(startedAt), ...details })
|
||||
logUpload('INFO', step, `${action} running`, 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,
|
||||
})
|
||||
logUpload(status === 'failed' ? 'ERROR' : 'INFO', step, `${action} ${status}`, startedAt, { ...details, ...extra })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +82,7 @@ export function useUploadOrchestrator({
|
||||
}
|
||||
|
||||
const folderName = entriesRef.current[index]?.folderName
|
||||
const endGitLog = startTimedLog('Git upload', { folderName, stagingId })
|
||||
const endGitLog = startTimedLog('Git', 'Upload', { folderName, stagingId })
|
||||
let gitResult: Awaited<ReturnType<typeof uploadGit>>
|
||||
|
||||
try {
|
||||
@@ -145,7 +144,7 @@ export function useUploadOrchestrator({
|
||||
driveError: undefined,
|
||||
})
|
||||
|
||||
const endDriveLog = startTimedLog('Drive upload', {
|
||||
const endDriveLog = startTimedLog('Drive', 'Upload', {
|
||||
folderName: folderEntry.folderName,
|
||||
stagingId,
|
||||
action: driveAction,
|
||||
@@ -206,7 +205,7 @@ export function useUploadOrchestrator({
|
||||
abortRef.current = controller
|
||||
|
||||
try {
|
||||
const endStageLog = startTimedLog('Verification: staging upload', {
|
||||
const endStageLog = startTimedLog('Verification', 'Staging', {
|
||||
folderName: folder.folderName,
|
||||
files: 1 + folder.textures.length,
|
||||
modelSize: folder.modelFile.size,
|
||||
@@ -225,7 +224,7 @@ export function useUploadOrchestrator({
|
||||
|
||||
stagingIdRef.current = staged.stagingId
|
||||
|
||||
const endCheckLog = startTimedLog('Verification: GitHub diff check', {
|
||||
const endCheckLog = startTimedLog('Verification', 'GitHub diff', {
|
||||
folderName: folder.folderName,
|
||||
stagingId: staged.stagingId,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user