Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): post a picked status image with its own type

Yudhi Armyndharisbab501991f65
diff --git a/dashboard/src/components/chats/StatusComposeModal.test.ts b/dashboard/src/components/chats/StatusComposeModal.test.ts
index a007a84db..4d4e7fa9b 100644
--- a/dashboard/src/components/chats/StatusComposeModal.test.ts
+++ b/dashboard/src/components/chats/StatusComposeModal.test.ts
@@ -108,3 +108,21 @@ test('an oversized pick also drops the earlier pick it was meant to replace', as
// The input now reads "No file chosen", so nothing on screen shows the earlier image any more.
assert.equal(post.disabled, true, 'the hidden earlier pick can still be posted');
});
+
+test('a picked image is posted with its own type', async () => {
+ const { screen, fireEvent, waitFor } = rtl;
+ render();
+ fireEvent.click(screen.getByRole('button', { name: 'Image' }));
+ fireEvent.change(screen.getByLabelText('Status image'), {
+ target: { files: [new window.File(['x'], 'chart.png', { type: 'image/png' })] },
+ });
+ const post = screen.getByRole('button', { name: 'Post' }) as HTMLButtonElement;
+ await waitFor(() => assert.equal(post.disabled, false));
+ fireEvent.click(post);
+
+ await waitFor(() => assert.equal(posted.length, 1));
+ assert.deepEqual((posted[0] as { image: unknown }).image, {
+ base64: 'data:image/png;base64,eA==',
+ mimetype: 'image/png',
+ });
+});
diff --git a/dashboard/src/components/chats/StatusComposeModal.tsx b/dashboard/src/components/chats/StatusComposeModal.tsx
index 48391a3b9..89a6c953a 100644
--- a/dashboard/src/components/chats/StatusComposeModal.tsx
+++ b/dashboard/src/components/chats/StatusComposeModal.tsx
@@ -150,7 +150,11 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {
font: composeFont === '' ? undefined : Number(composeFont),
});
} else {
- const image = composeImageBase64 ? { base64: composeImageBase64 } : { url: composeImageUrl.trim() };
+ // The gateway drops the data URL's prefix and labels bare base64 image/jpeg unless told otherwise,
+ // so the picked file's type travels as `mimetype`. A file with no image type leaves the default.
+ const image = composeImageBase64
+ ? { base64: composeImageBase64, mimetype: /^data:(image\/[^;,]+)/.exec(composeImageBase64)?.[1] }
+ : { url: composeImageUrl.trim() };
await sessionApi.postImageStatus(sessionId, image, recipients, composeCaption.trim() || undefined);
}
showSuccessToast(t('chats.status.posted'));