fix: 修复整合包失败后的完整重试流程
Some checks failed
Axolotl desktop CI / guardrails (push) Has been cancelled
Axolotl desktop CI / desktop (macos-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (ubuntu-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (windows-latest) (push) Has been cancelled
Axolotl desktop CI / website (push) Has been cancelled
Repository checks / typos (push) Has been cancelled
Repository checks / tombi (push) Has been cancelled
Rust checks / shear (push) Has been cancelled
Sync source to CNB / Sync Git ref (push) Has been cancelled
Sync LobeHub models / sync (push) Has been cancelled

This commit is contained in:
2026-09-19 00:13:43 +08:00
parent 392f01ea4b
commit a47d309103
8 changed files with 266 additions and 32 deletions

View File

@ -1,30 +1,59 @@
import { computed, reactive } from 'vue'
import { hostedSync, type HostedSyncResult } from '../helpers/hosted-packs.ts'
const tasks = reactive(
new Map<string, { busy: boolean; result: HostedSyncResult | null; error: string }>(),
)
const inFlight = new Map<string, Promise<HostedSyncResult>>()
function getTask(instanceId: string) {
if (!tasks.has(instanceId)) tasks.set(instanceId, { busy: false, result: null, error: '' })
return tasks.get(instanceId)!
}
/**
* Run one authoritative StarLight synchronization per instance. Every retry
* surface uses this function so the full pack transaction, its progress and
* its final result cannot diverge between pages.
*/
export function runHostedSync(instanceId: string): Promise<HostedSyncResult> {
const existing = inFlight.get(instanceId)
if (existing) return existing
const current = getTask(instanceId)
current.busy = true
current.error = ''
current.result = null
const request = hostedSync(instanceId)
.then((result) => {
current.result = result
return result
})
.catch((error) => {
current.error = String(error)
throw error
})
.finally(() => {
current.busy = false
inFlight.delete(instanceId)
})
inFlight.set(instanceId, request)
return request
}
export function useHostedSync(instanceId: () => string) {
const task = computed(() => {
const id = instanceId()
if (!tasks.has(id)) tasks.set(id, { busy: false, result: null, error: '' })
return tasks.get(id)!
return getTask(instanceId())
})
async function sync() {
const id = instanceId()
const current = task.value
if (current.busy) return
current.busy = true
current.error = ''
current.result = null
if (task.value.busy) return undefined
try {
current.result = await hostedSync(id)
} catch (error) {
current.error = String(error)
} finally {
current.busy = false
return await runHostedSync(id)
} catch {
return undefined
}
}