fix
This commit is contained in:
@@ -227,8 +227,15 @@ export function useTeachingBook(bookId: string): TeachingBookStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const abortController = new AbortController()
|
||||||
|
|
||||||
async function runWorker(): Promise<void> {
|
async function runWorker(): Promise<void> {
|
||||||
while (!firstError && !options.isCancelled?.()) {
|
while (!firstError) {
|
||||||
|
if (options.isCancelled?.()) {
|
||||||
|
abortController.abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const index = nextStartIndex
|
const index = nextStartIndex
|
||||||
if (index >= topics.length) return
|
if (index >= topics.length) return
|
||||||
|
|
||||||
@@ -237,12 +244,13 @@ export function useTeachingBook(bookId: string): TeachingBookStore {
|
|||||||
options.onTopicStart?.(topic)
|
options.onTopicStart?.(topic)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await booksApi.generateLesson(topic)
|
const result = await booksApi.generateLesson(topic, abortController.signal)
|
||||||
results[index] = removeGeneratedAdditionalContent(
|
results[index] = removeGeneratedAdditionalContent(
|
||||||
parseTeachingDesign(result.filename, result.markdown),
|
parseTeachingDesign(result.filename, result.markdown),
|
||||||
)
|
)
|
||||||
appendReadyLessons()
|
appendReadyLessons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error instanceof Error && error.name === 'AbortError') return
|
||||||
firstError = error instanceof Error ? error.message : '生成失败。'
|
firstError = error instanceof Error ? error.message : '生成失败。'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ export function deleteBook(id: string): Promise<{ ok: true }> {
|
|||||||
return authedFetch(`/api/books/${id}`, { method: 'DELETE' })
|
return authedFetch(`/api/books/${id}`, { method: 'DELETE' })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateLesson(topic: string): Promise<GenerateResult> {
|
export function generateLesson(topic: string, signal?: AbortSignal): Promise<GenerateResult> {
|
||||||
return authedFetch('/api/generate', { method: 'POST', body: JSON.stringify({ topic }) })
|
return authedFetch('/api/generate', { method: 'POST', body: JSON.stringify({ topic }), signal })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateOutline(theme: string): Promise<{ titles: string[] }> {
|
export function generateOutline(theme: string): Promise<{ titles: string[] }> {
|
||||||
|
|||||||
Reference in New Issue
Block a user