Merge pull request #4274 from Yanyutin753/display_size

💄Feat show the size of file and prepare for subsequent upload restrictions
This commit is contained in:
Timothy Jaeryang Baek 2024-08-02 14:27:42 +02:00 committed by GitHub
commit f334c834e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 2 deletions

View File

@ -39,6 +39,7 @@
url={`${file?.url}`} url={`${file?.url}`}
name={file.name} name={file.name}
type={file.type} type={file.type}
size={file?.size}
dismissible={true} dismissible={true}
on:dismiss={() => { on:dismiss={() => {
// Remove the file from the chatFiles array // Remove the file from the chatFiles array

View File

@ -554,6 +554,7 @@
<FileItem <FileItem
name={file.name} name={file.name}
type={file.type} type={file.type}
size={file?.size}
status={file.status} status={file.status}
dismissible={true} dismissible={true}
on:dismiss={() => { on:dismiss={() => {

View File

@ -104,6 +104,7 @@
url={file.url} url={file.url}
name={file.name} name={file.name}
type={file.type} type={file.type}
size={file?.size}
colorClassName="bg-white dark:bg-gray-850 " colorClassName="bg-white dark:bg-gray-850 "
/> />
{/if} {/if}

View File

@ -15,6 +15,21 @@
export let name: string; export let name: string;
export let type: 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]}`;
}
</script> </script>
<div class="relative group"> <div class="relative group">
@ -93,11 +108,11 @@
</div> </div>
<div class="flex flex-col justify-center -space-y-0.5 pl-1.5 pr-4 w-full"> <div class="flex flex-col justify-center -space-y-0.5 pl-1.5 pr-4 w-full">
<div class=" dark:text-gray-100 text-sm font-medium line-clamp-1"> <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1 mb-1">
{name} {name}
</div> </div>
<div class=" text-gray-500 text-xs"> <div class=" flex justify-between text-gray-500 text-xs">
{#if type === 'file'} {#if type === 'file'}
{$i18n.t('File')} {$i18n.t('File')}
{:else if type === 'doc'} {:else if type === 'doc'}
@ -107,6 +122,9 @@
{:else} {:else}
<span class=" capitalize">{type}</span> <span class=" capitalize">{type}</span>
{/if} {/if}
{#if size}
<span class="capitalize">{formatSize(size)}</span>
{/if}
</div> </div>
</div> </div>
</button> </button>