1- import { execSync } from 'child_process' ;
1+ import childProcess from 'child_process' ;
2+ import util from 'util' ;
23import { cleanupTempFiles } from './cleanup' ;
34import { getConvertedFilePath } from './logs' ;
45
6+ const exec = util . promisify ( childProcess . exec ) ;
7+
58export const DEFAULT_ARGS = [
69 '--headless' ,
710 '--invisible' ,
@@ -13,8 +16,8 @@ export const DEFAULT_ARGS = [
1316] ;
1417const LO_BINARY_PATH = 'libreoffice7.4' ;
1518
16- export function convertTo ( filename : string , format : string ) : string {
17- cleanupTempFiles ( ) ;
19+ export async function convertTo ( filename : string , format : string ) : Promise < string > {
20+ await cleanupTempFiles ( ) ;
1821
1922 const argumentsString = DEFAULT_ARGS . join ( ' ' ) ;
2023 const outputFilename = filename . split ( / \\ / ) . join ( ' ' ) ;
@@ -25,13 +28,13 @@ export function convertTo(filename: string, format: string): string {
2528
2629 // due to an unknown issue, we need to run command twice
2730 try {
28- logs = execSync ( cmd ) ;
31+ logs = ( await exec ( cmd ) ) . stdout ;
2932 } catch ( e ) {
30- logs = execSync ( cmd ) ;
33+ logs = ( await exec ( cmd ) ) . stdout ;
3134 }
3235
33- execSync ( `rm '/tmp/${ outputFilename } '` ) ;
34- cleanupTempFiles ( ) ;
36+ await exec ( `rm '/tmp/${ outputFilename } '` ) ;
37+ await cleanupTempFiles ( ) ;
3538
3639 return getConvertedFilePath ( logs . toString ( ) ) ;
3740}
0 commit comments