pass options to html2png

This commit is contained in:
hazycora 2023-08-03 09:49:25 -05:00
parent f6627672c9
commit 6876c5689e
No known key found for this signature in database
GPG key ID: 215AF1F81F86940E
2 changed files with 14 additions and 10 deletions

View file

@ -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) {

View file

@ -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']