diff --git a/src/lib/components/chat/Controls/Controls.svelte b/src/lib/components/chat/Controls/Controls.svelte index 4e4198e53..4e3968f49 100644 --- a/src/lib/components/chat/Controls/Controls.svelte +++ b/src/lib/components/chat/Controls/Controls.svelte @@ -39,6 +39,7 @@ url={`${file?.url}`} name={file.name} type={file.type} + size={file?.size} dismissible={true} on:dismiss={() => { // Remove the file from the chatFiles array diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 2fa835acd..2e1e4b98e 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -554,6 +554,7 @@ { diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index 748fcd61b..22b7081d7 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -104,6 +104,7 @@ url={file.url} name={file.name} type={file.type} + size={file?.size} colorClassName="bg-white dark:bg-gray-850 " /> {/if} diff --git a/src/lib/components/common/FileItem.svelte b/src/lib/components/common/FileItem.svelte index 6ae011cae..f4dfd27e7 100644 --- a/src/lib/components/common/FileItem.svelte +++ b/src/lib/components/common/FileItem.svelte @@ -15,6 +15,21 @@ export let name: string; export let type: string; + export let size: number; + + function formatSize(size) { + if (size == null) return 'Unknown size'; + if (typeof size !== 'number' || size < 0) return 'Invalid size'; + if (size === 0) return '0 B'; + const units = ['B', 'KB', 'MB', 'GB', 'TB']; + let unitIndex = 0; + + while (size >= 1024 && unitIndex < units.length - 1) { + size /= 1024; + unitIndex++; + } + return `${size.toFixed(1)} ${units[unitIndex]}`; + }
@@ -93,11 +108,11 @@
-
+
{name}
-
+
{#if type === 'file'} {$i18n.t('File')} {:else if type === 'doc'} @@ -107,6 +122,9 @@ {:else} {type} {/if} + {#if size} + {formatSize(size)} + {/if}