presidio ok v.1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import pdf from "pdf-parse/lib/pdf-parse";
|
||||
import pdf from "pdf-parse"; // ✅ Import correct
|
||||
import mammoth from "mammoth";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
@@ -27,13 +27,20 @@ export async function POST(req: NextRequest) {
|
||||
const data = await pdf(buffer);
|
||||
fileContent = data.text || "";
|
||||
console.log("✅ Extraction PDF réussie, longueur:", fileContent.length);
|
||||
|
||||
// ✅ Vérification supplémentaire
|
||||
if (!fileContent.trim()) {
|
||||
console.log("⚠️ PDF vide ou non lisible");
|
||||
return NextResponse.json(
|
||||
{ error: "Le PDF ne contient pas de texte extractible ou est protégé." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
} catch (pdfError) {
|
||||
console.error("❌ Erreur PDF:", pdfError);
|
||||
console.error("❌ Erreur PDF détaillée:", pdfError);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: `Erreur traitement PDF: ${
|
||||
pdfError instanceof Error ? pdfError.message : "Erreur inconnue"
|
||||
}`,
|
||||
error: `Erreur traitement PDF: ${pdfError instanceof Error ? pdfError.message : "Erreur inconnue"}. Vérifiez que le PDF n'est pas protégé ou corrompu.`,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
@@ -110,10 +117,10 @@ export async function POST(req: NextRequest) {
|
||||
};
|
||||
|
||||
console.log("🔍 Appel à Presidio Analyzer...");
|
||||
|
||||
const presidioAnalyzerUrl =
|
||||
"http://analyzer.151.80.20.211.sslip.io/analyze";
|
||||
|
||||
|
||||
// ✅ Définir l'URL AVANT de l'utiliser
|
||||
const presidioAnalyzerUrl = "http://analyzer.151.80.20.211.sslip.io/analyze";
|
||||
|
||||
try {
|
||||
const analyzeResponse = await fetch(presidioAnalyzerUrl, {
|
||||
method: "POST",
|
||||
@@ -123,11 +130,15 @@ export async function POST(req: NextRequest) {
|
||||
},
|
||||
body: JSON.stringify(analyzerConfig),
|
||||
});
|
||||
|
||||
|
||||
console.log("📊 Statut Analyzer:", analyzeResponse.status);
|
||||
console.log("📊 Headers Analyzer:", analyzeResponse.headers);
|
||||
|
||||
if (!analyzeResponse.ok) {
|
||||
const errorBody = await analyzeResponse.text();
|
||||
console.error("❌ Erreur Analyzer:", errorBody);
|
||||
console.error("❌ URL utilisée:", presidioAnalyzerUrl);
|
||||
console.error("❌ Config envoyée:", analyzerConfig);
|
||||
// Fallback: retourner juste le texte si Presidio n'est pas disponible
|
||||
return NextResponse.json({ text: fileContent }, { status: 200 });
|
||||
}
|
||||
@@ -172,6 +183,7 @@ export async function POST(req: NextRequest) {
|
||||
text: fileContent,
|
||||
anonymizedText: anonymizerResult.text,
|
||||
piiCount: analyzerResults.length,
|
||||
analyzerResults: analyzerResults,
|
||||
};
|
||||
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
|
||||
Reference in New Issue
Block a user