chore: prepare v1.0.0 release
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
'use client'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Upload orchestration hook — manages the Drive→Git upload pipeline
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
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 { checkFolderDiffs, stageUpload, uploadDrive, uploadGit } from '@/lib/upload-api'
|
||||
@@ -67,13 +64,11 @@ export function useUploadOrchestrator({
|
||||
const uploadActionRef = useRef(false)
|
||||
const stagingIdRef = useRef<string | null>(null)
|
||||
|
||||
// Refs for values used inside callbacks to avoid stale closures
|
||||
const secretRef = useRef(secret)
|
||||
secretRef.current = secret
|
||||
const entriesRef = useRef(entries)
|
||||
entriesRef.current = entries
|
||||
|
||||
// ---- Internal: push a single folder to Git ----
|
||||
const pushGit = useCallback(async (index: number, signal?: AbortSignal) => {
|
||||
const stagingId = stagingIdRef.current
|
||||
if (!stagingId) {
|
||||
@@ -95,7 +90,7 @@ export function useUploadOrchestrator({
|
||||
endGitLog(gitResult.success ? 'done' : 'failed', { error: gitResult.error })
|
||||
} catch (err) {
|
||||
endGitLog(signal?.aborted ? 'cancelled' : 'failed', {
|
||||
error: err instanceof Error ? err.message : 'Erreur inconnue',
|
||||
error: getErrorMessage(err),
|
||||
})
|
||||
throw err
|
||||
}
|
||||
@@ -108,7 +103,6 @@ export function useUploadOrchestrator({
|
||||
})
|
||||
}, [updateEntry])
|
||||
|
||||
// ---- Main upload flow: Drive first, then Git ----
|
||||
const proceedUpload = useCallback(async () => {
|
||||
if (uploadActionRef.current) return
|
||||
uploadActionRef.current = true
|
||||
@@ -135,7 +129,6 @@ export function useUploadOrchestrator({
|
||||
return
|
||||
}
|
||||
|
||||
// ---- Step 1: Drive upload ----
|
||||
updateEntry(i, {
|
||||
status: 'uploading',
|
||||
progress: 1,
|
||||
@@ -161,7 +154,7 @@ export function useUploadOrchestrator({
|
||||
endDriveLog(driveResult.success ? 'done' : 'failed', { error: driveResult.error })
|
||||
} catch (err) {
|
||||
endDriveLog(controller.signal.aborted ? 'cancelled' : 'failed', {
|
||||
error: err instanceof Error ? err.message : 'Erreur inconnue',
|
||||
error: getErrorMessage(err),
|
||||
})
|
||||
throw err
|
||||
}
|
||||
@@ -174,7 +167,6 @@ export function useUploadOrchestrator({
|
||||
|
||||
updateEntry(i, { driveStatus: 'success', progress: 50 })
|
||||
|
||||
// ---- Step 2: Git upload ----
|
||||
await pushGit(i, controller.signal)
|
||||
}
|
||||
} finally {
|
||||
@@ -184,8 +176,6 @@ export function useUploadOrchestrator({
|
||||
}
|
||||
}, [updateEntry, pushGit])
|
||||
|
||||
// ---- Handlers ----
|
||||
|
||||
const handleUpload = useCallback(async () => {
|
||||
if (uploadActionRef.current || isChecking || isUploading) return
|
||||
|
||||
@@ -217,7 +207,7 @@ export function useUploadOrchestrator({
|
||||
endStageLog('done', { stagingId: staged.stagingId, filesCount: staged.filesCount })
|
||||
} catch (err) {
|
||||
endStageLog(controller.signal.aborted ? 'cancelled' : 'failed', {
|
||||
error: err instanceof Error ? err.message : 'Erreur inconnue',
|
||||
error: getErrorMessage(err),
|
||||
})
|
||||
throw err
|
||||
}
|
||||
@@ -239,7 +229,7 @@ export function useUploadOrchestrator({
|
||||
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',
|
||||
error: getErrorMessage(err),
|
||||
})
|
||||
throw err
|
||||
}
|
||||
@@ -261,7 +251,7 @@ export function useUploadOrchestrator({
|
||||
return
|
||||
}
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
const message = getErrorMessage(err)
|
||||
setGlobalError(message)
|
||||
uploadActionRef.current = false
|
||||
setIsChecking(false)
|
||||
|
||||
Reference in New Issue
Block a user