|
|
@@ -997,8 +997,19 @@ router.post('/books/:id/generate', optionalAuth, async (ctx: Context) => {
|
|
|
await bookStore.update(bookId, { genStage: 'outlining', totalChapters: 0, progress: 0 });
|
|
|
|
|
|
langGraphGenerator.generate(bookId, book.description, bookScale, genLevel, userId)
|
|
|
- .then(() => {
|
|
|
+ .then(async () => {
|
|
|
console.log(`[LangGraph] 生成完成: bookId=${bookId}`);
|
|
|
+ // 根据实际章节状态更新书籍 genStage
|
|
|
+ const chapters = await bookStore.getChapterTree(bookId);
|
|
|
+ const leafNodes = chapters.filter((c: any) => {
|
|
|
+ const maxLevel = Math.max(...chapters.map((ch: any) => ch.level || 0));
|
|
|
+ return c.level === maxLevel;
|
|
|
+ });
|
|
|
+ const allContentDone = leafNodes.length > 0 && leafNodes.every((c: any) => c.genStage === 'content_completed' || c.genStage === 'audio_completed' || c.genStage === 'video_completed');
|
|
|
+ const allAudioDone = leafNodes.length > 0 && leafNodes.every((c: any) => c.genStage === 'audio_completed' || c.genStage === 'video_completed');
|
|
|
+ const finalStage = allAudioDone ? 'audio_completed' : allContentDone ? 'content_completed' : 'outlining';
|
|
|
+ await bookStore.update(bookId, { genStage: finalStage, progress: 100 });
|
|
|
+ console.log(`[LangGraph] 最终状态: ${finalStage}, 叶节点: ${leafNodes.length}`);
|
|
|
})
|
|
|
.catch(err => {
|
|
|
console.error(`[LangGraph] 生成失败: bookId=${bookId}`, err);
|