Skip to content

Commit dc8381a

Browse files
authored
Merge pull request #261 from iceljc/features/refine-chat-window
add chat file download
2 parents eb7cff2 + f022717 commit dc8381a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/lib/common/MessageFileGallery.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
return {
3636
file_name: item.file_name,
3737
file_extension: item.file_extension,
38-
file_data: isExternalUrl(item.file_url) ? item.file_url : `${PUBLIC_SERVICE_URL}${item.file_url}?access_token=${$userStore?.token}`
38+
file_data: isExternalUrl(item.file_url) ? item.file_url : `${PUBLIC_SERVICE_URL}${item.file_url}?access_token=${$userStore?.token}`,
39+
file_download_url: isExternalUrl(item.file_download_url) ? item.file_download_url : `${PUBLIC_SERVICE_URL}${item.file_download_url}?access_token=${$userStore?.token}`
3940
};
4041
});
4142
// @ts-ignore
@@ -50,6 +51,14 @@
5051
});
5152
}
5253
});
54+
55+
/** @param {number} idx */
56+
function handleDownloadFile(idx) {
57+
const found = textFiles.find((_, index) => index === idx);
58+
if (found?.file_download_url) {
59+
window.open(found.file_download_url);
60+
}
61+
}
5362
</script>
5463
5564
@@ -58,6 +67,8 @@
5867
containerStyles={galleryStyles}
5968
files={textFiles}
6069
showFileName
70+
needDownload
71+
onDownload={idx => handleDownloadFile(idx)}
6172
/>
6273
<AudioGallery
6374
id={messageId}

src/lib/helpers/types/fileTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @property {string} file_name - The file name.
1313
* @property {string} [file_extension] - The file extension.
1414
* @property {string} file_data - The file data or url.
15+
* @property {string} [file_download_url] - The file download url.
1516
*/
1617

1718
/**

0 commit comments

Comments
 (0)