Sfoglia il codice sorgente

feat: 添加防重复生成逻辑 - 正在生成中的书籍拒绝重复请求

MyFramework User 4 mesi fa
parent
commit
3c5eaf97ae
1 ha cambiato i file con 16 aggiunte e 0 eliminazioni
  1. 16 0
      server/src/modules/book-generator/langgraph-controller.ts

+ 16 - 0
server/src/modules/book-generator/langgraph-controller.ts

@@ -544,6 +544,22 @@ router.post('/books/:id/generate', async (ctx: Context) => {
       return;
     }
 
+    // 防止重复生成:如果书籍正在生成中,拒绝请求
+    if (book.status === 'generating') {
+      console.log(`[LangGraph Generate] 书籍正在生成中,拒绝重复请求 bookId=${bookId}`);
+      ctx.status = 400;
+      ctx.body = { 
+        code: 1, 
+        message: '书籍正在生成中,请勿重复提交',
+        data: {
+          bookId,
+          status: book.status,
+          progress: book.progress,
+        }
+      };
+      return;
+    }
+
     // 优先使用请求传入的 scale,否则使用书籍保存的 scale,最后默认标准教程
     const bookScale = body.bookScale || book.bookScale || '标准教程';