diff --git a/src/lib/components/bucket.svelte b/src/lib/components/bucket.svelte new file mode 100644 index 000000000..fd91e058b --- /dev/null +++ b/src/lib/components/bucket.svelte @@ -0,0 +1,19 @@ + + + +
+
+

+
+ +
+
+ +
+ +
+
diff --git a/src/lib/components/dropList.svelte b/src/lib/components/dropList.svelte index 114c4cfa8..251e532f8 100644 --- a/src/lib/components/dropList.svelte +++ b/src/lib/components/dropList.svelte @@ -20,7 +20,7 @@ -
+
{#if show}
export let icon = 'info'; export let aria = 'info'; + export let disabled = false; - -
+
    -
  • -
    -
    - % -
    - - -
  • -
  • -
    -
    - % -
    - - -
  • -
  • -
    -
    - % -
    - - -
  • + {#each $uploader.files as file} + {#if file.completed || file.progress === 100} +
  • +
    + +
    + + + +
  • + {:else if file.failed} +
  • +
    +
    + {file.progress}% +
    + + Failed + +
  • + {:else if file.cancelled} + cancelled? + {:else} +
  • +
    +
    + {file.progress}% +
    + + Pending + +
  • + {/if} + {/each}
{/if} - - diff --git a/src/lib/helpers/sizeConvertion.ts b/src/lib/helpers/sizeConvertion.ts new file mode 100644 index 000000000..e62d7a9f0 --- /dev/null +++ b/src/lib/helpers/sizeConvertion.ts @@ -0,0 +1,17 @@ +export function bytesToSize(bytes: number, decimals = 1) { + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} + +export function sizeToBytes(value: number, unit: string) { + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const index = sizes.indexOf(unit); + return value * Math.pow(1024, index); +} diff --git a/src/lib/stores/uploader.ts b/src/lib/stores/uploader.ts index b1571f4f1..6ca846214 100644 --- a/src/lib/stores/uploader.ts +++ b/src/lib/stores/uploader.ts @@ -3,6 +3,7 @@ import { writable } from 'svelte/store'; type UploaderFile = { $id: string; + bucketId: string; name: string; progress: number; completed: boolean; @@ -12,12 +13,14 @@ type UploaderFile = { }; export type Uploader = { isOpen: boolean; + isCollapsed: boolean; files: UploaderFile[]; }; const createUploader = () => { const { subscribe, set, update } = writable({ isOpen: false, + isCollapsed: false, files: [] }); @@ -35,17 +38,42 @@ const createUploader = () => { return { subscribe, - toggle: () => + + close: () => update((n) => { n.isOpen = !n.isOpen; + return n; + }), + toggle: () => + update((n) => { + n.isCollapsed = !n.isCollapsed; + return n; }), reset: () => set({ isOpen: false, + isCollapsed: false, files: [] }), + addFile: async (file: Models.File, isOpen = true, isCollapsed = false) => { + const newFile: UploaderFile = { + $id: file.$id, + bucketId: file.bucketId, + name: file.name, + progress: calculateProgress(file), + completed: calculateProgress(file) === 100 ? true : false, + failed: false, + cancelled: false + }; + return update((n) => { + n.isOpen = isOpen; + n.isCollapsed = isCollapsed; + n.files.unshift(newFile); + return n; + }); + }, removeFile: async (file: Models.File) => { if (file.chunksTotal === file.chunksUploaded) { return update((n) => { @@ -63,3 +91,8 @@ const createUploader = () => { }; export const uploader = createUploader(); + +function calculateProgress(file: Models.File) { + const progress = file.chunksUploaded / file.chunksTotal; + return Math.round(progress * 100); +} diff --git a/src/routes/console/[project]/storage/_create.svelte b/src/routes/console/[project]/storage/_create.svelte index c1031b9bf..8bd164664 100644 --- a/src/routes/console/[project]/storage/_create.svelte +++ b/src/routes/console/[project]/storage/_create.svelte @@ -1,6 +1,7 @@
- + Create Bucket - + + + + {#if !showDropdown} +
+ (showDropdown = !showDropdown)} + > +
+ {:else} + + Bucket ID +

Enter a custom bucket ID. Leave blank for a randomly generated bucket ID.

+ +
+ + +
+
+
+
+
+ {/if} +
- +
diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/__layout.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/__layout.svelte index 52877ed14..e70afc305 100644 --- a/src/routes/console/[project]/storage/bucket/[bucket]/__layout.svelte +++ b/src/routes/console/[project]/storage/bucket/[bucket]/__layout.svelte @@ -20,7 +20,7 @@ navigate: event, title: $bucket.name, copy: { - text: bucketId, + text: 'Bucket ID', value: bucketId }, tabs: [ diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/_create.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/_create.svelte index a885da6ee..19e08c5ed 100644 --- a/src/routes/console/[project]/storage/bucket/[bucket]/_create.svelte +++ b/src/routes/console/[project]/storage/bucket/[bucket]/_create.svelte @@ -1,25 +1,40 @@ + +
Upload File - - - + +
+
dropHandler(e)} + on:dragover|preventDefault={(e) => dragOverHandler(e)}> +
+
+
+
+

Drag and drop files here to upload

+
+ + {#if files?.length} + {files.item(0).name} + {/if} +
+
+
+
+ +

Max file size: {bytesToSize($bucket.maximumFileSize)}

+
+ + {#if !showDropdown} +
+ (showDropdown = !showDropdown)} + > +
+ {:else} + + File ID +

Enter a custom file ID. Leave blank for a randomly generated file ID.

+ +
+ + +
+
+
+
+
+ {/if} +

Permissions

+ +

+ Tip: Add role:all for wildcard access. Check out our documentation for more on + Permissions +

+
+ + +
diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/_deleteBucket.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/_deleteBucket.svelte new file mode 100644 index 000000000..550883a4b --- /dev/null +++ b/src/routes/console/[project]/storage/bucket/[bucket]/_deleteBucket.svelte @@ -0,0 +1,36 @@ + + + + + Delete Bucket +

Are you sure you want to delete {$bucket.name}?

+ + + + +
+ diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/_deleteFile.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/_deleteFile.svelte new file mode 100644 index 000000000..c05dbeb69 --- /dev/null +++ b/src/routes/console/[project]/storage/bucket/[bucket]/_deleteFile.svelte @@ -0,0 +1,37 @@ + + +
+ + Delete File +

Are you sure you want to delete {file.name}?

+ + + + +
+
diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/_update.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/_update.svelte deleted file mode 100644 index e28a18c0a..000000000 --- a/src/routes/console/[project]/storage/bucket/[bucket]/_update.svelte +++ /dev/null @@ -1,54 +0,0 @@ - - -
- - Update File - - - - - - - - -
diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/__layout.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/__layout.svelte new file mode 100644 index 000000000..51188ec58 --- /dev/null +++ b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/__layout.svelte @@ -0,0 +1,37 @@ + + + + Appwrite - File + + + diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/_deleteFile.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/_deleteFile.svelte new file mode 100644 index 000000000..b7276efbf --- /dev/null +++ b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/_deleteFile.svelte @@ -0,0 +1,36 @@ + + +
+ + Delete File +

Are you sure you want to delete {$file.name}?

+ + + + +
+
diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte new file mode 100644 index 000000000..cf1755ff7 --- /dev/null +++ b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte @@ -0,0 +1,164 @@ + + + + {#if $file} + +
+ {$file.name} +
+

{$file.name}

+ + File URL + +
+
+ +
+

MIME Type: {$file.mimeType}

+

Size: {bytesToSize($file.sizeOriginal)}

+

Created: {toLocaleDate($file.$createdAt)}

+

Last Updated: {toLocaleDate($file.$updatedAt)}

+
+
+ + + + +
+ + +
Update Permissions
+

+ Assign read or write permissions at the Bucket Level or File Level. If Bucket Level + permissions are enabled, file permissions will be ignored. +

+ + + + You have Bucket Level permissions enabled + +

+ If you want to assign permissions specific to this file, you will need to + update your Bucket Settings to enable File Level + permissions. +

+
+
    + + +
+
+ + + + +
+ + +
Delete file
+

+ The file will be permanently deleted, including all the files within it. This action + is irreversible. +

+ + + +
{$file.name}
+
+

+ Last Updated: {toLocaleDateTime($file.$updatedAt)} +

+
+
+ + + + +
+ {/if} +
+ + diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/store.ts b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/store.ts new file mode 100644 index 000000000..d4e2d74eb --- /dev/null +++ b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/store.ts @@ -0,0 +1,25 @@ +import { sdkForProject } from '$lib/stores/sdk'; +import type { Models } from '@aw-labs/appwrite-console'; +import { writable } from 'svelte/store'; +import { browser } from '$app/env'; + +function createFileStore() { + const { subscribe, set } = writable( + browser ? JSON.parse(sessionStorage.getItem('file')) : null + ); + + return { + subscribe, + set, + load: async (bucketId: string, fileId: string) => { + const response = await sdkForProject.storage.getFile(bucketId, fileId); + set(response); + } + }; +} + +export const file = createFileStore(); + +if (browser) { + file.subscribe((n) => sessionStorage?.setItem('file', JSON.stringify(n ?? ''))); +} diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/index.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/index.svelte index 88c5e5514..d4eefef82 100644 --- a/src/routes/console/[project]/storage/bucket/[bucket]/index.svelte +++ b/src/routes/console/[project]/storage/bucket/[bucket]/index.svelte @@ -1,129 +1,218 @@ -
-
- -
- + -
- {#await request} -
- {:then response} - {#if response.total} - - - Filename - Type - Size - Date Created - - - - {#each response.files as file} + + {#if $files?.total} +
+ + Filename + Type + Size + Date Created + + + + {#each $files.files as file, index} + {#if file.chunksTotal / file.chunksUploaded !== 1}
- openFile(file)}> - - {file.name} - +
+ + {file.name} + Pending
{file.mimeType} - {file.sizeOriginal} + {bytesToSize(file.sizeOriginal)} {toLocaleDate(file.$createdAt)} + +
+ + +
+
- {/each} - -
-
-

Total results: {response.total}

- -
- {:else if search} - -
- Sorry, we couldn’t find ‘{search}’ -
-

There are no files that match your search.

-
-
- -
+ {:else} + + +
+ + {file.name} +
+
+ {file.mimeType} + {bytesToSize(file.sizeOriginal)} + {toLocaleDate(file.$createdAt)} + + + + + { + e.preventDefault(); + goto( + `${base}/console/${project}/storage/bucket/${bucket}/file/${file.$id}` + ); + }}>Update + { + e.preventDefault(); + selectedFile = file; + showDelete = true; + }}>Delete + + + +
+ {/if} + {/each} + + +
+

Total results: {$files.total}

+ +
+ {:else if search} + +
+ Sorry, we couldn’t find ‘{search}’ +
+

There are no files that match your search.

- -
-

Total results: {response.total}

- -
- {:else} - -
-
- -
-
-

Upload some files to get started

-
-
- -
+
+
- - {/if} - {/await} +
+
+
+

Total results: {$files?.total}

+ +
+ {:else} + +
+
+ +
+
+

Upload some files to get started

+
+
+ +
+
+
+ {/if} - - + +{#if selectedFile} + +{/if} diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte index c270642c7..fce6a9482 100644 --- a/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte +++ b/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte @@ -1,10 +1,469 @@ - -

Settings

+ {#if $bucket} + +

{$bucket.name}

- + +
    + +
+

Created: {toLocaleDateTime($bucket.$createdAt)}

+

Last Updated: {toLocaleDateTime($bucket.$updatedAt)}

+
+ + + + +
+ + +
Update Name
+ + +
    + + {#if showError === 'name'} + {errorMessage} + {/if} +
+
+ + + + +
+ +
Update Permissions
+

+ Assign read or write permissions at the Bucket Level or + File Level. If Bucket Level permissions are assigned, file permissions will + be ignored. +

+ +
    +
  • + +
  • +
  • + +
  • +
+ +

+ Tip: Add role:all for wildcards access. Check out our documentation + for more on Permissions +

+
+ {#if bucketPermissions === 'bucket'} +
    + + +
+ {/if} +
+ + + +
+ +

Update Security Settings

+

+ Enable or disable security services for the bucket including Ecryption + and Antivirus scanning. +

+ +
    +
  • + +
  • +
  • + +
  • + +
  • +
+
+ + + + +
+ +

Update Maximum File Size

+

Set the maximum file size allowed in the bucket.

+ +
    + + +
+
+ + + + +
+ +
Update Allowed File Extensions
+

+ A maxiumum of 100 file extensions can be added. Leave blank to allow all file types. +

+ + +

+ Tip: Commonly added extensions include JPG, PNG, SVG, GIF, HTML, PDF, MP4. +

+
+
    + +
+
+ + + + +
+ +
Delete Bucket
+

+ The bucket will be permanently deleted, including all the files within it. This + action is irreversible. +

+ + + +
{$bucket.name}
+
+

Last Updated: {toLocaleDateTime($bucket.$updatedAt)}

+
+
+ + + + +
+ {/if}
+ + diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/store.ts b/src/routes/console/[project]/storage/bucket/[bucket]/store.ts index 0ddff775f..836a13b0f 100644 --- a/src/routes/console/[project]/storage/bucket/[bucket]/store.ts +++ b/src/routes/console/[project]/storage/bucket/[bucket]/store.ts @@ -1,17 +1,58 @@ import { sdkForProject } from '$lib/stores/sdk'; import type { Models } from '@aw-labs/appwrite-console'; import { writable } from 'svelte/store'; +import { browser } from '$app/env'; function createBucketStore() { - const { subscribe, set } = writable(); + const { subscribe, set } = writable( + browser ? JSON.parse(sessionStorage.getItem('bucket')) : null + ); return { subscribe, set, load: async (bucketId: string) => { - set(await sdkForProject.storage.getBucket(bucketId)); + const response = await sdkForProject.storage.getBucket(bucketId); + set(response); + } + }; +} + +function createFilesStore() { + const { subscribe, set } = writable( + browser ? JSON.parse(sessionStorage.getItem('files')) : null + ); + + return { + subscribe, + set, + load: async ( + bucketId: string, + search?: string, + limit?: number, + offset?: number, + cursor?: string, + cursorDirection?: string, + orderType?: 'DESC' | 'ASC' + ) => { + const response = await sdkForProject.storage.listFiles( + bucketId, + search, + limit, + offset, + cursor, + cursorDirection, + (orderType = 'DESC') + ); + set(response); } }; } export const bucket = createBucketStore(); +export const files = createFilesStore(); + +if (browser) { + bucket.subscribe((n) => sessionStorage?.setItem('bucket', JSON.stringify(n ?? ''))); + files.subscribe((n) => sessionStorage?.setItem('files', JSON.stringify(n ?? ''))); +} diff --git a/src/routes/console/[project]/storage/index.svelte b/src/routes/console/[project]/storage/index.svelte index 3b52c7ba9..f4fbe0409 100644 --- a/src/routes/console/[project]/storage/index.svelte +++ b/src/routes/console/[project]/storage/index.svelte @@ -1,14 +1,14 @@ @@ -30,87 +30,113 @@

Buckets

- {#await request} -
- {:then response} - {#if response.total} - - {#each response.buckets as bucket} - -
- XX Files - {#if !bucket.enabled} - Disabled - {/if} -
-

{bucket.name}

-
- - - -
- - {bucket.encryption - ? 'Encryption enabled' - : 'Encryption disabled'} - - - {bucket.antivirus - ? 'Antivirus enabled' - : 'Antivirus disabled'} - + + {#if $bucketList?.total} +
  • 3 ? '22rem' : '25rem' + };`}> + {#each $bucketList.buckets as bucket} + + XX Files + {bucket.name} + + {#if !bucket.enabled} + Disabled + {/if} + + + + Bucket ID + + + +
  • + + {bucket.encryption + ? 'Encryption enabled' + : 'Encryption disabled'} + +
  • +
  • + + {bucket.antivirus + ? 'Antivirus enabled' + : 'Antivirus disabled'} + +
  • + + + {/each} + {#if $bucketList.total % 2 !== 0} +
    + {/if} + -
    -

    Total results: {response.total}

    - -
    - {:else if search} - -
    - Sorry, we couldn’t find ‘{search}’ -
    -

    There are no buckets that match your search.

    -
    -
    - -
    +
    +

    Total results: {$bucketList.total}

    + +
    + {:else if search} + +
    + Sorry, we couldn’t find ‘{search}’ +
    +

    There are no buckets that match your search.

    +
    +
    +
    - -
    -

    Total results: {response.total}

    -
    - {:else} - + +
    +

    Total results: {$bucketList?.total}

    + +
    + {:else} + +
    -

    Add Your First Bucket To Get Started

    +

    Add your first bucket to get started

    - - {/if} - {/await} +
    +
    + {/if} diff --git a/src/routes/console/[project]/storage/store.ts b/src/routes/console/[project]/storage/store.ts new file mode 100644 index 000000000..0418b6106 --- /dev/null +++ b/src/routes/console/[project]/storage/store.ts @@ -0,0 +1,25 @@ +import { sdkForProject } from '$lib/stores/sdk'; +import type { Models } from '@aw-labs/appwrite-console'; +import { writable } from 'svelte/store'; +import { browser } from '$app/env'; + +function createBucketListStore() { + const { subscribe, set } = writable( + browser ? JSON.parse(sessionStorage.getItem('bucketList')) : null + ); + + return { + subscribe, + set, + load: async (search: string, limit: number, offset: number) => { + const response = await sdkForProject.storage.listBuckets(search, limit, offset); + set(response); + } + }; +} + +export const bucketList = createBucketListStore(); + +if (browser) { + bucketList.subscribe((n) => sessionStorage?.setItem('bucketList', JSON.stringify(n ?? ''))); +}