From 05e33d1d05bdc88dcddb7ecfe8c743d766482c26 Mon Sep 17 00:00:00 2001 From: liuguancen Date: Thu, 2 Apr 2026 14:59:17 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=89=8D=E7=AB=AF+RAG]=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=9A=E5=BC=82=E6=AD=A5=E4=B8=8A=E4=BC=A0+MySQL=E5=9B=9E?= =?UTF-8?q?=E5=86=99=E5=AF=BC=E8=AF=BB=EF=BC=9BPDF=E5=88=87=E6=8D=A2detach?= =?UTF-8?q?ed(Uint8Array=E5=A4=8D=E5=88=B6)=EF=BC=9B=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=A0=8F=E9=81=AE=E6=8C=A1=EF=BC=9B=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E6=A8=A1=E5=BC=8F=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat_web_front/src/components/PdfViewer.vue | 12 +- .../src/components/ReadingCreate.vue | 11 +- chat_web_front/src/views/reading/index.vue | 17 +-- .../server/knowledge_base/kb_doc_api.py | 142 ++++++++++++------ 4 files changed, 120 insertions(+), 62 deletions(-) diff --git a/chat_web_front/src/components/PdfViewer.vue b/chat_web_front/src/components/PdfViewer.vue index 072f977..5d170eb 100644 --- a/chat_web_front/src/components/PdfViewer.vue +++ b/chat_web_front/src/components/PdfViewer.vue @@ -74,9 +74,17 @@ const loadPdf = async () => { loading.value = true; error.value = ''; try { + // 每次加载都复制一份,避免 pdfjs worker transfer 后 detach 原始数据 const rawSrc = toRaw(props.src); - const data = rawSrc instanceof ArrayBuffer ? new Uint8Array(rawSrc) : rawSrc; - const loadingTask = pdfjsLib.getDocument({ data }); + let bytes: Uint8Array; + if (rawSrc instanceof Uint8Array) { + bytes = new Uint8Array(rawSrc); // 复制 + } else if (rawSrc instanceof ArrayBuffer) { + bytes = new Uint8Array(new Uint8Array(rawSrc)); // 复制 + } else { + bytes = rawSrc as any; + } + const loadingTask = pdfjsLib.getDocument({ data: bytes }); pdfDoc = await loadingTask.promise; const numPages = pdfDoc.numPages; pages.value = Array.from({ length: numPages }, (_, i) => i + 1); diff --git a/chat_web_front/src/components/ReadingCreate.vue b/chat_web_front/src/components/ReadingCreate.vue index 9af880a..5be0c74 100644 --- a/chat_web_front/src/components/ReadingCreate.vue +++ b/chat_web_front/src/components/ReadingCreate.vue @@ -434,7 +434,7 @@ const handleStop = async () => {