diff --git a/src/controllers/document.controller.ts b/src/controllers/document.controller.ts index a9db548..fd0d9b4 100644 --- a/src/controllers/document.controller.ts +++ b/src/controllers/document.controller.ts @@ -490,7 +490,9 @@ export async function extractTextFromUploadedFile(file: { buffer: Buffer; mimety .trim(); const cleaned = sanitizePostgresText(plainText); - if (cleaned.length > 5 && !cleaned.startsWith('PK')) { + // Akıllı filtreleme: content.xml, content.xmlPK gibi ZIP başlık isimlerini metin sanma + const isZipNoise = /^content\.xml/i.test(cleaned) || cleaned.includes('content.xmlPK') || cleaned.includes('documentproperties.xml'); + if (cleaned.length > 5 && !cleaned.startsWith('PK') && !isZipNoise) { return cleaned; } } @@ -507,7 +509,7 @@ export async function extractTextFromUploadedFile(file: { buffer: Buffer; mimety } } - // 3. ZIP çözülemediyse ham buffer içinden okunabilir Türkçe metin bloklarını çek + // 3. ZIP çözülemediyse ham buffer içinden okunabilir Türkçe metin bloklarını çek (İkili / ZIP başlık verisini süz) let rawText = ''; try { rawText = iconv.decode(file.buffer, 'iso-8859-9'); } catch (_) { rawText = file.buffer.toString('utf8'); } @@ -515,19 +517,27 @@ export async function extractTextFromUploadedFile(file: { buffer: Buffer; mimety if (textMatches && textMatches.length > 0) { const cleanExtracted = textMatches .map(m => m.trim()) - .filter(m => m.length > 8 && !m.includes('documentproperties') && !m.includes('sign.sgn') && !m.startsWith('PK')) + .filter(m => { + const lower = m.toLowerCase(); + return m.length > 8 && + !lower.includes('documentproperties') && + !lower.includes('content.xml') && + !lower.includes('sign.sgn') && + !lower.includes('manifest.xml') && + !m.startsWith('PK'); + }) .join('\n'); const cleaned = sanitizePostgresText(cleanExtracted); - if (cleaned.length > 10) { + if (cleaned.length > 10 && !cleaned.toLowerCase().includes('content.xml')) { return cleaned; } } - return `[UDF Belgesi: ${file.originalname} (İçerik e-imzalı kilitli veya taranmış görsellidir)]`; + return `[UDF Belgesi: ${file.originalname} (İçerik e-imzalı kilitli veya metinsizdir)]`; } catch (err: any) { console.error("UDF parse error:", err); - return `[UDF Belgesi: ${file.originalname} - Ek metin olarak eklendi]`; + return `[UDF Belgesi: ${file.originalname} - Şablon olarak yüklendi]`; } }