fix(parse-cv): polyfill DOMMatrix and dynamically import pdf-parse
This commit is contained in:
parent
30546bcb24
commit
c6024efcef
1 changed files with 11 additions and 1 deletions
|
|
@ -1,9 +1,16 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { createServerSupabaseClient } from "@/lib/supabase";
|
||||
import { generateEmbedding } from "@/lib/embeddings";
|
||||
import { PDFParse } from "pdf-parse";
|
||||
import { extractCandidateProfile } from "@/lib/gemini";
|
||||
|
||||
// Polyfill missing DOM APIs in Next.js Serverless / Node environment for pdfjs-dist
|
||||
if (typeof global !== "undefined") {
|
||||
const g = global as Record<string, unknown>;
|
||||
if (!g["DOMMatrix"]) g["DOMMatrix"] = class DOMMatrix {};
|
||||
if (!g["ImageData"]) g["ImageData"] = class ImageData {};
|
||||
if (!g["Path2D"]) g["Path2D"] = class Path2D {};
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const formData = await request.formData();
|
||||
|
|
@ -15,6 +22,9 @@ export async function POST(request: NextRequest) {
|
|||
const arrayBuffer = await file.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
|
||||
// Dynamic import to ensure global polyfills run first
|
||||
const { PDFParse } = await import("pdf-parse");
|
||||
|
||||
// Extract text from PDF using PDFParse v2 API
|
||||
const parser = new PDFParse({ data: buffer });
|
||||
const pdfData = await parser.getText();
|
||||
|
|
|
|||
Loading…
Reference in a new issue