MCPcopy Create free account
hub / github.com/HisMax/RedInk / useImageRetry

Function useImageRetry

frontend/src/composables/useImageRetry.ts:13–121  ·  view source on GitHub ↗
(setError: (error: AppError | null) => void)

Source from the content-addressed store, hash-verified

11} from '../utils/errors'
12
13export function useImageRetry(setError: (error: AppError | null) => void) {
14 const store = useGeneratorStore()
15 const isRetrying = ref(false)
16 const regeneratingIndices = ref(new Set<number>())
17
18 function finishIfAllImagesDone() {
19 if (store.taskId && store.images.length > 0 && store.images.every(img => img.status === 'done')) {
20 store.finishGeneration(store.taskId)
21 }
22 }
23
24 function retrySingleImage(index: number) {
25 if (!store.taskId || regeneratingIndices.value.has(index)) return
26
27 const page = store.outline.pages.find(p => p.index === index)
28 if (!page) return
29
30 regeneratingIndices.value.add(index)
31 store.setImageRetrying(index)
32
33 const context = {
34 fullOutline: store.outline.raw || '',
35 userTopic: store.topic || '',
36 recordId: store.recordId
37 }
38
39 apiRegenerateImage(store.taskId, page, true, context)
40 .then(result => {
41 if (result.success && result.image_url) {
42 store.updateImage(index, result.image_url)
43 finishIfAllImagesDone()
44 } else {
45 store.updateProgress(
46 index,
47 'error',
48 undefined,
49 formatErrorMessage(result.error || result.error_message || '重绘失败', '重绘失败')
50 )
51 }
52 })
53 .catch(e => {
54 store.updateProgress(index, 'error', undefined, formatErrorMessage(e, '重绘失败'))
55 })
56 .finally(() => {
57 regeneratingIndices.value.delete(index)
58 })
59 }
60
61 function regenerateImage(index: number) {
62 retrySingleImage(index)
63 }
64
65 async function retryAllFailed() {
66 if (!store.taskId) return
67
68 const failedPages = store.getFailedPages()
69 if (failedPages.length === 0) return
70

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected