From 32d72d535b3e6045d5576ec39a0c284665b6f312 Mon Sep 17 00:00:00 2001 From: Rohan Port Date: Thu, 25 Aug 2022 10:21:06 +1000 Subject: [PATCH 1/2] Renamed instances of Pdf with PDF - To maintain consistency with naming convention - Rule seems to be: use same case chars for pdf/PDF --- .../lesmis-server/src/routes/PDFExportRoute.ts | 4 ++-- packages/tsutils/src/PDFExporter.ts | 14 +++++++------- .../src/export/PDFExportHandler.js | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/lesmis-server/src/routes/PDFExportRoute.ts b/packages/lesmis-server/src/routes/PDFExportRoute.ts index 12229fb07c..1986d9e5db 100644 --- a/packages/lesmis-server/src/routes/PDFExportRoute.ts +++ b/packages/lesmis-server/src/routes/PDFExportRoute.ts @@ -5,7 +5,7 @@ */ import { Request, Response, NextFunction } from 'express'; import { Route } from '@tupaia/server-boilerplate'; -import { downloadPageAsPdf } from '@tupaia/tsutils'; +import { downloadPageAsPDF } from '@tupaia/tsutils'; type Body = { pdfPageUrl: string; @@ -28,7 +28,7 @@ export class PDFExportRoute extends Route { const { pdfPageUrl } = this.req.body; const { cookie, host: cookieDomain } = this.req.headers; - const buffer = await downloadPageAsPdf(pdfPageUrl, cookie, cookieDomain); + const buffer = await downloadPageAsPDF(pdfPageUrl, cookie, cookieDomain); this.res.set({ 'Content-Type': 'application/pdf', 'Content-Length': buffer.length, diff --git a/packages/tsutils/src/PDFExporter.ts b/packages/tsutils/src/PDFExporter.ts index fceeba61b6..4e2750039d 100644 --- a/packages/tsutils/src/PDFExporter.ts +++ b/packages/tsutils/src/PDFExporter.ts @@ -1,7 +1,7 @@ import cookie from 'cookie'; import puppeteer from 'puppeteer'; -const verifyPdfPageUrl = (pdfPageUrl: string): string => { +const verifyPDFPageUrl = (pdfPageUrl: string): string => { const lesmisValidDomains = ['lesmis.la', 'www.lesmis.la']; if (!pdfPageUrl || typeof pdfPageUrl !== 'string') { throw new Error(`'pdfPageUrl' should be provided in request body, got: ${pdfPageUrl}`); @@ -19,8 +19,8 @@ const verifyPdfPageUrl = (pdfPageUrl: string): string => { const buildParams = (pdfPageUrl: string, userCookie: string, cookieDomain: string | undefined) => { const cookies = cookie.parse(userCookie || ''); - const verifiedPdfPageUrl = verifyPdfPageUrl(pdfPageUrl); - const location = new URL(verifiedPdfPageUrl); + const verifiedPDFPageUrl = verifyPDFPageUrl(pdfPageUrl); + const location = new URL(verifiedPDFPageUrl); const finalisedCookieObjects = Object.keys(cookies).map(name => ({ name, domain: cookieDomain, @@ -28,7 +28,7 @@ const buildParams = (pdfPageUrl: string, userCookie: string, cookieDomain: strin httpOnly: true, value: cookies[name], })); - return { verifiedPdfPageUrl, cookies: finalisedCookieObjects }; + return { verifiedPDFPageUrl, cookies: finalisedCookieObjects }; }; /** @@ -37,20 +37,20 @@ const buildParams = (pdfPageUrl: string, userCookie: string, cookieDomain: strin * @param cookieDomain the domain of cookie, required when setting up cookie in page * @returns pdf buffer */ -export const downloadPageAsPdf = async ( +export const downloadPageAsPDF = async ( pdfPageUrl: string, userCookie = '', cookieDomain: string | undefined, ) => { let browser; let buffer; - const { cookies, verifiedPdfPageUrl } = buildParams(pdfPageUrl, userCookie, cookieDomain); + const { cookies, verifiedPDFPageUrl } = buildParams(pdfPageUrl, userCookie, cookieDomain); try { browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setCookie(...cookies); - await page.goto(verifiedPdfPageUrl, { timeout: 60000, waitUntil: 'networkidle0' }); + await page.goto(verifiedPDFPageUrl, { timeout: 60000, waitUntil: 'networkidle0' }); buffer = await page.pdf({ format: 'a4', printBackground: true, diff --git a/packages/web-config-server/src/export/PDFExportHandler.js b/packages/web-config-server/src/export/PDFExportHandler.js index 8286119992..683ee66e86 100644 --- a/packages/web-config-server/src/export/PDFExportHandler.js +++ b/packages/web-config-server/src/export/PDFExportHandler.js @@ -1,4 +1,4 @@ -import { downloadPageAsPdf } from '@tupaia/tsutils'; +import { downloadPageAsPDF } from '@tupaia/tsutils'; import { convertToCDNHost } from '@tupaia/utils'; export const PDFExportHandler = async (req, res) => { @@ -6,7 +6,7 @@ export const PDFExportHandler = async (req, res) => { const { cookie, host, via } = req.headers; const cookieDomain = via && via.includes('cloudfront.net') ? convertToCDNHost(host) : host; - const buffer = await downloadPageAsPdf(pdfPageUrl, cookie, cookieDomain); + const buffer = await downloadPageAsPDF(pdfPageUrl, cookie, cookieDomain); res.set({ 'Content-Type': 'application/pdf', 'Content-Length': buffer.length, From 28381306e2eee09c8f7574cff13e5009a7da5e0a Mon Sep 17 00:00:00 2001 From: Rohan Port Date: Thu, 25 Aug 2022 10:22:21 +1000 Subject: [PATCH 2/2] Renamed PDFExporter -> downloadPageAsPDF --- packages/tsutils/src/{PDFExporter.ts => downloadPageAsPDF.ts} | 0 packages/tsutils/src/index.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/tsutils/src/{PDFExporter.ts => downloadPageAsPDF.ts} (100%) diff --git a/packages/tsutils/src/PDFExporter.ts b/packages/tsutils/src/downloadPageAsPDF.ts similarity index 100% rename from packages/tsutils/src/PDFExporter.ts rename to packages/tsutils/src/downloadPageAsPDF.ts diff --git a/packages/tsutils/src/index.ts b/packages/tsutils/src/index.ts index b92628d5c2..5153655aff 100644 --- a/packages/tsutils/src/index.ts +++ b/packages/tsutils/src/index.ts @@ -1,3 +1,3 @@ export * from './validation'; export * from './types'; -export * from './PDFExporter'; +export * from './downloadPageAsPDF';