diff --git a/app/api/process-document/route.ts b/app/api/process-document/route.ts index b469f6f..e4c03fd 100644 --- a/app/api/process-document/route.ts +++ b/app/api/process-document/route.ts @@ -175,8 +175,8 @@ export async function POST(req: NextRequest) { // ✅ Définir l'URL AVANT de l'utiliser const presidioAnalyzerUrl = - "http://analyzer.151.80.20.211.sslip.io/analyze"; - + // "http://analyzer.151.80.20.211.sslip.io/analyze"; + "http://localhost:5001/analyze"; try { const analyzeResponse = await fetch(presidioAnalyzerUrl, { method: "POST", @@ -213,7 +213,8 @@ export async function POST(req: NextRequest) { console.log("🔍 Appel à Presidio Anonymizer..."); const presidioAnonymizerUrl = - "http://analyzer.151.80.20.211.sslip.io/anonymize"; + // "http://analyzer.151.80.20.211.sslip.io/anonymize"; + "http://localhost:5001/anonymize"; const anonymizeResponse = await fetch(presidioAnonymizerUrl, { method: "POST", @@ -251,32 +252,45 @@ export async function POST(req: NextRequest) { analyzerResults: AnalyzerResult[] ) => { const replacementMap: Record = {}; - + // Extraire tous les remplacements [XXX] du texte anonymisé const replacementPattern = /\[[^\]]+\]/g; - const foundReplacements = anonymizedText.match(replacementPattern) || []; - - console.log("🔍 Remplacements trouvés dans le texte anonymisé:", foundReplacements); - + const foundReplacements = + anonymizedText.match(replacementPattern) || []; + + console.log( + "🔍 Remplacements trouvés dans le texte anonymisé:", + foundReplacements + ); + // Trier les entités par position - const sortedResults = [...analyzerResults].sort((a, b) => a.start - b.start); - + const sortedResults = [...analyzerResults].sort( + (a, b) => a.start - b.start + ); + // Associer chaque entité avec son remplacement correspondant sortedResults.forEach((result, index) => { - const originalValue = originalText.substring(result.start, result.end); - + const originalValue = originalText.substring( + result.start, + result.end + ); + if (index < foundReplacements.length) { // Utiliser le remplacement correspondant par ordre d'apparition replacementMap[originalValue] = foundReplacements[index]; - console.log(`✅ Mapping ordonné: "${originalValue}" -> "${foundReplacements[index]}"`); + console.log( + `✅ Mapping ordonné: "${originalValue}" -> "${foundReplacements[index]}"` + ); } else { // Fallback si pas assez de remplacements trouvés const fallbackValue = `[${result.entity_type.toUpperCase()}]`; replacementMap[originalValue] = fallbackValue; - console.log(`⚠️ Fallback: "${originalValue}" -> "${fallbackValue}"`); + console.log( + `⚠️ Fallback: "${originalValue}" -> "${fallbackValue}"` + ); } }); - + console.log("🔧 Mapping final:", replacementMap); return replacementMap; }; diff --git a/app/components/InstructionsPanel.tsx b/app/components/InstructionsPanel.tsx index 1c9c685..0f7b9de 100644 --- a/app/components/InstructionsPanel.tsx +++ b/app/components/InstructionsPanel.tsx @@ -11,8 +11,7 @@ export const InstructionsPanel: React.FC = () => {