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
|
||||
const filters: Record<string, string> = {
|
||||
type FileCategories = "text" | "calc";
|
||||
|
||||
const filters: Record<FileCategories, Record<string, string>> = {
|
||||
text: {
|
||||
"602": "T602Document",
|
||||
abw: "AbiWord",
|
||||
csv: "Text",
|
||||
cwk: "ClarisWorks",
|
||||
doc: "MS Word 97",
|
||||
docm: "MS Word 2007 XML VBA",
|
||||
docx: "MS Word 2007 XML",
|
||||
|
|
@ -101,7 +102,7 @@ const filters: Record<string, string> = {
|
|||
odt: "writer8",
|
||||
ott: "writer8_template",
|
||||
pages: "Apple Pages",
|
||||
//pdf should differentiate between import and export just leave as default for now
|
||||
// pdf: "writer_pdf_import",
|
||||
psw: "PocketWord File",
|
||||
rtf: "Rich Text Format",
|
||||
sdw: "StarOffice_Writer",
|
||||
|
|
@ -116,7 +117,19 @@ const filters: Record<string, string> = {
|
|||
wpt: "MS Word 97 Vorlage",
|
||||
wri: "MS_Write",
|
||||
xhtml: "HTML (StarWriter)",
|
||||
xml: "OpenDocument Text Flat XML",
|
||||
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(
|
||||
|
|
@ -131,19 +144,17 @@ export function convert(
|
|||
|
||||
// Build arguments array
|
||||
const args: string[] = [];
|
||||
|
||||
args.push("--headless");
|
||||
args.push("--outdir", outputPath);
|
||||
const [inFilter, outFilter] = getFilters(fileType, convertTo);
|
||||
|
||||
const inFilter = filters[fileType];
|
||||
if (inFilter) {
|
||||
args.push(`--infilter="${inFilter}"`);
|
||||
}
|
||||
const outFilter = filters[convertTo];
|
||||
|
||||
if (outFilter) {
|
||||
args.push("--convert-to", `"${convertTo}:${outFilter}"`, filePath);
|
||||
args.push("--convert-to", `${convertTo}:${outFilter}`, "--outdir", outputPath, filePath);
|
||||
} else {
|
||||
args.push("--convert-to", convertTo, filePath);
|
||||
args.push("--convert-to", convertTo, "--outdir", outputPath, filePath);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue