diff --git a/backend/src/utils/pdf.ts b/backend/src/utils/pdf.ts index a231a40..c997cd2 100644 --- a/backend/src/utils/pdf.ts +++ b/backend/src/utils/pdf.ts @@ -2,6 +2,9 @@ import {PDFDocument, StandardFonts, rgb} from "pdf-lib" import dayjs from "dayjs" import {renderAsCurrency, splitStringBySpace} from "./stringRendering"; import {FastifyInstance} from "fastify"; +import { GetObjectCommand } from "@aws-sdk/client-s3"; +import { s3 } from "./s3"; +import { secrets } from "./secrets"; const getCoordinatesForPDFLib = (x:number ,y:number, page:any) => { /* @@ -25,9 +28,21 @@ const getCoordinatesForPDFLib = (x:number ,y:number, page:any) => { const getBackgroundSourceBuffer = async (server:FastifyInstance, path:string) => { - const {data:backgroundPDFData,error:backgroundPDFError} = await server.supabase.storage.from("files").download(path) + console.log(path) - return backgroundPDFData.arrayBuffer() + const { Body } = await s3.send( + new GetObjectCommand({ + Bucket: secrets.S3_BUCKET, + Key: path + }) + ) + + const chunks: Buffer[] = [] + for await (const chunk of Body as any) { + chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)) + } + + return Buffer.concat(chunks) } const getDuration = (time) => {