file parse
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m40s

This commit is contained in:
Song367 2026-03-12 17:38:18 +08:00
parent 18dd726fb3
commit a1f8b1b50b

View File

@ -1,8 +1,5 @@
import mammoth from 'mammoth'; import mammoth from 'mammoth';
import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist'; import { getDocument } from 'pdfjs-dist';
import pdfWorker from 'pdfjs-dist/build/pdf.worker.mjs?url';
GlobalWorkerOptions.workerSrc = pdfWorker;
const SUPPORTED_EXTENSIONS = ['docx', 'txt', 'pdf', 'md'] as const; const SUPPORTED_EXTENSIONS = ['docx', 'txt', 'pdf', 'md'] as const;
export type SupportedUploadExtension = typeof SUPPORTED_EXTENSIONS[number]; export type SupportedUploadExtension = typeof SUPPORTED_EXTENSIONS[number];
@ -22,7 +19,7 @@ function getExtension(fileName: string): SupportedUploadExtension | null {
async function parsePdf(file: File): Promise<string> { async function parsePdf(file: File): Promise<string> {
const data = new Uint8Array(await file.arrayBuffer()); const data = new Uint8Array(await file.arrayBuffer());
const pdf = await getDocument({ data }).promise; const pdf = await getDocument({ data, disableWorker: true as unknown as boolean }).promise;
const pages: string[] = []; const pages: string[] = [];
for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber += 1) { for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber += 1) {