UNPKG

@opengis/fastify-table

Version:

core-plugins

24 lines (19 loc) 632 B
import { mkdir, writeFile } from 'fs/promises'; import path from 'path'; import grpc from '../grpc.js'; export default async function html2pdf({ html, filepath, logger, }) { const time = Date.now(); try { const result = await grpc.htmlToPdf({ html }); logger.file('format/pdf', { msec: Date.now() - time, resp_code: 200 }); if (result.err) throw new Error(result.err); await mkdir(path.dirname(filepath), { recursive: true }); await writeFile(filepath, result.result, 'base64'); return { filepath }; } catch (err) { return { err: err.toString(), status: 500 }; } }