Skip to content

Commit

Permalink
Merge pull request #745 from appwrite/fix-byte-sizes
Browse files Browse the repository at this point in the history
Fix-byte-sizes
  • Loading branch information
TorstenDittmann authored Jan 26, 2024
2 parents 7563d10 + 9e7982e commit 093fce6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/lib/helpers/sizeConvertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ export function bytesToSize(value: number, unit: Size) {
return value / Math.pow(1024, index);
}

export function humanFileSize(bytes: number): {
export function humanFileSize(
bytes: number,
useBits = false
): {
value: string;
unit: Size;
} {
if (typeof bytes !== 'number') return { value: '0', unit: 'Bytes' };
const value = prettyBytes(bytes, {
locale: 'en'
locale: 'en',
bits: useBits
}).split(' ');

return {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/helpers/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ export function createTimeUnitPair(initialValue = 0) {
return { ...createValueUnitPair(initialValue, units), units };
}

export function createByteUnitPair(initialValue = 0) {
export function createByteUnitPair(initialValue = 0, base = 1024) {
const units: Unit[] = [
{ name: 'Bytes', value: 1 },
{ name: 'Kilobytes', value: 1024 },
{ name: 'Megabytes', value: 1024 ** 2 },
{ name: 'Gigabytes', value: 1024 ** 3 }
{ name: 'Kilobytes', value: base },
{ name: 'Megabytes', value: base ** 2 },
{ name: 'Gigabytes', value: base ** 3 }
];
return { ...createValueUnitPair(initialValue, units), units };
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { updateBucket } from './+page.svelte';
const service = getServiceLimit('fileSize');
const { value, unit, baseValue, units } = createByteUnitPair($bucket.maximumFileSize);
const { value, unit, baseValue, units } = createByteUnitPair($bucket.maximumFileSize, 1000);
const options = units.map((v) => ({ label: v.name, value: v.name }));
function updateMaxSize() {
Expand All @@ -36,7 +36,7 @@
<p class="text">Set the maximum file size allowed in the bucket.</p>
<svelte:fragment slot="aside">
{#if isCloud}
{@const size = humanFileSize(sizeToBytes(service, 'GB', 1024))}
{@const size = humanFileSize(sizeToBytes(service, 'MB', 1000))}
{@const plan = tierToPlan($organization?.billingPlan)}
<Alert type="info">
<p class="text">
Expand Down

1 comment on commit 093fce6

@vercel
Copy link

@vercel vercel bot commented on 093fce6 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

console-cloud – ./

console-cloud-git-main-appwrite.vercel.app
console-cloud-appwrite.vercel.app
console-cloud.vercel.app

Please sign in to comment.