Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
Added chunking for larger thumbnails
Gaurav Bhatt3879670d38df
diff --git a/apps/erp/app/modules/shared/shared.service.ts b/apps/erp/app/modules/shared/shared.service.tsindex 7e648cc3e2..f16f040402 100644--- a/apps/erp/app/modules/shared/shared.service.ts+++ b/apps/erp/app/modules/shared/shared.service.ts@@ -48,7 +48,16 @@ export async function getBase64ImageFromSupabase(path: string) {function arrayBufferToBase64(buffer: ArrayBuffer): string {- const binary = String.fromCharCode(...new Uint8Array(buffer));+ // Use chunking for large objects to prevent stack overflow+ const bytes = new Uint8Array(buffer);+ const chunkSize = 8192;+ let binary = "";++ for (let i = 0; i < bytes.length; i += chunkSize) {+ const chunk = bytes.slice(i, i + chunkSize);+ binary += String.fromCharCode(...chunk);+ }+return btoa(binary);}@@ -57,17 +66,24 @@ export async function getBase64ImageFromSupabase(return null;}+ // Check file size before processingconst arrayBuffer = await data.arrayBuffer();- const base64String = arrayBufferToBase64(arrayBuffer);- // Determine the mime type based on file extension- const fileExtension = path.split(".").pop()?.toLowerCase();- const mimeType =- fileExtension === "jpg" || fileExtension === "jpeg"- ? "image/jpeg"- : "image/png";+ try {+ const base64String = arrayBufferToBase64(arrayBuffer);++ // Determine the mime type based on file extension+ const fileExtension = path.split(".").pop()?.toLowerCase();+ const mimeType =+ fileExtension === "jpg" || fileExtension === "jpeg"+ ? "image/jpeg"+ : "image/png";- return `data:${mimeType};base64,${base64String}`;+ return `data:${mimeType};base64,${base64String}`;+ } catch (err) {+ console.error(`Failed to convert image to base64: ${path}`, err);+ return null;+ }}export async function getCountries(client: SupabaseClient<Database>) {diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.tsxindex 0a2473eb6e..33999d526f 100644--- a/apps/erp/app/routes/x+/quote+/$quoteId.tsx+++ b/apps/erp/app/routes/x+/quote+/$quoteId.tsx@@ -61,21 +61,25 @@ export async function loader({ request, params }: LoaderFunctionArgs) {throw redirect(path.to.quotes);}- const [customer, shipment, payment, lines, prices, opportunity, methods] =- await Promise.all([- getCustomer(client, quote.data?.customerId ?? ""),- getQuoteShipment(client, quoteId),- getQuotePayment(client, quoteId),- getQuoteLines(client, quoteId),- getQuoteLinePricesByQuoteId(client, quoteId),- getOpportunity(client, quote.data?.opportunityId),- getQuoteMethodTrees(client, quoteId),- getOpportunityDocuments(- client,- companyId,- quote.data?.opportunityId ?? ""- ),- ]);+ const [+ customer,+ shipment,+ payment,+ lines,+ prices,+ opportunity,+ methods,+ opportunityDocuments,+ ] = await Promise.all([+ getCustomer(client, quote.data?.customerId ?? ""),+ getQuoteShipment(client, quoteId),+ getQuotePayment(client, quoteId),+ getQuoteLines(client, quoteId),+ getQuoteLinePricesByQuoteId(client, quoteId),+ getOpportunity(client, quote.data?.opportunityId),+ getQuoteMethodTrees(client, quoteId),+ getOpportunityDocuments(client, companyId, quote.data?.opportunityId ?? ""),+ ]);if (!opportunity.data) throw new Error("Failed to get opportunity record");@@ -128,11 +132,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {customer: customer.data,lines: lines.data ?? [],methods: methods.data ?? [],- files: getOpportunityDocuments(- client,- companyId,- quote.data?.opportunityId ?? ""- ),+ files: opportunityDocuments,prices: prices.data ?? [],shipment: shipment.data,payment: payment.data,