Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
FileWidget: Fix size format
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Aug 17, 2020
1 parent f327f6b commit 8d13b1a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/components/theme/Widgets/FileWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { flattenToAppURL } from '@plone/volto/helpers';
const niceBytes = (bytes) => {
bytes = Number(bytes);

const divider = 1000;
const divider = 1024;
const magnitude = (Math.log(bytes) / Math.log(divider)) | 0;
const result = bytes / Math.pow(divider, magnitude);
const fixed = result.toFixed(2);
const fixed = result.toFixed(0);

const suffix = magnitude ? 'kMGTPEZY'[magnitude - 1] + 'B' : 'B';

Expand All @@ -22,7 +22,7 @@ export const FileWidget = ({ value, children, className }) => {

const url = flattenToAppURL(value.download || value.filename || value);
const filename = value.filename || url;
const size = value.size || 0;
const size = value.data ? value.data.length * 0.75 : value.size || 0;
const ctype = value['content-type'] || '';
return (
<a
Expand Down
4 changes: 2 additions & 2 deletions src/components/theme/Widgets/ImageWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { flattenToAppURL } from '@plone/volto/helpers';
const niceBytes = (bytes) => {
bytes = Number(bytes);

const divider = 1000;
const divider = 1024;
const magnitude = (Math.log(bytes) / Math.log(divider)) | 0;
const result = bytes / Math.pow(divider, magnitude);
const fixed = result.toFixed(2);
const fixed = result.toFixed(0);

const suffix = magnitude ? 'kMGTPEZY'[magnitude - 1] + 'B' : 'B';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`FileWidget renders a file view widget component 1`] = `
className="metadata file widget"
data-content-type=""
data-size={0}
data-size-fmt="0.00B"
data-size-fmt="0B"
href="/foo-bar.pdf"
title="/foo-bar.pdf"
>
Expand All @@ -18,7 +18,7 @@ exports[`FileWidget renders a file view widget component with children 1`] = `
className="metadata file widget"
data-content-type="application/x-pdf"
data-size={123456}
data-size-fmt="123.46kB"
data-size-fmt="121kB"
href="/foo-bar.pdf"
title="application/x-pdf"
>
Expand All @@ -33,7 +33,7 @@ exports[`FileWidget renders a simple file view widget component 1`] = `
className="metadata file widget"
data-content-type=""
data-size={0}
data-size-fmt="0.00B"
data-size-fmt="0B"
href="/foo-bar.pdf"
title="/foo-bar.pdf"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`ImageWidget renders an image view widget component 1`] = `
alt=""
data-content-type=""
data-size={0}
data-size-fmt="0.00B"
data-size-fmt="0B"
src="/foo-bar.png"
/>
</span>
Expand All @@ -24,7 +24,7 @@ exports[`ImageWidget renders an image view widget component with children 1`] =
alt="foo-bar.png"
data-content-type=""
data-size={0}
data-size-fmt="0.00B"
data-size-fmt="0B"
src="/foo-bar.png"
/>
</span>
Expand Down

0 comments on commit 8d13b1a

Please sign in to comment.