const AdmZip = require("adm-zip"); function parseUDF(buffer) { try { const zip = new AdmZip(buffer); const zipEntries = zip.getEntries(); const contentEntry = zipEntries.find((entry) => entry.entryName === "content.xml" || entry.entryName.endsWith(".xml")); if (!contentEntry) { throw new Error("No XML content found inside UDF/ZIP"); } const xmlData = zip.readAsText(contentEntry); // Remove XML tags and replace with space, then replace multiple spaces with single space const plainText = xmlData.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim(); return plainText; } catch (err) { console.error("UDF parse error:", err); return ""; } } console.log("ok");