ok
This commit is contained in:
@@ -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://localhost:5001/analyze";
|
||||
"http://analyzer.151.80.20.211.sslip.io/analyze";
|
||||
// "http://localhost:5001/analyze";
|
||||
try {
|
||||
const analyzeResponse = await fetch(presidioAnalyzerUrl, {
|
||||
method: "POST",
|
||||
@@ -213,8 +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://localhost:5001/anonymize";
|
||||
"http://analyzer.151.80.20.211.sslip.io/anonymize";
|
||||
// "http://localhost:5001/anonymize";
|
||||
|
||||
const anonymizeResponse = await fetch(presidioAnonymizerUrl, {
|
||||
method: "POST",
|
||||
@@ -253,36 +253,33 @@ export async function POST(req: NextRequest) {
|
||||
) => {
|
||||
const replacementMap: Record<string, string> = {};
|
||||
|
||||
// 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
|
||||
);
|
||||
|
||||
// Trier les entités par position
|
||||
const sortedResults = [...analyzerResults].sort(
|
||||
(a, b) => a.start - b.start
|
||||
);
|
||||
|
||||
// Associer chaque entité avec son remplacement correspondant
|
||||
sortedResults.forEach((result, index) => {
|
||||
// Pour chaque entité, trouver son remplacement dans le texte anonymisé
|
||||
let searchOffset = 0;
|
||||
|
||||
sortedResults.forEach((result) => {
|
||||
const originalValue = originalText.substring(
|
||||
result.start,
|
||||
result.end
|
||||
);
|
||||
|
||||
if (index < foundReplacements.length) {
|
||||
// Utiliser le remplacement correspondant par ordre d'apparition
|
||||
replacementMap[originalValue] = foundReplacements[index];
|
||||
// Chercher le prochain remplacement [XXX] après la position courante
|
||||
const replacementPattern = /\[[^\]]+\]/g;
|
||||
replacementPattern.lastIndex = searchOffset;
|
||||
const match = replacementPattern.exec(anonymizedText);
|
||||
|
||||
if (match) {
|
||||
replacementMap[originalValue] = match[0];
|
||||
searchOffset = match.index + match[0].length;
|
||||
console.log(
|
||||
`✅ Mapping ordonné: "${originalValue}" -> "${foundReplacements[index]}"`
|
||||
`✅ Mapping positionnel: "${originalValue}" -> "${match[0]}"`
|
||||
);
|
||||
} else {
|
||||
// Fallback si pas assez de remplacements trouvés
|
||||
// Fallback
|
||||
const fallbackValue = `[${result.entity_type.toUpperCase()}]`;
|
||||
replacementMap[originalValue] = fallbackValue;
|
||||
console.log(
|
||||
|
||||
Reference in New Issue
Block a user