libreoffice-convert 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +19 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -10,11 +10,12 @@ const { execFile } = require('child_process');
|
|
|
10
10
|
const convertWithOptions = (document, format, filter, options, callback) => {
|
|
11
11
|
const tmpOptions = (options || {}).tmpOptions || {};
|
|
12
12
|
const asyncOptions = (options || {}).asyncOptions || {};
|
|
13
|
+
const execOptions = (options || {}).execOptions || {};
|
|
13
14
|
const tempDir = tmp.dirSync({prefix: 'libreofficeConvert_', unsafeCleanup: true, ...tmpOptions});
|
|
14
15
|
const installDir = tmp.dirSync({prefix: 'soffice', unsafeCleanup: true, ...tmpOptions});
|
|
15
16
|
return async.auto({
|
|
16
17
|
soffice: (callback) => {
|
|
17
|
-
let paths = (options || {}).sofficeBinaryPaths
|
|
18
|
+
let paths = (options || {}).sofficeBinaryPaths || [];
|
|
18
19
|
switch (process.platform) {
|
|
19
20
|
case 'darwin': paths = [...paths, '/Applications/LibreOffice.app/Contents/MacOS/soffice'];
|
|
20
21
|
break;
|
|
@@ -45,13 +46,18 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
45
46
|
},
|
|
46
47
|
saveSource: callback => fs.writeFile(path.join(tempDir.name, 'source'), document, callback),
|
|
47
48
|
convert: ['soffice', 'saveSource', (results, callback) => {
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
let filterParam = filter?.length ? `:${filter}` : "";
|
|
50
|
+
let fmt = !(filter ?? "").includes(" ") ? `${format}${filterParam}` : `"${format}${filterParam}"`;
|
|
51
|
+
let args = [];
|
|
52
|
+
args.push(`-env:UserInstallation=${url.pathToFileURL(installDir.name)}`);
|
|
53
|
+
args.push('--headless');
|
|
54
|
+
args.push('--convert-to');
|
|
55
|
+
args.push(fmt);
|
|
56
|
+
args.push('--outdir');
|
|
57
|
+
args.push(tempDir.name);
|
|
58
|
+
args.push(path.join(tempDir.name, 'source'));
|
|
59
|
+
|
|
60
|
+
return execFile(results.soffice, args, execOptions, callback);
|
|
55
61
|
}],
|
|
56
62
|
loadDestination: ['convert', (results, callback) =>
|
|
57
63
|
async.retry({
|
|
@@ -59,15 +65,13 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
59
65
|
interval: asyncOptions.interval || 200
|
|
60
66
|
}, (callback) => fs.readFile(path.join(tempDir.name, `source.${format.split(":")[0]}`), callback), callback)
|
|
61
67
|
]
|
|
62
|
-
}
|
|
68
|
+
}).then( (res) => {
|
|
69
|
+
return callback(null, res.loadDestination);
|
|
70
|
+
}).catch( (err) => {
|
|
71
|
+
return callback(err);
|
|
72
|
+
}).finally( () => {
|
|
63
73
|
tempDir.removeCallback();
|
|
64
74
|
installDir.removeCallback();
|
|
65
|
-
|
|
66
|
-
if (err) {
|
|
67
|
-
return callback(err);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return callback(null, res.loadDestination);
|
|
71
75
|
});
|
|
72
76
|
};
|
|
73
77
|
|