file parse 优化
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m41s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m41s
This commit is contained in:
parent
a1f8b1b50b
commit
c357ea9b2a
@ -1,5 +1,10 @@
|
|||||||
import mammoth from 'mammoth';
|
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;
|
const SUPPORTED_EXTENSIONS = ['docx', 'txt', 'pdf', 'md'] as const;
|
||||||
export type SupportedUploadExtension = typeof SUPPORTED_EXTENSIONS[number];
|
export type SupportedUploadExtension = typeof SUPPORTED_EXTENSIONS[number];
|
||||||
@ -19,7 +24,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, disableWorker: true as unknown as boolean }).promise;
|
const pdf = await getDocument({ data }).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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user