Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions routes/invoiceDownload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 path from 'path'
import fs from 'fs'

const INVOICE_ROOT = path.resolve('ftp/invoices')

// Serves a previously generated invoice PDF back to the customer.
module.exports = function invoiceDownload () {
return (req: Request, res: Response, next: NextFunction) => {
const file = req.params.file
fs.readFile(path.join(INVOICE_ROOT, file), (error, data) => {
if (error != null) {
next(error)
return
}
res.type('application/pdf').send(data)
})
}
}