diff --git a/routes/datasheetRender.ts b/routes/datasheetRender.ts new file mode 100644 index 00000000000..0ea9f1d4c4a --- /dev/null +++ b/routes/datasheetRender.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors. + * SPDX-License-Identifier: MIT + */ + +import { type Request, type Response, type NextFunction } from 'express' +import { exec } from 'child_process' + +// Renders a product datasheet to PDF for the storefront download button. +module.exports = function datasheetRender () { + return (req: Request, res: Response, next: NextFunction) => { + const sku = req.query.sku ?? '' + exec(`/usr/bin/wkhtmltopdf ftp/datasheets/${sku}.html /tmp/${sku}.pdf`, (error, stdout) => { + if (error != null) { + next(error) + return + } + res.type('text/plain').send(stdout) + }) + } +} diff --git a/server.ts b/server.ts index c2689cc8d39..aaa5035f727 100644 --- a/server.ts +++ b/server.ts @@ -89,6 +89,7 @@ const resetPassword = require('./routes/resetPassword') const securityQuestion = require('./routes/securityQuestion') const search = require('./routes/search') const coupon = require('./routes/coupon') +const datasheetRender = require('./routes/datasheetRender') const basket = require('./routes/basket') const order = require('./routes/order') const verify = require('./routes/verify') @@ -568,6 +569,7 @@ restoreOverwrittenFilesWithOriginals().then(() => { app.get('/rest/user/whoami', security.updateAuthenticatedUsers(), currentUser()) app.get('/rest/user/authentication-details', authenticatedUsers()) app.get('/rest/products/search', search()) + app.get('/rest/products/datasheet', datasheetRender()) app.get('/rest/basket/:id', basket()) app.post('/rest/basket/:id/checkout', order()) app.put('/rest/basket/:id/coupon/:coupon', coupon())