qsimple text files

This commit is contained in:
Jason Fu
2025-06-26 04:53:37 +02:00
parent dcb15aee0e
commit 482421f10e

View File

@@ -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<string, string> = {
//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<string> {
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) => {