Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(status): let a URL's Content-Type label status media sent untyped
Yudhi Armyndharis70fb0a0843c7
diff --git a/src/modules/status/status.service.spec.ts b/src/modules/status/status.service.spec.tsindex 0c4190516..188fe58f2 100644--- a/src/modules/status/status.service.spec.ts+++ b/src/modules/status/status.service.spec.ts@@ -328,6 +328,37 @@ describe('StatusService media validation and selection', () => {});});+ // A URL's bytes come with the host's Content-Type, which the engines use unless the caller declared+ // a type; octet-stream is the placeholder they read as "undeclared". Only base64 has nothing to go on.+ it('defaults the mimetype for base64 only, and leaves an undeclared URL type to the fetched one', async () => {+ const url = 'https://example.com/banner.png';+ await service.postImageStatus('s1', { url }, { recipients: ['[email protected]'] });+ await service.postVideoStatus('s1', { url }, { recipients: ['[email protected]'] });+ await service.postImageStatus('s1', { base64: 'QUJD' }, { recipients: ['[email protected]'] });+ await service.postVideoStatus('s1', { base64: 'QUJD' }, { recipients: ['[email protected]'] });++ expect(engine.postImageStatus).toHaveBeenNthCalledWith(+ 1,+ { mimetype: 'application/octet-stream', data: url },+ expect.anything(),+ );+ expect(engine.postImageStatus).toHaveBeenNthCalledWith(+ 2,+ { mimetype: 'image/jpeg', data: 'QUJD' },+ expect.anything(),+ );+ expect(engine.postVideoStatus).toHaveBeenNthCalledWith(+ 1,+ { mimetype: 'application/octet-stream', data: url },+ expect.anything(),+ );+ expect(engine.postVideoStatus).toHaveBeenNthCalledWith(+ 2,+ { mimetype: 'video/mp4', data: 'QUJD' },+ expect.anything(),+ );+ });+it('strips a data-URI prefix before handing base64 bytes to either engine path', async () => {const prefixed = 'data:image/png;base64,QUJD';await service.postImageStatus('s1', { base64: prefixed, mimetype: 'image/png' }, { recipients: ['[email protected]'] });diff --git a/src/modules/status/status.service.ts b/src/modules/status/status.service.tsindex cb11945e2..8564bf8b8 100644--- a/src/modules/status/status.service.ts+++ b/src/modules/status/status.service.ts@@ -158,7 +158,9 @@ export class StatusService {() => new NotFoundException(`Session ${sessionId} not found or not connected`),);const gated = await this.gate(sessionId, 'status-image', {- media: { mimetype: mimetype ?? 'image/jpeg', data: base64 || url || '' },+ // A URL with no declared type keeps the placeholder the engines read as "undeclared", so the+ // fetched Content-Type labels the bytes (as on the chat path); the route default is for base64.+ media: { mimetype: mimetype ?? (base64 ? 'image/jpeg' : 'application/octet-stream'), data: base64 || url || '' },options,});return this.recordedPost(sessionId, () => engine.postImageStatus(this.guardGatedMedia(gated.media), gated.options));@@ -181,7 +183,7 @@ export class StatusService {() => new NotFoundException(`Session ${sessionId} not found or not connected`),);const gated = await this.gate(sessionId, 'status-video', {- media: { mimetype: mimetype ?? 'video/mp4', data: base64 || url || '' },+ media: { mimetype: mimetype ?? (base64 ? 'video/mp4' : 'application/octet-stream'), data: base64 || url || '' },options,});return this.recordedPost(sessionId, () => engine.postVideoStatus(this.guardGatedMedia(gated.media), gated.options));