mirror of
https://github.com/C4illin/ConvertX.git
synced 2025-11-02 04:53:22 +00:00
qsimple text files
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user