1+ "use strict" ;
2+
3+ Object . defineProperty ( exports , "__esModule" , {
4+ value : true
5+ } ) ;
6+ exports . DEFAULT_ARGS = void 0 ;
7+ exports . convertTo = convertTo ;
8+ var _child_process = _interopRequireDefault ( require ( "child_process" ) ) ;
9+ var _util = _interopRequireDefault ( require ( "util" ) ) ;
10+ var _cleanup = require ( "./cleanup" ) ;
11+ var _logs = require ( "./logs" ) ;
12+ function _interopRequireDefault ( e ) { return e && e . __esModule ? e : { default : e } ; }
13+ const exec = _util . default . promisify ( _child_process . default . exec ) ;
14+ const DEFAULT_ARGS = [ '--headless' , '--invisible' , '--nodefault' , '--view' , '--nolockcheck' , '--nologo' , '--norestore' ] ;
15+ exports . DEFAULT_ARGS = DEFAULT_ARGS ;
16+ const LO_BINARY_PATH = process . env . LO_BINARY_PATH ?? 'libreoffice7.6' ;
17+ async function convertTo ( filename , format ) {
18+ await ( 0 , _cleanup . cleanupTempFiles ) ( ) ;
19+ const argumentsString = DEFAULT_ARGS . join ( ' ' ) ;
20+ const outputFilename = filename . split ( / \\ / ) . join ( ' ' ) ;
21+ const cmd = `cd /tmp && ${ LO_BINARY_PATH } ${ argumentsString } --convert-to ${ format } --outdir /tmp '/tmp/${ outputFilename } '` ;
22+ let logs ;
23+
24+ // due to an unknown issue, we need to run command twice
25+ try {
26+ logs = ( await exec ( cmd ) ) . stdout ;
27+ } catch ( e ) {
28+ logs = ( await exec ( cmd ) ) . stdout ;
29+ }
30+ await exec ( `rm '/tmp/${ outputFilename } '` ) ;
31+ await ( 0 , _cleanup . cleanupTempFiles ) ( ) ;
32+ return ( 0 , _logs . getConvertedFilePath ) ( logs . toString ( ) ) ;
33+ }
0 commit comments