Skip to content

Commit 093fce6

Browse files
Merge pull request #745 from appwrite/fix-byte-sizes
Fix-byte-sizes
2 parents 7563d10 + 9e7982e commit 093fce6

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/lib/helpers/sizeConvertion.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ export function bytesToSize(value: number, unit: Size) {
2424
return value / Math.pow(1024, index);
2525
}
2626

27-
export function humanFileSize(bytes: number): {
27+
export function humanFileSize(
28+
bytes: number,
29+
useBits = false
30+
): {
2831
value: string;
2932
unit: Size;
3033
} {
3134
if (typeof bytes !== 'number') return { value: '0', unit: 'Bytes' };
3235
const value = prettyBytes(bytes, {
33-
locale: 'en'
36+
locale: 'en',
37+
bits: useBits
3438
}).split(' ');
3539

3640
return {

src/lib/helpers/unit.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ export function createTimeUnitPair(initialValue = 0) {
7373
return { ...createValueUnitPair(initialValue, units), units };
7474
}
7575

76-
export function createByteUnitPair(initialValue = 0) {
76+
export function createByteUnitPair(initialValue = 0, base = 1024) {
7777
const units: Unit[] = [
7878
{ name: 'Bytes', value: 1 },
79-
{ name: 'Kilobytes', value: 1024 },
80-
{ name: 'Megabytes', value: 1024 ** 2 },
81-
{ name: 'Gigabytes', value: 1024 ** 3 }
79+
{ name: 'Kilobytes', value: base },
80+
{ name: 'Megabytes', value: base ** 2 },
81+
{ name: 'Gigabytes', value: base ** 3 }
8282
];
8383
return { ...createValueUnitPair(initialValue, units), units };
8484
}

src/routes/console/project-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import { updateBucket } from './+page.svelte';
1515
1616
const service = getServiceLimit('fileSize');
17-
const { value, unit, baseValue, units } = createByteUnitPair($bucket.maximumFileSize);
17+
const { value, unit, baseValue, units } = createByteUnitPair($bucket.maximumFileSize, 1000);
1818
const options = units.map((v) => ({ label: v.name, value: v.name }));
1919
2020
function updateMaxSize() {
@@ -36,7 +36,7 @@
3636
<p class="text">Set the maximum file size allowed in the bucket.</p>
3737
<svelte:fragment slot="aside">
3838
{#if isCloud}
39-
{@const size = humanFileSize(sizeToBytes(service, 'GB', 1024))}
39+
{@const size = humanFileSize(sizeToBytes(service, 'MB', 1000))}
4040
{@const plan = tierToPlan($organization?.billingPlan)}
4141
<Alert type="info">
4242
<p class="text">

0 commit comments

Comments
 (0)