Skip to content

Commit 9f73c27

Browse files
Merge pull request #42 from appwrite/storage-2
feat: add suggested extensions to storage setting screen
2 parents bae16bf + 6bef14f commit 9f73c27

File tree

7 files changed

+247
-240
lines changed

7 files changed

+247
-240
lines changed

src/lib/elements/forms/inputTags.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</div>
8989
<input
9090
{id}
91-
{placeholder}
91+
placeholder={!tags.length ? placeholder : ''}
9292
type="text"
9393
class="tags-input-text"
9494
bind:value

src/lib/elements/pill.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
export let disabled = false;
3+
export let selected = false;
34
export let success = false;
45
export let warning = false;
56
export let danger = false;
@@ -18,6 +19,7 @@
1819
rel={external ? 'noopener noreferrer' : ''}
1920
class="tag"
2021
class:is-disabled={disabled}
22+
class:is-selected={selected}
2123
class:is-success={success}
2224
class:is-warning={warning}
2325
class:is-danger={danger}
@@ -31,6 +33,7 @@
3133
type={submit ? 'submit' : 'button'}
3234
class="tag"
3335
class:is-disabled={disabled}
36+
class:is-selected={selected}
3437
class:is-success={success}
3538
class:is-warning={warning}
3639
class:is-danger={danger}
@@ -41,6 +44,7 @@
4144
<div
4245
class="tag"
4346
class:is-disabled={disabled}
47+
class:is-selected={selected}
4448
class:is-success={success}
4549
class:is-warning={warning}
4650
class:is-danger={danger}

src/lib/helpers/sizeConvertion.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
export function bytesToSize(bytes: number, decimals = 1) {
1+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
2+
3+
export function calculateSize(bytes: number, decimals = 1) {
24
if (bytes === 0) return '0 Bytes';
35

46
const k = 1024;
57
const dm = decimals < 0 ? 0 : decimals;
6-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
78

89
const i = Math.floor(Math.log(bytes) / Math.log(k));
910

1011
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
1112
}
1213

1314
export function sizeToBytes(value: number, unit: string) {
14-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
1515
const index = sizes.indexOf(unit);
1616
return value * Math.pow(1024, index);
1717
}
18+
export function bytesToSize(value: number, unit: string) {
19+
const index = sizes.indexOf(unit);
20+
return value / Math.pow(1024, index);
21+
}

src/routes/console/[project]/storage/bucket/[bucket]/_create.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { page } from '$app/stores';
88
import { uploader } from '$lib/stores/uploader';
99
import { bucket } from './store';
10-
import { bytesToSize } from '$lib/helpers/sizeConvertion';
10+
import { calculateSize } from '$lib/helpers/sizeConvertion';
1111
1212
export let showCreate = false;
1313
@@ -120,7 +120,7 @@
120120
</div>
121121
</div>
122122

123-
<p>Max file size: {bytesToSize($bucket.maximumFileSize)}</p>
123+
<p>Max file size: {calculateSize($bucket.maximumFileSize)}</p>
124124
</div>
125125

126126
{#if !showDropdown}

src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date';
88
import { sdkForProject } from '$lib/stores/sdk';
99
import { addNotification } from '$lib/stores/notifications';
10-
import { bytesToSize } from '$lib/helpers/sizeConvertion';
10+
import { calculateSize } from '$lib/helpers/sizeConvertion';
1111
import Delete from './_deleteFile.svelte';
1212
import { page } from '$app/stores';
1313
import { onMount } from 'svelte';
@@ -101,7 +101,7 @@
101101
<svelte:fragment slot="aside">
102102
<div>
103103
<p>MIME Type: {$file.mimeType}</p>
104-
<p>Size: {bytesToSize($file.sizeOriginal)}</p>
104+
<p>Size: {calculateSize($file.sizeOriginal)}</p>
105105
<p>Created: {toLocaleDate($file.$createdAt)}</p>
106106
<p>Last Updated: {toLocaleDate($file.$updatedAt)}</p>
107107
</div>

src/routes/console/[project]/storage/bucket/[bucket]/index.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
TableCell
1818
} from '$lib/elements/table';
1919
import { toLocaleDate } from '$lib/helpers/date';
20-
import { bytesToSize } from '$lib/helpers/sizeConvertion';
20+
import { calculateSize } from '$lib/helpers/sizeConvertion';
2121
import { Container } from '$lib/layout';
2222
import { base } from '$app/paths';
2323
import { files } from './store';
@@ -97,7 +97,7 @@
9797
</TableCell>
9898
<TableCellText title="Type">{file.mimeType}</TableCellText>
9999
<TableCellText title="Size"
100-
>{bytesToSize(file.sizeOriginal)}</TableCellText>
100+
>{calculateSize(file.sizeOriginal)}</TableCellText>
101101
<TableCellText title="Date Created"
102102
>{toLocaleDate(file.$createdAt)}</TableCellText>
103103
<TableCell>
@@ -132,7 +132,7 @@
132132
</TableCell>
133133
<TableCellText title="Type">{file.mimeType}</TableCellText>
134134
<TableCellText title="Size"
135-
>{bytesToSize(file.sizeOriginal)}</TableCellText>
135+
>{calculateSize(file.sizeOriginal)}</TableCellText>
136136
<TableCellText title="Date Created"
137137
>{toLocaleDate(file.$createdAt)}</TableCellText>
138138
<TableCell showOverflow>

0 commit comments

Comments
 (0)