fix: harden upload resilience and contracts
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
import { useState, useRef, useCallback } from 'react'
|
||||
import { getErrorMessage } from '@/lib/guards'
|
||||
import type { FolderEntry } from '@/lib/client-types'
|
||||
import type { DriveAction, FileDiff, GitModelMode } from '@/lib/types'
|
||||
import type {
|
||||
CheckUploadResult,
|
||||
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>
|
||||
|
||||
@@ -62,7 +66,7 @@ export function useUploadOrchestrator({
|
||||
} | null>(null)
|
||||
|
||||
const abortRef = useRef<AbortController | null>(null)
|
||||
const checkResultRef = useRef<CheckResult>({ exists: false, diffs: [] })
|
||||
const checkResultRef = useRef<CheckUploadResult>({ exists: false, diffs: [] })
|
||||
const uploadActionRef = useRef(false)
|
||||
const stagingIdRef = useRef<string | null>(null)
|
||||
|
||||
@@ -101,6 +105,7 @@ export function useUploadOrchestrator({
|
||||
status: gitResult.success ? 'success' : 'error',
|
||||
progress: gitResult.success ? 100 : 0,
|
||||
error: gitResult.success ? undefined : gitResult.error,
|
||||
uploadWarning: gitResult.success ? gitResult.warning : undefined,
|
||||
filename: gitResult.filename,
|
||||
})
|
||||
}, [updateEntry])
|
||||
@@ -135,6 +140,7 @@ export function useUploadOrchestrator({
|
||||
status: 'uploading',
|
||||
progress: 1,
|
||||
error: undefined,
|
||||
uploadWarning: undefined,
|
||||
driveStatus: 'uploading',
|
||||
driveError: undefined,
|
||||
})
|
||||
@@ -221,7 +227,7 @@ export function useUploadOrchestrator({
|
||||
folderName: folder.folderName,
|
||||
stagingId: staged.stagingId,
|
||||
})
|
||||
let check: CheckResult
|
||||
let check: CheckUploadResult
|
||||
|
||||
try {
|
||||
check = await checkFolderDiffs(
|
||||
@@ -238,6 +244,7 @@ export function useUploadOrchestrator({
|
||||
}
|
||||
|
||||
checkResultRef.current = check
|
||||
updateEntry(0, { uploadWarning: check.warning })
|
||||
|
||||
if (check.exists) {
|
||||
if (check.diffs.length === 0) {
|
||||
@@ -289,6 +296,7 @@ export function useUploadOrchestrator({
|
||||
status: 'uploading',
|
||||
progress: 0,
|
||||
error: undefined,
|
||||
uploadWarning: undefined,
|
||||
driveStatus: 'skipped',
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user