draft implementation
This commit is contained in:
parent
482421f10e
commit
78f52c769d
1 changed files with 106 additions and 25 deletions
|
|
@ -2,20 +2,71 @@ import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
text: ["docx", "txt"],
|
text: [
|
||||||
|
"602",
|
||||||
|
"abw",
|
||||||
|
"csv",
|
||||||
|
"cwk",
|
||||||
|
"doc",
|
||||||
|
"docm",
|
||||||
|
"docx",
|
||||||
|
"dot",
|
||||||
|
"dotx",
|
||||||
|
"dotm",
|
||||||
|
"epub",
|
||||||
|
"fb2",
|
||||||
|
"fodt",
|
||||||
|
"htm",
|
||||||
|
"html",
|
||||||
|
"hwp",
|
||||||
|
"mcw",
|
||||||
|
"mw",
|
||||||
|
"mwd",
|
||||||
|
"lwp",
|
||||||
|
"lrf",
|
||||||
|
"odt",
|
||||||
|
"ott",
|
||||||
|
"pages",
|
||||||
|
"pdf",
|
||||||
|
"psw",
|
||||||
|
"rtf",
|
||||||
|
"sdw",
|
||||||
|
"stw",
|
||||||
|
"sxw",
|
||||||
|
"tab",
|
||||||
|
"tsv",
|
||||||
|
"txt",
|
||||||
|
"wn",
|
||||||
|
"wpd",
|
||||||
|
"wps",
|
||||||
|
"wpt",
|
||||||
|
"wri",
|
||||||
|
"xhtml",
|
||||||
|
"xml",
|
||||||
|
"zabw",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
text: [
|
text: [
|
||||||
|
"csv",
|
||||||
"doc",
|
"doc",
|
||||||
|
"docm",
|
||||||
|
"docx",
|
||||||
"dot",
|
"dot",
|
||||||
|
"dotx",
|
||||||
|
"dotm",
|
||||||
|
"epub",
|
||||||
"fodt",
|
"fodt",
|
||||||
"htm",
|
"htm",
|
||||||
"html",
|
"html",
|
||||||
"odt",
|
"odt",
|
||||||
|
"ott",
|
||||||
"pdf",
|
"pdf",
|
||||||
"rtf",
|
"rtf",
|
||||||
"sxw", //bugged
|
"tab",
|
||||||
|
"tsv",
|
||||||
"txt",
|
"txt",
|
||||||
|
"wpd",
|
||||||
"wps",
|
"wps",
|
||||||
"wpt",
|
"wpt",
|
||||||
"xhtml",
|
"xhtml",
|
||||||
|
|
@ -24,22 +75,48 @@ export const properties = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const filterNames: Record<string, string> = {
|
// input/output files parsing method
|
||||||
//default
|
const filters: Record<string, string> = {
|
||||||
doc: "doc",
|
"602": "T602Document",
|
||||||
dot: "dot",
|
abw: "AbiWord",
|
||||||
fodt: "fodt",
|
csv: "Text",
|
||||||
htm: "htm",
|
cwk: "ClarisWorks",
|
||||||
html: "html",
|
doc: "MS Word 97",
|
||||||
odt: "odt",
|
docm: "MS Word 2007 XML VBA",
|
||||||
rtf: "rtf",
|
docx: "MS Word 2007 XML",
|
||||||
sxw: "sxw",
|
dot: "MS Word 97 Vorlage",
|
||||||
pdf: "pdf",
|
dotx: "MS Word 2007 XML Template",
|
||||||
txt: "txt",
|
dotm: "MS Word 2007 XML Template",
|
||||||
wps: "wps",
|
epub: "EPUB",
|
||||||
wpt: "wpt",
|
fb2: "Fictionbook 2",
|
||||||
xhtml: "xhtml",
|
fodt: "OpenDocument Text Flat XML",
|
||||||
xml: "xml",
|
htm: "HTML (StarWriter)",
|
||||||
|
html: "HTML (StarWriter)",
|
||||||
|
hwp: "writer_MIZI_Hwp_97",
|
||||||
|
mcw: "MacWrite",
|
||||||
|
mw: "MacWrite",
|
||||||
|
mwd: "Mariner_Write",
|
||||||
|
lwd: "LotusWordPro",
|
||||||
|
lrf: "BroadBand eBook",
|
||||||
|
odt: "writer8",
|
||||||
|
ott: "writer8_template",
|
||||||
|
pages: "Apple Pages",
|
||||||
|
//pdf should differentiate between import and export just leave as default for now
|
||||||
|
psw: "PocketWord File",
|
||||||
|
rtf: "Rich Text Format",
|
||||||
|
sdw: "StarOffice_Writer",
|
||||||
|
stw: "writer_StarOffice_XML_Writer_Template",
|
||||||
|
sxw: "StarOffice XML (Writer)",
|
||||||
|
tab: "Text",
|
||||||
|
tsv: "Text",
|
||||||
|
txt: "Text",
|
||||||
|
wn: "WriteNow",
|
||||||
|
wpd: "WordPerfect",
|
||||||
|
wps: "MS Word 97",
|
||||||
|
wpt: "MS Word 97 Vorlage",
|
||||||
|
wri: "MS_Write",
|
||||||
|
xhtml: "HTML (StarWriter)",
|
||||||
|
zabw: "AbiWord",
|
||||||
};
|
};
|
||||||
|
|
||||||
export function convert(
|
export function convert(
|
||||||
|
|
@ -51,20 +128,24 @@ 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", filterName, filePath);
|
|
||||||
args.push("--outdir", outputPath);
|
args.push("--outdir", outputPath);
|
||||||
|
|
||||||
|
const inFilter = filters[fileType];
|
||||||
|
if (inFilter) {
|
||||||
|
args.push(`--infilter="${inFilter}"`);
|
||||||
|
}
|
||||||
|
const outFilter = filters[convertTo];
|
||||||
|
if (outFilter) {
|
||||||
|
args.push("--convert-to", `"${convertTo}:${outFilter}"`, filePath);
|
||||||
|
} else {
|
||||||
|
args.push("--convert-to", convertTo, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
execFile("soffice", args, (error, stdout, stderr) => {
|
execFile("soffice", args, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue