libreoffice-convert 1.4.1 → 1.5.1

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.
Files changed (2) hide show
  1. package/index.js +19 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -10,6 +10,7 @@ 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({
@@ -18,7 +19,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
18
19
  switch (process.platform) {
19
20
  case 'darwin': paths = [...paths, '/Applications/LibreOffice.app/Contents/MacOS/soffice'];
20
21
  break;
21
- case 'linux': paths = [...paths, '/usr/bin/libreoffice', '/usr/bin/soffice', '/snap/bin/libreoffice'];
22
+ case 'linux': paths = [...paths, '/usr/bin/libreoffice', '/usr/bin/soffice', '/snap/bin/libreoffice', '/opt/libreoffice/program/soffice', '/opt/libreoffice7.6/program/soffice'];
22
23
  break;
23
24
  case 'win32': paths = [
24
25
  ...paths,
@@ -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 command = `-env:UserInstallation=${url.pathToFileURL(installDir.name)} --headless --convert-to ${format}`;
49
- if (filter !== undefined) {
50
- command += `:"${filter}"`;
51
- }
52
- command += ` --outdir ${tempDir.name} ${path.join(tempDir.name, 'source')}`;
53
- const args = command.split(' ');
54
- return execFile(results.soffice, args, callback);
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
- }, (err, res) => {
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libreoffice-convert",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "A simple and fast node.js module for converting office documents to different formats",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",