qsimple text files
This commit is contained in:
parent
dcb15aee0e
commit
482421f10e
1 changed files with 42 additions and 2 deletions
|
|
@ -5,10 +5,43 @@ export const properties = {
|
||||||
text: ["docx", "txt"],
|
text: ["docx", "txt"],
|
||||||
},
|
},
|
||||||
to: {
|
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(
|
export function convert(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
fileType: string,
|
fileType: string,
|
||||||
|
|
@ -18,11 +51,18 @@ export function convert(
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", "");
|
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
|
// Build arguments array
|
||||||
const args: string[] = [];
|
const args: string[] = [];
|
||||||
|
|
||||||
args.push("--headless");
|
args.push("--headless");
|
||||||
args.push("--convert-to", convertTo, filePath);
|
args.push("--convert-to", filterName, filePath);
|
||||||
args.push("--outdir", outputPath);
|
args.push("--outdir", outputPath);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue