5 Commits

2 changed files with 11 additions and 5 deletions

View File

@@ -30,6 +30,7 @@ ENV NODE_ENV=production
COPY --from=build /app/backend/dist ./dist
COPY --from=build /app/backend/package.json ./package.json
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/backend/node_modules/ ./node_modules/
COPY backend/.env .env
EXPOSE 3000

View File

@@ -63,9 +63,15 @@ export function isPdfConversionError(r: unknown): r is PdfConversionError {
);
}
// pdf-parse v1 default export: (buffer, options?) => Promise<{ text, numpages, info }>
// eslint-disable-next-line @typescript-eslint/no-require-imports
const pdfParse: (buf: Buffer) => Promise<{ text: string }> = require('pdf-parse');
// Lazy-loaded so the app starts even if pdf-parse is missing from node_modules.
let _pdfParse: ((buf: Buffer) => Promise<{ text: string }>) | undefined;
function getPdfParse() {
if (!_pdfParse) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
_pdfParse = require('pdf-parse') as (buf: Buffer) => Promise<{ text: string }>;
}
return _pdfParse;
}
export async function convertPdfToStatement(
buffer: Buffer,
@@ -80,7 +86,7 @@ export async function convertPdfToStatement(
let text: string;
try {
const result = await pdfParse(buffer);
const result = await getPdfParse()(buffer);
text = result.text || '';
} catch (err) {
console.error('PDF extraction error:', err);
@@ -113,7 +119,6 @@ export async function convertPdfToStatement(
],
temperature: 0,
max_tokens: 32768,
response_format: { type: 'json_object' },
});
const content = completion.choices[0]?.message?.content?.trim();