From e5ddb4087a67626e515340b32c50e942db5a73d7 Mon Sep 17 00:00:00 2001 From: Santhosh Vaiyapuri Date: Thu, 23 Nov 2023 17:13:33 +0100 Subject: [PATCH] fix: filenames --- package/src/components/Channel/Channel.tsx | 2 +- .../messageInputContext/MessageInputContext.tsx | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package/src/components/Channel/Channel.tsx b/package/src/components/Channel/Channel.tsx index 7aaa83e32d..c9bf60153d 100644 --- a/package/src/components/Channel/Channel.tsx +++ b/package/src/components/Channel/Channel.tsx @@ -1306,6 +1306,7 @@ const ChannelWithContext = < isLocalUrl(attachment.image_url) ) { const filename = file.name ?? file.uri.replace(/^(file:\/\/|content:\/\/)/, ''); + // if any upload is in progress, cancel it const controller = uploadAbortControllerRef.current.get(filename); if (controller) { controller.abort(); @@ -1313,7 +1314,6 @@ const ChannelWithContext = < } const contentType = lookup(filename) || 'multipart/form-data'; - // if any upload is in progress, cancel it const uploadResponse = doImageUploadRequest ? await doImageUploadRequest(file, channel) : await channel.sendImage(file.uri, filename, contentType); diff --git a/package/src/contexts/messageInputContext/MessageInputContext.tsx b/package/src/contexts/messageInputContext/MessageInputContext.tsx index 1a2795c1e6..edf762ba79 100644 --- a/package/src/contexts/messageInputContext/MessageInputContext.tsx +++ b/package/src/contexts/messageInputContext/MessageInputContext.tsx @@ -641,20 +641,25 @@ export const MessageInputProvider = < setText(''); }; - const mapImageUploadToAttachment = (image: ImageUpload) => { + const mapImageUploadToAttachment = (image: ImageUpload): Attachment => { const mime_type: string | boolean = lookup(image.file.filename as string); + const name = image.file.name ?? (image.file.filename as string); return { - fallback: image.file.name, + fallback: name, image_url: image.url, mime_type: mime_type ? mime_type : undefined, original_height: image.height, original_width: image.width, - originalFile: image.file, + originalFile: { + ...image.file, + duration: image.file.duration ? `${image.file.duration}` : undefined, + name, + }, type: 'image', - } as Attachment; + }; }; - const mapFileUploadToAttachment = (file: FileUpload) => { + const mapFileUploadToAttachment = (file: FileUpload): Attachment => { if (file.file.mimeType?.startsWith('image/')) { return { fallback: file.file.name,