Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
refactor(dashboard): share the upload size limit
Yudhi Armyndharis3f8f5c8a595e
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsxindex 45bf4039a..8ef03800f 100644--- a/dashboard/src/components/chats/ChatComposer.tsx+++ b/dashboard/src/components/chats/ChatComposer.tsx@@ -9,6 +9,7 @@ import { messagesQueryKey, useChatMessagesActions, upsertCachedMessage } from '.import { useRole } from '../../hooks/useRole';import { useToast } from '../../hooks/useToast';import type { ScrollDirection } from '../../utils/scrollDecision';+import { MEDIA_UPLOAD_MAX_BYTES } from '../../utils/mediaUpload';// Map an attachment MIME type to the neutral MessageType for the optimistic outgoing bubble, so the// placeholder matches what the backend will persist (e.g. a PDF is `document`, not `application`).@@ -19,11 +20,6 @@ const messageTypeFromMime = (mimetype: string): MessageType => {return 'document';};-// Client pre-check before base64-encoding an upload, same cap as the message tester: base64-// inflates ~1.33x, so ~18 MiB raw stays under the backend's default 25 MiB body limit and the-// pick fails here with a toast instead of OOMing the tab on the FileReader.-export const MEDIA_UPLOAD_MAX_BYTES = 18 * 1024 * 1024;-/** A picked-but-unsent file, staged until send, removal, or a move to another chat. */export interface StagedAttachment {file: File;diff --git a/dashboard/src/components/chats/StatusComposeModal.tsx b/dashboard/src/components/chats/StatusComposeModal.tsxindex 1571a5266..243557d24 100644--- a/dashboard/src/components/chats/StatusComposeModal.tsx+++ b/dashboard/src/components/chats/StatusComposeModal.tsx@@ -6,7 +6,7 @@ import { contactApi, sessionApi } from '../../services/api';import { useRole } from '../../hooks/useRole';import { useToast } from '../../hooks/useToast';import { Modal } from '../Modal';-import { MEDIA_UPLOAD_MAX_BYTES } from './ChatComposer';+import { MEDIA_UPLOAD_MAX_BYTES } from '../../utils/mediaUpload';import { captionLength } from '../../utils/bulkMedia';// Mirrors @ArrayMaxSize(256) on the send-status DTOs — the picker caps selection client-side so thediff --git a/dashboard/src/pages/MessageTester.tsx b/dashboard/src/pages/MessageTester.tsxindex 34668f812..f7b2b025f 100644--- a/dashboard/src/pages/MessageTester.tsx+++ b/dashboard/src/pages/MessageTester.tsx@@ -33,6 +33,7 @@ import { groupLabel, isGatewayRefusal, planGroupSend } from '../utils/groupSelecimport { sendSequentially } from '../utils/sendSequentially';import { keepsSameKey } from '../utils/authLifecycle';import './MessageTester.css';+import { MEDIA_UPLOAD_MAX_BYTES } from '../utils/mediaUpload';interface ApiResponse {success: boolean;@@ -115,12 +116,6 @@ const fallbackMime: Record<(typeof messageTypes)[number], string> = {bulk: 'application/octet-stream',};-// Client pre-check before base64-encoding an upload. Aligned with the default request-body limit: base64-// inflates ~1.33x, so ~18 MiB raw stays under the 25 MiB BODY_SIZE_LIMIT and lets the backend reject with a-// clear 413 instead of the tab OOMing on a multi-hundred-MB pick before the request is even sent. The-// backend's MEDIA_DOWNLOAD_MAX_BYTES (default 50 MiB) stays authoritative for URL sends (fetched server-side).-const MEDIA_UPLOAD_MAX_BYTES = 18 * 1024 * 1024;-// Batch statuses that stop the progress polling (mirrors the backend BatchStatus enum).const TERMINAL_BATCH_STATUSES: readonly BatchStatus[] = ['completed', 'cancelled', 'failed'];diff --git a/dashboard/src/utils/mediaUpload.ts b/dashboard/src/utils/mediaUpload.tsnew file mode 100644index 000000000..0cf8a1888--- /dev/null+++ b/dashboard/src/utils/mediaUpload.ts@@ -0,0 +1,5 @@+// Client pre-check before base64-encoding an upload. Aligned with the default request-body limit: base64+// inflates ~1.33x, so ~18 MiB raw stays under the 25 MiB BODY_SIZE_LIMIT and lets the backend reject with a+// clear 413 instead of the tab OOMing on a multi-hundred-MB pick before the request is even sent. The+// backend's MEDIA_DOWNLOAD_MAX_BYTES (default 50 MiB) stays authoritative for URL sends (fetched server-side).+export const MEDIA_UPLOAD_MAX_BYTES = 18 * 1024 * 1024;