From c357ea9b2a3d87ade1a993989e3dff9a355d3ca6 Mon Sep 17 00:00:00 2001 From: Song367 <601337784@qq.com> Date: Thu, 12 Mar 2026 17:46:29 +0800 Subject: [PATCH] =?UTF-8?q?file=20parse=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/fileParsing.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/fileParsing.ts b/src/services/fileParsing.ts index 4522960..93f0da3 100644 --- a/src/services/fileParsing.ts +++ b/src/services/fileParsing.ts @@ -1,5 +1,10 @@ import mammoth from 'mammoth'; -import { getDocument } from 'pdfjs-dist'; +import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist'; +import PdfWorker from 'pdfjs-dist/build/pdf.worker.mjs?worker'; + +if (typeof window !== 'undefined' && 'Worker' in window) { + GlobalWorkerOptions.workerPort = new PdfWorker(); +} const SUPPORTED_EXTENSIONS = ['docx', 'txt', 'pdf', 'md'] as const; export type SupportedUploadExtension = typeof SUPPORTED_EXTENSIONS[number]; @@ -19,7 +24,7 @@ function getExtension(fileName: string): SupportedUploadExtension | null { async function parsePdf(file: File): Promise { const data = new Uint8Array(await file.arrayBuffer()); - const pdf = await getDocument({ data, disableWorker: true as unknown as boolean }).promise; + const pdf = await getDocument({ data }).promise; const pages: string[] = []; for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber += 1) {