From 9d35c14bc20e324343c07861b732565334b0e7fb Mon Sep 17 00:00:00 2001 From: wangdl Date: Sat, 4 Jul 2026 11:59:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20storage=20=E9=BB=98=E8=AE=A4=20COS=20+?= =?UTF-8?q?=20indexStatus=20=E6=9B=B4=E6=96=B0=20+=20BullMQ=20=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E6=96=87=E4=BB=B6=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - storage.config.ts: NODE_ENV=production 默认 COS - internal-rag.controller.ts: saveChunks 同步更新 indexStatus - document-import.worker.ts: 文件导入跳过,留给 Python RAG Worker - .gitignore: 添加 uploads/ Co-Authored-By: Claude --- .gitignore | 1 + src/config/storage.config.ts | 2 +- src/modules/rag/internal-rag.controller.ts | 11 ++++++++++- src/workers/document-import.worker.ts | 7 +++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9cf75ba..424562f 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ docs/AI回答.md # rag-worker (migrated to own project) rag-worker/ +uploads/ diff --git a/src/config/storage.config.ts b/src/config/storage.config.ts index cf2ddf8..4509dd6 100644 --- a/src/config/storage.config.ts +++ b/src/config/storage.config.ts @@ -1,7 +1,7 @@ import { registerAs } from '@nestjs/config'; export default registerAs('storage', () => ({ - driver: process.env.STORAGE_DRIVER || 'local', + driver: process.env.STORAGE_DRIVER || (process.env.NODE_ENV === 'production' ? 'cos' : 'local'), localPath: process.env.STORAGE_LOCAL_PATH || './uploads', cos: { secretId: process.env.STORAGE_COS_SECRET_ID || '', diff --git a/src/modules/rag/internal-rag.controller.ts b/src/modules/rag/internal-rag.controller.ts index 3e6b786..f82edb9 100644 --- a/src/modules/rag/internal-rag.controller.ts +++ b/src/modules/rag/internal-rag.controller.ts @@ -115,7 +115,7 @@ export class InternalRagController { const totalChars = sourceChunks.reduce((sum, c) => sum + (c.tokenCount || c.content?.length || 0), 0); await this.prisma.knowledgeSource.updateMany({ where: { id: sourceId }, - data: { textLength: totalChars, parseStatus: 'completed', updatedAt: new Date() }, + data: { textLength: totalChars, parseStatus: 'completed', indexStatus: 'completed', updatedAt: new Date() }, }); } } @@ -140,6 +140,15 @@ export class InternalRagController { body.importId, body.candidates || [], ); + + // 更新 source 的学习状态 + if (body.sourceId && body.candidates?.length > 0) { + await this.prisma.knowledgeSource.updateMany({ + where: { id: body.sourceId }, + data: { learningStatus: 'completed', updatedAt: new Date() }, + }); + } + return { success: true, count: body.candidates?.length || 0 }; } } diff --git a/src/workers/document-import.worker.ts b/src/workers/document-import.worker.ts index 5304a34..e8c2523 100644 --- a/src/workers/document-import.worker.ts +++ b/src/workers/document-import.worker.ts @@ -40,10 +40,9 @@ export class DocumentImportWorker extends WorkerHost { try { if (!rawText) { - await this.repository.updateStatus(importId, 'completed'); - await this.redis.set(`job:document-import:${importId}:status`, 'completed', 86400); - await this.redis.set(`job:document-import:${importId}:progress`, '100', 86400); - await this.redis.set(`job:document-import:${importId}:message`, '无需解析的空文件', 86400); + // 文件导入(PDF/Office 等),由 Python RAG Worker 处理 + // BullMQ Worker 只处理纯文本导入 + this.logger.log(`Skipping file import ${importId} — delegated to Python RAG Worker`); return; }