From 6876c5689ebbb8ad89fadd0fc697b206be2e42de Mon Sep 17 00:00:00 2001 From: hazycora Date: Thu, 3 Aug 2023 09:49:25 -0500 Subject: [PATCH] pass options to html2png --- lib/render.js | 4 ++-- server.js | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/render.js b/lib/render.js index b39d37c..da6e52f 100644 --- a/lib/render.js +++ b/lib/render.js @@ -116,8 +116,8 @@ const renderOptions = { ] } -export default async function (html) { - return html2png(html, css, renderOptions) +export default async function (html, options = {}) { + return html2png(html, css, { ...renderOptions, ...options }) } export async function renderHtml(html) { diff --git a/server.js b/server.js index d218c60..0ce9da0 100644 --- a/server.js +++ b/server.js @@ -81,9 +81,10 @@ app.get('/:owner/:repo', async function (req, res) { res.send(await renderHtml(html)) return } - res.type('png') + const format = req.query.format == 'svg' ? 'svg' : 'png' + res.type(format) res.set('Content-Disposition', 'inline') - res.send(await render(html)) + res.send(await render(html, { format })) }) app.get('/:owner/:repo/commit/:hash', async function (req, res) { @@ -127,9 +128,10 @@ app.get('/:owner/:repo/commit/:hash', async function (req, res) { res.send(await renderHtml(html)) return } - res.type('png') + const format = req.query.format == 'svg' ? 'svg' : 'png' + res.type(format) res.set('Content-Disposition', 'inline') - res.send(await render(html)) + res.send(await render(html, { format })) }) app.get('/:owner/:repo/:type/:num', (req, res, next) => { @@ -172,9 +174,10 @@ app.get('/:owner/:repo/issues/:num', async function (req, res) { res.send(await renderHtml(html)) return } - res.type('png') + const format = req.query.format == 'svg' ? 'svg' : 'png' + res.type(format) res.set('Content-Disposition', 'inline') - res.send(await render(html)) + res.send(await render(html, { format })) }) app.get('/:owner/:repo/pulls/:num', async function (req, res) { @@ -223,9 +226,10 @@ app.get('/:owner/:repo/pulls/:num', async function (req, res) { res.send(await renderHtml(html)) return } - res.type('png') + const format = req.query.format == 'svg' ? 'svg' : 'png' + res.type(format) res.set('Content-Disposition', 'inline') - res.send(await render(html)) + res.send(await render(html, { format })) }) const [port, host] = [process.env.PORT ?? 9054, process.env.HOST ?? '127.0.0.1']