Vary number of decimals of file sizes
This commit is contained in:
@@ -775,10 +775,9 @@ export function Lightbox({
|
||||
{attachment.totalDownloaded && attachment.size
|
||||
? i18n('icu:lightBoxDownloading', {
|
||||
downloaded: formatFileSize(
|
||||
attachment.totalDownloaded,
|
||||
2
|
||||
attachment.totalDownloaded
|
||||
),
|
||||
total: formatFileSize(attachment.size, 2),
|
||||
total: formatFileSize(attachment.size),
|
||||
})
|
||||
: undefined}
|
||||
</Toast>
|
||||
|
@@ -126,7 +126,7 @@ export function AttachmentDetailPill({
|
||||
);
|
||||
text = (
|
||||
<div className="AttachmentDetailPill__text-wrapper">
|
||||
{formatFileSize(totalSize, 2)}
|
||||
{formatFileSize(totalSize)}
|
||||
</div>
|
||||
);
|
||||
} else if (totalDownloadedSize > 0) {
|
||||
@@ -148,9 +148,9 @@ export function AttachmentDetailPill({
|
||||
text = (
|
||||
<div className="AttachmentDetailPill__text-wrapper">
|
||||
{totalDownloadedSize > 0 && areAnyPending
|
||||
? `${formatFileSize(totalDownloadedSize, 2)} / `
|
||||
? `${formatFileSize(totalDownloadedSize)} / `
|
||||
: undefined}
|
||||
{formatFileSize(totalSize, 2)}
|
||||
{formatFileSize(totalSize)}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
@@ -165,7 +165,7 @@ export function AttachmentDetailPill({
|
||||
);
|
||||
text = (
|
||||
<div className="AttachmentDetailPill__text-wrapper">
|
||||
{formatFileSize(totalSize, 2)}
|
||||
{formatFileSize(totalSize)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -191,9 +191,9 @@ export function AttachmentDetailPill({
|
||||
<div className="AttachmentDetailPill">
|
||||
<div className="AttachmentDetailPill__text-wrapper">
|
||||
{totalDownloadedSize > 0 && areAnyPending
|
||||
? `${formatFileSize(totalDownloadedSize, 2)} / `
|
||||
? `${formatFileSize(totalDownloadedSize)} / `
|
||||
: undefined}
|
||||
{formatFileSize(totalSize, 2)}
|
||||
{formatFileSize(totalSize)}
|
||||
{isGif ? ' · GIF' : undefined}
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -2,6 +2,9 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import filesize from 'filesize';
|
||||
|
||||
export function formatFileSize(size: number, decimals = 0): string {
|
||||
return filesize(size, { round: decimals });
|
||||
// Intentional, `filesize` uses `jedec` standard by default
|
||||
const MB = 1000 * 1000;
|
||||
|
||||
export function formatFileSize(size: number): string {
|
||||
return filesize(size, { round: size < MB ? 0 : 1 });
|
||||
}
|
||||
|
Reference in New Issue
Block a user