1- const { unpack} = require ( '@shelf/aws-lambda-brotli-unpacker' ) ;
2- const { execSync} = require ( 'child_process' ) ;
3- const path = require ( 'path' ) ;
4- const defaultArgs = require ( './args' ) ;
5- const { cleanupTempFiles } = require ( './cleanup' ) ;
1+ import { unpack } from '@shelf/aws-lambda-brotli-unpacker' ;
2+ import { execSync } from 'child_process' ;
3+ import path from 'path' ;
4+ import { cleanupTempFiles } from './cleanup' ;
5+ import defaultArgsJSON from './args.json' ;
66
7- module . exports . defaultArgs = defaultArgs ;
7+ export const defaultArgs = defaultArgsJSON ;
88
99const inputPath = path . join ( __dirname , '..' , 'bin' , 'lo.tar.br' ) ;
1010const outputPath = '/tmp/instdir/program/soffice' ;
1111
12- // see https://github.com/alixaxel/chrome-aws-lambda
13- module . exports . getExecutablePath = async function ( ) {
14- cleanupTempFiles ( ) ;
15-
16- return unpack ( { inputPath, outputPath} ) ;
17- } ;
18-
1912/**
2013 * Converts a file in /tmp to PDF
2114 * @param {String } filePath Absolute path to file to convert located in /tmp directory
2215 * @return {Promise<String> } Logs from spawning LibreOffice process
2316 */
24- module . exports . convertFileToPDF = async function ( filePath ) {
25- const binary = await module . exports . getExecutablePath ( ) ;
17+ export async function convertFileToPDF ( filePath ) : Promise < string > {
18+ const binary = await getExecutablePath ( ) ;
2619
2720 const logs = execSync (
2821 `cd /tmp && ${ binary } ${ defaultArgs . join ( ' ' ) } --convert-to pdf --outdir /tmp ${ filePath } `
@@ -31,4 +24,11 @@ module.exports.convertFileToPDF = async function(filePath) {
3124 execSync ( `rm /tmp/${ filePath } ` ) ;
3225
3326 return logs . toString ( 'utf8' ) ;
34- } ;
27+ }
28+
29+ // see https://github.com/alixaxel/chrome-aws-lambda
30+ export async function getExecutablePath ( ) : Promise < string > {
31+ cleanupTempFiles ( ) ;
32+
33+ return unpack ( { inputPath, outputPath} ) ;
34+ }
0 commit comments