From 482421f10e85d14178f9d10e707286a4d5cf3a80 Mon Sep 17 00:00:00 2001 From: Jason Fu Date: Thu, 26 Jun 2025 04:53:37 +0200 Subject: [PATCH] qsimple text files --- src/converters/libreoffice.ts | 44 +++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/converters/libreoffice.ts b/src/converters/libreoffice.ts index 87441e0..d6d7b66 100644 --- a/src/converters/libreoffice.ts +++ b/src/converters/libreoffice.ts @@ -5,10 +5,43 @@ export const properties = { text: ["docx", "txt"], }, to: { - text: ["pdf", "txt"], + text: [ + "doc", + "dot", + "fodt", + "htm", + "html", + "odt", + "pdf", + "rtf", + "sxw", //bugged + "txt", + "wps", + "wpt", + "xhtml", + "xml", + ], }, }; +const filterNames: Record = { + //default + doc: "doc", + dot: "dot", + fodt: "fodt", + htm: "htm", + html: "html", + odt: "odt", + rtf: "rtf", + sxw: "sxw", + pdf: "pdf", + txt: "txt", + wps: "wps", + wpt: "wpt", + xhtml: "xhtml", + xml: "xml", +}; + export function convert( filePath: string, fileType: string, @@ -18,11 +51,18 @@ export function convert( options?: unknown, ): Promise { const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", ""); + const filterName = filterNames[convertTo]; + + if (!filterName) { + console.error("Unable to resolve file extension to filtername"); + return Promise.reject("Something went wrong"); + } + // Build arguments array const args: string[] = []; args.push("--headless"); - args.push("--convert-to", convertTo, filePath); + args.push("--convert-to", filterName, filePath); args.push("--outdir", outputPath); return new Promise((resolve, reject) => {