addedsperate filters per file category
This commit is contained in:
parent
78f52c769d
commit
8273a2a6a0
1 changed files with 59 additions and 48 deletions
|
|
@ -75,12 +75,13 @@ export const properties = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// input/output files parsing method
|
type FileCategories = "text" | "calc";
|
||||||
const filters: Record<string, string> = {
|
|
||||||
|
const filters: Record<FileCategories, Record<string, string>> = {
|
||||||
|
text: {
|
||||||
"602": "T602Document",
|
"602": "T602Document",
|
||||||
abw: "AbiWord",
|
abw: "AbiWord",
|
||||||
csv: "Text",
|
csv: "Text",
|
||||||
cwk: "ClarisWorks",
|
|
||||||
doc: "MS Word 97",
|
doc: "MS Word 97",
|
||||||
docm: "MS Word 2007 XML VBA",
|
docm: "MS Word 2007 XML VBA",
|
||||||
docx: "MS Word 2007 XML",
|
docx: "MS Word 2007 XML",
|
||||||
|
|
@ -101,7 +102,7 @@ const filters: Record<string, string> = {
|
||||||
odt: "writer8",
|
odt: "writer8",
|
||||||
ott: "writer8_template",
|
ott: "writer8_template",
|
||||||
pages: "Apple Pages",
|
pages: "Apple Pages",
|
||||||
//pdf should differentiate between import and export just leave as default for now
|
// pdf: "writer_pdf_import",
|
||||||
psw: "PocketWord File",
|
psw: "PocketWord File",
|
||||||
rtf: "Rich Text Format",
|
rtf: "Rich Text Format",
|
||||||
sdw: "StarOffice_Writer",
|
sdw: "StarOffice_Writer",
|
||||||
|
|
@ -116,7 +117,19 @@ const filters: Record<string, string> = {
|
||||||
wpt: "MS Word 97 Vorlage",
|
wpt: "MS Word 97 Vorlage",
|
||||||
wri: "MS_Write",
|
wri: "MS_Write",
|
||||||
xhtml: "HTML (StarWriter)",
|
xhtml: "HTML (StarWriter)",
|
||||||
|
xml: "OpenDocument Text Flat XML",
|
||||||
zabw: "AbiWord",
|
zabw: "AbiWord",
|
||||||
|
},
|
||||||
|
calc: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const getFilters = (fileType: string, converto: string) => {
|
||||||
|
if (fileType in filters.text && converto in filters.text) {
|
||||||
|
return [filters.text[fileType], filters.text[converto]];
|
||||||
|
} else if (fileType in filters.calc && converto in filters.calc) {
|
||||||
|
return [filters.calc[fileType], filters.calc[converto]];
|
||||||
|
}
|
||||||
|
return [null, null];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function convert(
|
export function convert(
|
||||||
|
|
@ -131,19 +144,17 @@ export function convert(
|
||||||
|
|
||||||
// Build arguments array
|
// Build arguments array
|
||||||
const args: string[] = [];
|
const args: string[] = [];
|
||||||
|
|
||||||
args.push("--headless");
|
args.push("--headless");
|
||||||
args.push("--outdir", outputPath);
|
const [inFilter, outFilter] = getFilters(fileType, convertTo);
|
||||||
|
|
||||||
const inFilter = filters[fileType];
|
|
||||||
if (inFilter) {
|
if (inFilter) {
|
||||||
args.push(`--infilter="${inFilter}"`);
|
args.push(`--infilter="${inFilter}"`);
|
||||||
}
|
}
|
||||||
const outFilter = filters[convertTo];
|
|
||||||
if (outFilter) {
|
if (outFilter) {
|
||||||
args.push("--convert-to", `"${convertTo}:${outFilter}"`, filePath);
|
args.push("--convert-to", `${convertTo}:${outFilter}`, "--outdir", outputPath, filePath);
|
||||||
} else {
|
} else {
|
||||||
args.push("--convert-to", convertTo, filePath);
|
args.push("--convert-to", convertTo, "--outdir", outputPath, filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue