Skip to content

Commit

Permalink
add chat file download
Browse files Browse the repository at this point in the history
  • Loading branch information
Jicheng Lu committed Nov 5, 2024
1 parent eb7cff2 commit f022717
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib/common/MessageFileGallery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
</script>
Expand All @@ -58,6 +67,8 @@
containerStyles={galleryStyles}
files={textFiles}
showFileName
needDownload
onDownload={idx => handleDownloadFile(idx)}
/>
<AudioGallery
id={messageId}
Expand Down
1 change: 1 addition & 0 deletions src/lib/helpers/types/fileTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property {string} file_name - The file name.
* @property {string} [file_extension] - The file extension.
* @property {string} file_data - The file data or url.
* @property {string} [file_download_url] - The file download url.
*/

/**
Expand Down

0 comments on commit f022717

Please sign in to comment.