Merge pull request #745 from appwrite/fix-byte-sizes

Fix-byte-sizes
This commit is contained in:
Torsten Dittmann
2024-01-26 13:08:10 +01:00
committed by GitHub
3 changed files with 12 additions and 8 deletions
+6 -2
View File
@@ -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 {
+4 -4
View File
@@ -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 };
}
@@ -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() {
@@ -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">