From 1ca5d3ea078ef51818657e2b3c9f114c67bff86d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 19 Feb 2021 20:04:15 +0100 Subject: [PATCH] Added download option to cards --- src/controllers/PdfController.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/PdfController.ts b/src/controllers/PdfController.ts index ab12874..0aad6c7 100644 --- a/src/controllers/PdfController.ts +++ b/src/controllers/PdfController.ts @@ -37,7 +37,7 @@ export class PdfController { @Post('/cards') @OpenAPI({ description: "Generate runner card pdfs from runner card objects.
You can choose your prefered locale by passing the 'locale' query-param." }) - async generateCards(@Body({ validate: true, options: { limit: "500mb" } }) cards: RunnerCard | RunnerCard[], @Res() res: any, @QueryParam("locale") locale: string) { + async generateCards(@Body({ validate: true, options: { limit: "500mb" } }) cards: RunnerCard | RunnerCard[], @Res() res: any, @QueryParam("locale") locale: string, @QueryParam("download") download: boolean) { if (!this.initialized) { await this.pdf.init(); this.initialized = true; @@ -48,6 +48,9 @@ export class PdfController { cards = this.mapCardGroupNames(cards); const contracts = await this.pdf.generateRunnerCards(cards, locale); res.setHeader('content-type', 'application/pdf'); + if (download) { + res.setHeader('Content-Disposition', 'attachment; filename="cards.pdf"') + } return contracts; }