From f02271769fcab9d74c05c02145e075d4db9565f7 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 5 Nov 2024 00:30:17 -0600 Subject: [PATCH] add chat file download --- src/lib/common/MessageFileGallery.svelte | 13 ++++++++++++- src/lib/helpers/types/fileTypes.js | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/common/MessageFileGallery.svelte b/src/lib/common/MessageFileGallery.svelte index e2256f0e..d8ef4543 100644 --- a/src/lib/common/MessageFileGallery.svelte +++ b/src/lib/common/MessageFileGallery.svelte @@ -35,7 +35,8 @@ return { file_name: item.file_name, file_extension: item.file_extension, - file_data: isExternalUrl(item.file_url) ? item.file_url : `${PUBLIC_SERVICE_URL}${item.file_url}?access_token=${$userStore?.token}` + file_data: isExternalUrl(item.file_url) ? item.file_url : `${PUBLIC_SERVICE_URL}${item.file_url}?access_token=${$userStore?.token}`, + file_download_url: isExternalUrl(item.file_download_url) ? item.file_download_url : `${PUBLIC_SERVICE_URL}${item.file_download_url}?access_token=${$userStore?.token}` }; }); // @ts-ignore @@ -50,6 +51,14 @@ }); } }); + + /** @param {number} idx */ + function handleDownloadFile(idx) { + const found = textFiles.find((_, index) => index === idx); + if (found?.file_download_url) { + window.open(found.file_download_url); + } + } @@ -58,6 +67,8 @@ containerStyles={galleryStyles} files={textFiles} showFileName + needDownload + onDownload={idx => handleDownloadFile(idx)} />