@opengis/fastify-table
Version:
core-plugins
20 lines (19 loc) • 687 B
JavaScript
import path from "node:path";
import { mkdir, writeFile } from "node:fs/promises";
import grpc from "../grpc.js";
const { htmlToPdf } = grpc();
export default async function html2pdf({ html, filepath, logger }) {
const time = Date.now();
try {
const result = await 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 };
}
}