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