Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(status-store): serve status media stored without a mimetype
Yudhi Armyndharis328d7e84f905
diff --git a/src/modules/status-store/status-store.service.spec.ts b/src/modules/status-store/status-store.service.spec.tsindex 1444fcd29..f6292ea66 100644--- a/src/modules/status-store/status-store.service.spec.ts+++ b/src/modules/status-store/status-store.service.spec.ts@@ -200,6 +200,21 @@ describe('StatusStoreService (ingest / list / getMedia)', () => {expect(media?.path).toContain('statuses/sess/');});+ // A status whose media arrived without a type still has its bytes stored and its mediaUrl+ // advertised, so the URL has to resolve; the media endpoint serves an unknown type as inert bytes.+ it('getMedia serves stored media that arrived without a mimetype as octet-stream', async () => {+ await service.ingest('sess', {+ waStatusId: 'untyped',+ contactJid: '[email protected]',+ type: 'image',+ media: { mimetype: '', data: Buffer.from('raw').toString('base64') },+ postedAt: Date.now(),+ });+ const media = await service.getMedia('sess', 'untyped');+ expect(media?.mimetype).toBe('application/octet-stream');+ expect(media?.path).toContain('statuses/sess/');+ });+it('getMedia returns null for an omitted-media status', async () => {expect(await service.getMedia('sess', 'w3')).toBeNull();});diff --git a/src/modules/status-store/status-store.service.ts b/src/modules/status-store/status-store.service.tsindex 91e193ae8..b9fda1969 100644--- a/src/modules/status-store/status-store.service.ts+++ b/src/modules/status-store/status-store.service.ts@@ -311,8 +311,10 @@ export class StatusStoreService implements OnModuleInit, OnModuleDestroy {const row = await this.repository.findOne({where: { sessionId, waStatusId: statusId, expiresAt: MoreThan(Date.now()) },});- if (!row || row.mediaOmitted || !row.mediaPath || !row.mediaMimetype) return null;- return { path: row.mediaPath, mimetype: row.mediaMimetype };+ // Same condition toStatus() advertises a mediaUrl on. Media stored without a type (an engine that+ // reported none) is still served, as octet-stream.+ if (!row || row.mediaOmitted || !row.mediaPath) return null;+ return { path: row.mediaPath, mimetype: row.mediaMimetype || 'application/octet-stream' };}/**