fix: improve UDF xml text extraction buffer reading
This commit is contained in:
@@ -449,7 +449,18 @@ export async function extractTextFromUploadedFile(file: { buffer: Buffer; mimety
|
|||||||
|
|
||||||
// Eğer XML bulunmuşsa XML üzerinden devam et
|
// Eğer XML bulunmuşsa XML üzerinden devam et
|
||||||
if (xmlEntry) {
|
if (xmlEntry) {
|
||||||
const rawXml = zip.readAsText(xmlEntry);
|
let rawXml = '';
|
||||||
|
try {
|
||||||
|
const entryBuffer = xmlEntry.getData();
|
||||||
|
// UDF belgeleri UTF-8 veya ISO-8859-9 / Windows-1254 (Türkçe) kodlamasına sahip olabilir
|
||||||
|
rawXml = entryBuffer.toString('utf8');
|
||||||
|
if (rawXml.includes('encoding="ISO-8859-9"') || rawXml.includes('encoding="windows-1254"')) {
|
||||||
|
// iconv-lite or fallback string replacement if needed
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
rawXml = zip.readAsText(xmlEntry);
|
||||||
|
}
|
||||||
|
|
||||||
if (rawXml && rawXml.trim()) {
|
if (rawXml && rawXml.trim()) {
|
||||||
const plainText = rawXml.replace(/<style[\s\S]*?<\/style>/gi, '')
|
const plainText = rawXml.replace(/<style[\s\S]*?<\/style>/gi, '')
|
||||||
.replace(/<br\s*\/?>/gi, '\n')
|
.replace(/<br\s*\/?>/gi, '\n')
|
||||||
|
|||||||
Reference in New Issue
Block a user