Skip to content

Commit

Permalink
refactor(core): clean up unused code and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-sh committed Dec 3, 2024
1 parent e50d36f commit 6a777ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
57 changes: 34 additions & 23 deletions api/core/core.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import * as buffer from "node:buffer";

export const cloud = require("chrome-aws-lambda");

export function base64EncodedResponse(base64Encoded: Buffer, fileName) {
const response = {
headers: {
"Content-type": "application/pdf",
"content-disposition": `attachment; filename=${fileName}.pdf`,
},
statusCode: 200,
body: buffer.toString("base64"),
isBase64Encoded: true,
};
}
export function pdfResponse(pdf: Buffer, fileName: string) {
return base64EncodedResponse();
}
// import * as buffer from "node:buffer";
//
// export const cloud = require("chrome-aws-lambda");
//
// export function base64EncodedResponse(base64Encoded: ArrayBuffer, fileName) {
// const response = {
// headers: {
// "Content-type": "application/pdf",
// "content-disposition": `attachment; filename=${fileName}.pdf`,
// },
// statusCode: 200,
// body: buffer.toString("base64"),
// isBase64Encoded: true,
// };
// return response
// }
// export function pdfResponse(pdf: Buffer, fileName: string) {
// return base64EncodedResponse(pdf, fileName);
// }

export async function downloadPDF() {
// const cloud = require("@sparticuz/chromium");
// // biome-ignore lint/style/useSingleVarDeclarator: <explanation>
// const executablePath = await cloud.executablePath()
// const { chromium } = require("playwright-core");
const cloud = require("@sparticuz/chromium");
const executablePath = await cloud.executablePath();
const { chromium } = require("playwright-core");
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
let url: string;
url = "https://ax-sh.github.io/";
await page.goto(url);
// await page.close()
// await browser.close()
return { args: cloud.args, executablePath };

return pdfResponse(null, "portfolio.pdf");
//
// console.log( chromium.args)
//
// return pdfResponse(null, "portfolio.pdf");
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[functions]
node_bundler = "esbuild"
external_node_modules = ["@sparticuz/chromium"]
external_node_modules = ["@sparticuz/chromium", "playwright-core"]

# this is actually a Rewrite
# totally optional, but makes up for
Expand Down

0 comments on commit 6a777ea

Please sign in to comment.