@opengis/fastify-table
Version:
core-plugins
19 lines (17 loc) • 509 B
JavaScript
import { mkdir, writeFile } from 'fs/promises';
import path from 'path';
import grpc from '../grpc.js';
export default async function html2pdf({
html, filepath,
}) {
const result = await grpc.htmlToImg({ html });
if (result.err) throw new Error(result.err);
try {
await mkdir(path.dirname(filepath), { recursive: true });
await writeFile(filepath, result.result, 'base64');
return { filepath };
}
catch (err) {
return { err: err.toString(), status: 500 };
}
}