fix: use require() for pdf-parse and pdfjs-dist legacy build to fix Node 24 compat
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
Logger,
|
||||
ServiceUnavailableException,
|
||||
} from '@nestjs/common';
|
||||
import pdfParse from 'pdf-parse';
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||
const pdfParse = require('pdf-parse') as (buffer: Buffer) => Promise<{ text: string }>;
|
||||
|
||||
const MISTRAL_API_URL = 'https://api.mistral.ai/v1/chat/completions';
|
||||
const RECEIPT_VISION_MODEL = 'mistral-small-2603'; // vision — används för bild-input
|
||||
@@ -288,10 +289,12 @@ export class ReceiptParsingService {
|
||||
} catch (err) {
|
||||
this.logger.warn(`pdf-parse misslyckades: ${err}`);
|
||||
|
||||
// Fallback to pdfjs-dist for more complex PDFs
|
||||
// Fallback to pdfjs-dist legacy build (Node.js compatible, no DOMMatrix needed)
|
||||
try {
|
||||
const pdfjsLib = await import('pdfjs-dist');
|
||||
const loadingTask = pdfjsLib.getDocument({ data: buffer });
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const pdfjsLib = require('pdfjs-dist/legacy/build/pdf.js') as typeof import('pdfjs-dist');
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = '';
|
||||
const loadingTask = pdfjsLib.getDocument({ data: new Uint8Array(buffer) });
|
||||
const pdfDocument = await loadingTask.promise;
|
||||
|
||||
let fullText = '';
|
||||
|
||||
Reference in New Issue
Block a user