diff --git a/src/controllers/document.controller.ts b/src/controllers/document.controller.ts index a452d92..8113291 100644 --- a/src/controllers/document.controller.ts +++ b/src/controllers/document.controller.ts @@ -451,10 +451,11 @@ export async function extractTextFromUploadedFile(file: { buffer: Buffer; mimety if (zip) { const zipEntries = zip.getEntries().filter((e: any) => !e.isDirectory); - // 1. XML dosyalarını kontrol et (content.xml veya *.xml) - const xmlEntries = zipEntries.filter((entry: any) => - entry.entryName === "content.xml" || entry.entryName.toLowerCase().endsWith(".xml") - ); + // 1. XML dosyalarını kontrol et (content.xml, *.xml veya template XML) + const xmlEntries = zipEntries.filter((entry: any) => { + const name = entry.entryName.toLowerCase(); + return name.includes('content') || name.endsWith('.xml') || name.includes('template'); + }); // 2. İçerisinde gömülü PDF dosyası var mı kontrol et (*.pdf) const pdfEntry = zipEntries.find((entry: any) => @@ -480,7 +481,24 @@ export async function extractTextFromUploadedFile(file: { buffer: Buffer; mimety } if (rawXml && rawXml.trim()) { - const plainText = rawXml.replace(//gi, '') + // A. UYAP CDATA bloğu kontrolü (): UYAP format 1.8 şablonlarında asıl metin buradadır + const cdataMatches = rawXml.match(//gi); + if (cdataMatches && cdataMatches.length > 0) { + const cdataText = cdataMatches + .map(m => m.replace(/^$/, '').trim()) + .filter(Boolean) + .join('\n\n'); + + const cleanedCdata = sanitizePostgresText(cdataText); + if (cleanedCdata.length > 10) { + return cleanedCdata; + } + } + + // B. Genel XML etiket temizliği + const plainText = rawXml + .replace(//gi, (m) => m.replace(/^$/, '')) + .replace(//gi, '') .replace(//gi, '') .replace(//gi, '\n') .replace(/<\/p>/gi, '\n') @@ -490,7 +508,6 @@ export async function extractTextFromUploadedFile(file: { buffer: Buffer; mimety .trim(); const cleaned = sanitizePostgresText(plainText); - // Sadece tek başına "content.xml" veya "content.xmlPK" olan kısa çöp dizgileri süz (Gerçek metinleri kesinlikle engelleme) const isExactZipHeader = /^content\.xml(PK)?$/i.test(cleaned.trim()) && cleaned.length < 35; if (cleaned.length > 5 && !cleaned.startsWith('PK') && !isExactZipHeader) { return cleaned;