mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
22 files changed
+1504
-306
No files matched your search
@@ -0,0 +1,19 @@
|
||||
<script>
|
||||
export let href;
|
||||
</script>
|
||||
|
||||
<a class="card" {href}>
|
||||
<div class="bucket">
|
||||
<div class="eyebrow-heading-3"><slot name="eyebrow" /></div>
|
||||
<h2 class="heading-level-6"><slot name="title" /></h2>
|
||||
<div class="bucket-status">
|
||||
<slot name="status" />
|
||||
</div>
|
||||
<div class="bucket-options">
|
||||
<slot />
|
||||
</div>
|
||||
<ul class="bucket-icons u-flex u-gap-8">
|
||||
<slot name="icons" />
|
||||
</ul>
|
||||
</div>
|
||||
</a>
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<svelte:window on:click={onBlur} />
|
||||
|
||||
<div class="drop-wrapper" bind:this={parentElement}>
|
||||
<div class="drop-wrapper" class:is-open={show} bind:this={parentElement}>
|
||||
<slot />
|
||||
{#if show}
|
||||
<div
|
||||
|
||||
@@ -25,3 +25,4 @@ export { default as SwitchBoxes } from './switchBoxes.svelte';
|
||||
export { default as Alert } from './alert.svelte';
|
||||
export { default as Box } from './box.svelte';
|
||||
export { default as Search } from './search.svelte';
|
||||
export { default as Bucket } from './bucket.svelte';
|
||||
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let icon = 'info';
|
||||
export let aria = 'info';
|
||||
export let disabled = false;
|
||||
</script>
|
||||
|
||||
<button class="tooltip" aria-label={aria}>
|
||||
<span class={`icon-${icon}`} aria-hidden="true" />
|
||||
<span class:u-opacity-0-2={disabled} class={`icon-${icon}`} aria-hidden="true" />
|
||||
<span class="tooltip-popup" role="tooltip">
|
||||
<slot />
|
||||
</span>
|
||||
|
||||
@@ -1,83 +1,99 @@
|
||||
<script lang="ts">
|
||||
export let show = false;
|
||||
export let collapsed = false;
|
||||
import { uploader } from '$lib/stores/uploader';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { Avatar } from '$lib/components';
|
||||
|
||||
async function removeFile($id: string, bucketId: string) {
|
||||
const file = await sdkForProject.storage.getFile(bucketId, $id);
|
||||
uploader.removeFile(file);
|
||||
}
|
||||
|
||||
const getPreview = (fileId: string, bucketId: string) =>
|
||||
sdkForProject.storage.getFilePreview(bucketId, fileId, 32, 32).toString() + '&mode=admin';
|
||||
</script>
|
||||
|
||||
{#if show}
|
||||
<section class="upload-box">
|
||||
{#if $uploader?.isOpen}
|
||||
<section class="upload-box is-float">
|
||||
<header class="upload-box-header">
|
||||
<h4 class="upload-box-title">
|
||||
<span class="text">Uploading files</span>
|
||||
<span class="amount">3</span>
|
||||
<span class="amount">{$uploader.files.length}</span>
|
||||
</h4>
|
||||
<button
|
||||
class="icon-button"
|
||||
class:is-open={collapsed}
|
||||
class:is-open={!$uploader.isCollapsed}
|
||||
aria-label="toggle upload box"
|
||||
on:click={() => (collapsed = !collapsed)}>
|
||||
<span class="icon-up-dir" aria-hidden="true" />
|
||||
on:click={() => uploader.toggle()}>
|
||||
<span class="icon-cheveron-up" aria-hidden="true" />
|
||||
</button>
|
||||
<button class="icon-button" aria-label="close upload box">
|
||||
<span class="icon-cancel" aria-hidden="true" />
|
||||
<button
|
||||
on:click={() => uploader.close()}
|
||||
class="icon-button"
|
||||
aria-label="close upload box">
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</button>
|
||||
</header>
|
||||
<div class="upload-box-content" class:is-open={collapsed}>
|
||||
<div class="upload-box-content" class:is-open={!$uploader.isCollapsed}>
|
||||
<ul class="upload-box-list">
|
||||
<li class="upload-box-item">
|
||||
<div class="upload-image u-margin-inline-end-16">
|
||||
<div
|
||||
class="progress"
|
||||
style="--progress-value:20"
|
||||
role="progressbar"
|
||||
aria-valuenow={20}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100} />
|
||||
<span class="icon">%</span>
|
||||
</div>
|
||||
<label for="file1" class="file-name">hello.mp4</label>
|
||||
<button class="icon-button" aria-label="Uploading"
|
||||
><span class="icon">&</span></button>
|
||||
</li>
|
||||
<li class="upload-box-item">
|
||||
<div class="upload-image u-margin-inline-end-16">
|
||||
<div
|
||||
class="progress"
|
||||
style="--progress-value:70"
|
||||
role="progressbar"
|
||||
aria-valuenow={20}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100} />
|
||||
<span class="icon">%</span>
|
||||
</div>
|
||||
<label for="file1" class="file-name">hello.mp4</label>
|
||||
<button class="icon-button" aria-label="Uploading"
|
||||
><span class="icon">&</span></button>
|
||||
</li>
|
||||
<li class="upload-box-item">
|
||||
<div class="upload-image is-finished u-margin-inline-end-16">
|
||||
<div
|
||||
class="progress"
|
||||
style="--progress-value:100"
|
||||
role="progressbar"
|
||||
aria-valuenow={20}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100} />
|
||||
<span class="icon">%</span>
|
||||
</div>
|
||||
<label for="file1" class="file-name">hello.mp4</label>
|
||||
<button class="icon-button" aria-label="Uploading"
|
||||
><span class="icon">&</span></button>
|
||||
</li>
|
||||
{#each $uploader.files as file}
|
||||
{#if file.completed || file.progress === 100}
|
||||
<li class="upload-box-item">
|
||||
<div class="u-margin-inline-end-16">
|
||||
<Avatar
|
||||
size={32}
|
||||
src={getPreview(file.$id, file.bucketId)}
|
||||
name={file.name} />
|
||||
</div>
|
||||
|
||||
<label for={file.name} class="file-name">{file.name}</label>
|
||||
<span class="icon-check" />
|
||||
</li>
|
||||
{:else if file.failed}
|
||||
<li class="upload-box-item">
|
||||
<div class="upload-image u-margin-inline-end-16">
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow={file.progress}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100} />
|
||||
<span class="icon">{file.progress}%</span>
|
||||
</div>
|
||||
<label for={file.name} class="file-name">{file.name}</label>
|
||||
<Pill danger>Failed</Pill>
|
||||
<button
|
||||
class="icon-button"
|
||||
aria-label="Failed"
|
||||
on:click={() => removeFile(file.$id, file.bucketId)}>
|
||||
<span class="icon-x" />
|
||||
</button>
|
||||
</li>
|
||||
{:else if file.cancelled}
|
||||
cancelled?
|
||||
{:else}
|
||||
<li class="upload-box-item">
|
||||
<div class="upload-image u-margin-inline-end-16">
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow={file.progress}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100} />
|
||||
<span class="icon">{file.progress}%</span>
|
||||
</div>
|
||||
<label for={file.name} class="file-name">{file.name}</label>
|
||||
<Pill warning>Pending</Pill>
|
||||
<button
|
||||
class="icon-button"
|
||||
aria-label="Pending"
|
||||
on:click={() => removeFile(file.$id, file.bucketId)}>
|
||||
<span class="icon-x" />
|
||||
</button>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
section.upload-box {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
margin: 0 1rem 1rem 0;
|
||||
}
|
||||
</style>
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<Uploader>({
|
||||
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);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, Form, InputText } from '$lib/elements/forms';
|
||||
import { Modal, InnerModal } from '$lib/components';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Button, InputText, Form, FormList } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
@@ -11,10 +12,16 @@
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
let name = '';
|
||||
let id: string = null;
|
||||
let showDropdown = false;
|
||||
|
||||
const create = async () => {
|
||||
try {
|
||||
const bucket = await sdkForProject.storage.createBucket('unique()', name, 'bucket');
|
||||
const bucket = await sdkForProject.storage.createBucket(
|
||||
id ? id : 'unique()',
|
||||
name,
|
||||
'bucket'
|
||||
);
|
||||
name = null;
|
||||
showCreate = false;
|
||||
dispatch('created', bucket);
|
||||
@@ -25,15 +32,64 @@
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$: if (!showDropdown) {
|
||||
id = null;
|
||||
}
|
||||
$: if (!showCreate) {
|
||||
showDropdown = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Form on:submit={create}>
|
||||
<Modal bind:show={showCreate}>
|
||||
<Modal size="big" bind:show={showCreate}>
|
||||
<svelte:fragment slot="header">Create Bucket</svelte:fragment>
|
||||
<InputText id="name" label="Name" bind:value={name} autofocus required />
|
||||
<FormList>
|
||||
<InputText
|
||||
id="name"
|
||||
label="Name"
|
||||
placeholder="New Bucket"
|
||||
bind:value={name}
|
||||
autofocus
|
||||
required />
|
||||
|
||||
{#if !showDropdown}
|
||||
<div>
|
||||
<Pill button on:click={() => (showDropdown = !showDropdown)}
|
||||
><span class="icon-pencil" aria-hidden="true" /><span class="text">
|
||||
Bucket ID
|
||||
</span></Pill>
|
||||
</div>
|
||||
{:else}
|
||||
<InnerModal bind:show={showDropdown}>
|
||||
<svelte:fragment slot="title">Bucket ID</svelte:fragment>
|
||||
<p>Enter a custom bucket ID. Leave blank for a randomly generated bucket ID.</p>
|
||||
<svelte:fragment slot="content">
|
||||
<div class="form">
|
||||
<InputText
|
||||
id="id"
|
||||
label="Custom ID"
|
||||
showLabel={false}
|
||||
placeholder="Enter ID"
|
||||
autofocus={true}
|
||||
bind:value={id} />
|
||||
|
||||
<div class="u-flex u-gap-4 u-margin-block-start-8 u-small">
|
||||
<span
|
||||
class="icon-info u-cross-center u-margin-block-start-2 u-line-height-1 u-icon-small"
|
||||
aria-hidden="true" />
|
||||
<span class="text u-line-height-1-5"
|
||||
>Allowed characters: alphanumeric, hyphen, non-leading
|
||||
underscore, period</span>
|
||||
</div>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</InnerModal>
|
||||
{/if}
|
||||
</FormList>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button submit>Create</Button>
|
||||
<Button secondary on:click={() => (showCreate = false)}>Cancel</Button>
|
||||
<Button submit>Create</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
</Form>
|
||||
@@ -20,7 +20,7 @@
|
||||
navigate: event,
|
||||
title: $bucket.name,
|
||||
copy: {
|
||||
text: bucketId,
|
||||
text: 'Bucket ID',
|
||||
value: bucketId
|
||||
},
|
||||
tabs: [
|
||||
|
||||
@@ -1,25 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { InputTags, Button, InputFile, Form } from '$lib/elements/forms';
|
||||
import { Modal } from '$lib/components';
|
||||
import { InputTags, InputText, Button, Form, FormList } from '$lib/elements/forms';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Modal, Alert, InnerModal } from '$lib/components';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { page } from '$app/stores';
|
||||
import { uploader } from '$lib/stores/uploader';
|
||||
import { bucket } from './store';
|
||||
import { bytesToSize } from '$lib/helpers/sizeConvertion';
|
||||
|
||||
export let showCreate = false;
|
||||
|
||||
const bucket = $page.params.bucket;
|
||||
const bucketId = $page.params.bucket;
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
let list = new DataTransfer();
|
||||
let files: FileList;
|
||||
let read: string[] = [];
|
||||
let write: string[] = [];
|
||||
let id: string = null;
|
||||
let showDropdown = false;
|
||||
|
||||
const create = async () => {
|
||||
try {
|
||||
await sdkForProject.storage.createFile(bucket, 'unique()', files[0], read, write);
|
||||
const file = await sdkForProject.storage.createFile(
|
||||
bucketId,
|
||||
id ?? 'unique()',
|
||||
files[0],
|
||||
read,
|
||||
write
|
||||
);
|
||||
files = null;
|
||||
showCreate = false;
|
||||
showDropdown = false;
|
||||
uploader.addFile(file);
|
||||
dispatch('created');
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
@@ -28,24 +43,143 @@
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function dropHandler(ev: DragEvent) {
|
||||
console.log(ev);
|
||||
ev.preventDefault();
|
||||
if (ev.dataTransfer.items) {
|
||||
// Use DataTransferItemList interface to access the file(s)
|
||||
for (let i = 0; i < ev.dataTransfer.items.length; i++) {
|
||||
// If dropped items aren't files, reject them
|
||||
if (ev.dataTransfer.items[i].kind === 'file') {
|
||||
list.items.clear();
|
||||
list.items.add(ev.dataTransfer.items[i].getAsFile());
|
||||
files = list.files;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Use DataTransfer interface to access the file(s)
|
||||
for (let i = 0; i < ev.dataTransfer.files.length; i++) {
|
||||
console.log('... file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dragOverHandler(ev: DragEvent) {
|
||||
console.log('File(s) in drop zone');
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
$: if (!showCreate) {
|
||||
id = null;
|
||||
list = new DataTransfer();
|
||||
files = null;
|
||||
read = [];
|
||||
write = [];
|
||||
}
|
||||
|
||||
$: if (!showDropdown) {
|
||||
id = null;
|
||||
}
|
||||
</script>
|
||||
|
||||
<input bind:files id="file" type="file" style="display: none" />
|
||||
|
||||
<Form on:submit={create}>
|
||||
<Modal bind:show={showCreate}>
|
||||
<svelte:fragment slot="header">Upload File</svelte:fragment>
|
||||
<InputFile id="file" label="File" bind:files required />
|
||||
<InputTags
|
||||
id="read"
|
||||
label="Read"
|
||||
bind:tags={read}
|
||||
helper="Add 'role:all' for wildcard access"
|
||||
placeholder="User ID, Team ID or Role" />
|
||||
<InputTags
|
||||
id="write"
|
||||
label="Write"
|
||||
bind:tags={write}
|
||||
helper="Add 'role:all' for wildcard access"
|
||||
placeholder="User ID, Team ID or Role" />
|
||||
<FormList>
|
||||
<div>
|
||||
<div
|
||||
class="card is-border-dashed is-no-shadow"
|
||||
on:drop|preventDefault={(e) => dropHandler(e)}
|
||||
on:dragover|preventDefault={(e) => dragOverHandler(e)}>
|
||||
<div class="u-flex u-main-center u-cross-center u-gap-32">
|
||||
<div class="avatar is-size-large">
|
||||
<span class="icon-upload" aria-hidden="true" />
|
||||
</div>
|
||||
<div class="u-grid u-gap-16">
|
||||
<p>Drag and drop files here to upload</p>
|
||||
<div>
|
||||
<Button
|
||||
secondary
|
||||
on:click={() => {
|
||||
document.getElementById('file').click();
|
||||
}}>
|
||||
<span class="icon-upload" aria-hidden="true" />
|
||||
<span class="text">Choose File</span>
|
||||
</Button>
|
||||
{#if files?.length}
|
||||
{files.item(0).name}
|
||||
<button
|
||||
on:click={() => (files = null)}
|
||||
type="button"
|
||||
class="x-button"
|
||||
aria-label="remove file"
|
||||
title="Remove file"
|
||||
><span class="icon-x" aria-hidden="true" /></button
|
||||
>{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Max file size: {bytesToSize($bucket.maximumFileSize)}</p>
|
||||
</div>
|
||||
|
||||
{#if !showDropdown}
|
||||
<div>
|
||||
<Pill button on:click={() => (showDropdown = !showDropdown)}
|
||||
><span class="icon-pencil" aria-hidden="true" /><span class="text">
|
||||
File ID
|
||||
</span></Pill>
|
||||
</div>
|
||||
{:else}
|
||||
<InnerModal bind:show={showDropdown}>
|
||||
<svelte:fragment slot="title">File ID</svelte:fragment>
|
||||
<p>Enter a custom file ID. Leave blank for a randomly generated file ID.</p>
|
||||
<svelte:fragment slot="content">
|
||||
<div class="form">
|
||||
<InputText
|
||||
id="id"
|
||||
label="Custom ID"
|
||||
showLabel={false}
|
||||
placeholder="Enter ID"
|
||||
autofocus={true}
|
||||
bind:value={id} />
|
||||
|
||||
<div class="u-flex u-gap-4 u-margin-block-start-8 u-small">
|
||||
<span
|
||||
class="icon-info u-cross-center u-margin-block-start-2 u-line-height-1 u-icon-small"
|
||||
aria-hidden="true" />
|
||||
<span class="text u-line-height-1-5"
|
||||
>Allowed characters: alphanumeric, hyphen, non-leading
|
||||
underscore, period</span>
|
||||
</div>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</InnerModal>
|
||||
{/if}
|
||||
<p class="heading-level-7">Permissions</p>
|
||||
<Alert type="info">
|
||||
<p>
|
||||
Tip: Add role:all for wildcard access. Check out our documentation for more on <a
|
||||
class="link"
|
||||
href="#">
|
||||
Permissions</a>
|
||||
</p>
|
||||
</Alert>
|
||||
<InputTags
|
||||
id="read"
|
||||
label="Read"
|
||||
bind:tags={read}
|
||||
placeholder="User ID, Team ID or Role" />
|
||||
<InputTags
|
||||
id="write"
|
||||
label="Write"
|
||||
bind:tags={write}
|
||||
placeholder="User ID, Team ID or Role" />
|
||||
</FormList>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (showCreate = false)}>Cancel</Button>
|
||||
<Button submit>Upload</Button>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { bucket } from './store';
|
||||
|
||||
export let showDelete = false;
|
||||
|
||||
const deleteUser = async () => {
|
||||
try {
|
||||
await sdkForProject.storage.deleteBucket($bucket.$id);
|
||||
showDelete = false;
|
||||
await goto(`${base}/console/${$page.params.project}/storage`);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<Form on:submit={deleteUser}>
|
||||
<Modal warning={true} bind:show={showDelete}>
|
||||
<svelte:fragment slot="header">Delete Bucket</svelte:fragment>
|
||||
<p>Are you sure you want to delete <b>{$bucket.name}</b>?</p>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button text on:click={() => (showDelete = false)}>Cancel</Button>
|
||||
<Button secondary submit>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
</Form>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
export let file: Models.File;
|
||||
export let showDelete = false;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const deleteFile = async () => {
|
||||
try {
|
||||
await sdkForProject.storage.deleteFile(file.bucketId, file.$id);
|
||||
showDelete = false;
|
||||
dispatch('deleted', file);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<Form on:submit={deleteFile}>
|
||||
<Modal warning={true} bind:show={showDelete}>
|
||||
<svelte:fragment slot="header">Delete File</svelte:fragment>
|
||||
<p>Are you sure you want to delete <b>{file.name}</b>?</p>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button text on:click={() => (showDelete = false)}>Cancel</Button>
|
||||
<Button secondary submit>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
</Form>
|
||||
@@ -1,54 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { CopyInput, Modal } from '$lib/components';
|
||||
import { Button, Form, InputTags } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
export let showUpdate = false;
|
||||
export let file: Models.File = null;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const updateFile = async () => {
|
||||
try {
|
||||
await sdkForProject.storage.updateFile(
|
||||
file.bucketId,
|
||||
file.$id,
|
||||
file.$read,
|
||||
file.$write
|
||||
);
|
||||
showUpdate = false;
|
||||
dispatch('updated');
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<Form on:submit={updateFile}>
|
||||
<Modal bind:show={showUpdate}>
|
||||
<svelte:fragment slot="header">Update File</svelte:fragment>
|
||||
<CopyInput value={file.$id} />
|
||||
<InputTags
|
||||
bind:tags={file.$read}
|
||||
label="Read Access"
|
||||
id="read"
|
||||
helper="Add 'role:all' for wildcard access"
|
||||
placeholder="User ID, Team ID or Role" />
|
||||
<InputTags
|
||||
bind:tags={file.$write}
|
||||
label="Read Access"
|
||||
id="write"
|
||||
helper="Add 'role:all' for wildcard access"
|
||||
placeholder="User ID, Team ID or Role" />
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (showUpdate = false)}>Cancel</Button>
|
||||
<Button submit>Update</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
</Form>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { afterNavigate } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { base } from '$app/paths';
|
||||
import { file } from './store';
|
||||
import { updateLayout } from '$lib/stores/layout';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
const bucketId = $page.params.bucket;
|
||||
const fileId = $page.params.file;
|
||||
|
||||
onMount(handle);
|
||||
afterNavigate(handle);
|
||||
|
||||
async function handle(event = null) {
|
||||
if ($file?.$id !== fileId) {
|
||||
await file.load(bucketId, fileId);
|
||||
}
|
||||
|
||||
updateLayout({
|
||||
navigate: event,
|
||||
back: `${base}/console/${$page.params.project}/storage/bucket/${bucketId}`,
|
||||
title: $file.name,
|
||||
copy: {
|
||||
text: 'File ID',
|
||||
value: fileId
|
||||
},
|
||||
tabs: []
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Appwrite - File</title>
|
||||
</svelte:head>
|
||||
|
||||
<slot />
|
||||
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { file } from './store';
|
||||
|
||||
export let showDelete = false;
|
||||
|
||||
const deleteFile = async () => {
|
||||
try {
|
||||
await sdkForProject.storage.deleteFile($file.bucketId, $file.$id);
|
||||
showDelete = false;
|
||||
await goto(`${base}/console/${$page.params.project}/storage/bucket/${$file.bucketId}`);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<Form on:submit={deleteFile}>
|
||||
<Modal warning={true} bind:show={showDelete}>
|
||||
<svelte:fragment slot="header">Delete File</svelte:fragment>
|
||||
<p>Are you sure you want to delete <b>{$file.name}</b>?</p>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button text on:click={() => (showDelete = false)}>Cancel</Button>
|
||||
<Button secondary submit>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
</Form>
|
||||
@@ -0,0 +1,164 @@
|
||||
<script lang="ts">
|
||||
import { Alert, CardGrid, Box, Copy } from '$lib/components';
|
||||
import { Container } from '$lib/layout';
|
||||
import { Button, InputTags } from '$lib/elements/forms';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { file } from './store';
|
||||
import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { bytesToSize } from '$lib/helpers/sizeConvertion';
|
||||
import Delete from './_deleteFile.svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
onMount(async () => {
|
||||
let bucketId = $page.params.bucket;
|
||||
let fileId = $page.params.file;
|
||||
await file.load(bucketId, fileId);
|
||||
fileRead = $file?.$read;
|
||||
fileWrite = $file?.$write;
|
||||
});
|
||||
|
||||
let showDelete = false;
|
||||
let fileRead = $file?.$read;
|
||||
let fileWrite = $file?.$write;
|
||||
let arePermsDisabled = true;
|
||||
|
||||
const getPreview = (fileId: string) =>
|
||||
sdkForProject.storage.getFilePreview($file.bucketId, fileId, 205, 125).toString() +
|
||||
'&mode=admin';
|
||||
const getView = (fileId: string) =>
|
||||
sdkForProject.storage.getFileView($file.bucketId, fileId).toString() + '&mode=admin';
|
||||
|
||||
$: if (fileRead || fileWrite) {
|
||||
if (fileRead) {
|
||||
if (JSON.stringify(fileRead) !== JSON.stringify($file.$read)) {
|
||||
arePermsDisabled = false;
|
||||
} else arePermsDisabled = true;
|
||||
} else if (fileWrite) {
|
||||
if (JSON.stringify(fileWrite) !== JSON.stringify($file.$write)) {
|
||||
arePermsDisabled = false;
|
||||
} else arePermsDisabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
function downloadFile() {
|
||||
return (
|
||||
sdkForProject.storage.getFileDownload($file.bucketId, $file.$id).toString() +
|
||||
'&mode=admin'
|
||||
);
|
||||
}
|
||||
|
||||
async function updatePermissions() {
|
||||
try {
|
||||
await sdkForProject.storage.updateFile($file.bucketId, $file.$id, fileRead, fileWrite);
|
||||
$file.$read = fileRead;
|
||||
$file.$write = fileWrite;
|
||||
arePermsDisabled = true;
|
||||
addNotification({
|
||||
message: 'Permissions have been updated',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
{#if $file}
|
||||
<CardGrid>
|
||||
<div class="u-flex u-gap-16">
|
||||
<img width="205" height="125" src={getPreview($file.$id)} alt={$file.name} />
|
||||
<div>
|
||||
<h2 class="heading-level-7">{$file.name}</h2>
|
||||
<Copy value={getView($file.$id)}>
|
||||
<Pill button><i class="icon-duplicate" />File URL</Pill>
|
||||
</Copy>
|
||||
</div>
|
||||
</div>
|
||||
<svelte:fragment slot="aside">
|
||||
<div>
|
||||
<p>MIME Type: {$file.mimeType}</p>
|
||||
<p>Size: {bytesToSize($file.sizeOriginal)}</p>
|
||||
<p>Created: {toLocaleDate($file.$createdAt)}</p>
|
||||
<p>Last Updated: {toLocaleDate($file.$updatedAt)}</p>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button secondary href={downloadFile()}>
|
||||
<span class="icon-download" aria-hidden="true" />
|
||||
<span class="text"> Download</span></Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Update Permissions</h6>
|
||||
<p>
|
||||
Assign read or write permissions at the Bucket Level or File Level. If Bucket Level
|
||||
permissions are enabled, file permissions will be ignored.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Alert type="info">
|
||||
<svelte:fragment slot="title">
|
||||
You have Bucket Level permissions enabled
|
||||
</svelte:fragment>
|
||||
<p>
|
||||
If you want to assign permissions specific to this file, you will need to
|
||||
update your <a class="link" href="#"> Bucket Settings</a> to enable File Level
|
||||
permissions.
|
||||
</p>
|
||||
</Alert>
|
||||
<ul class="common-section">
|
||||
<InputTags
|
||||
id="read"
|
||||
label="Read Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={fileRead} />
|
||||
<InputTags
|
||||
id="write"
|
||||
label="Write Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={fileWrite} />
|
||||
</ul>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={arePermsDisabled}
|
||||
on:click={() => {
|
||||
updatePermissions();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Delete file</h6>
|
||||
<p>
|
||||
The file will be permanently deleted, including all the files within it. This action
|
||||
is irreversible.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Box>
|
||||
<svelte:fragment slot="title">
|
||||
<h6 class="u-bold">{$file.name}</h6>
|
||||
</svelte:fragment>
|
||||
<p>
|
||||
Last Updated: {toLocaleDateTime($file.$updatedAt)}
|
||||
</p>
|
||||
</Box>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
{/if}
|
||||
</Container>
|
||||
|
||||
<Delete bind:showDelete />
|
||||
@@ -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<Models.File>(
|
||||
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 ?? '')));
|
||||
}
|
||||
@@ -1,129 +1,218 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Empty, Pagination, Avatar } from '$lib/components';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { Empty, Pagination, Avatar, Search, DropList, DropListItem } from '$lib/components';
|
||||
import Create from './_create.svelte';
|
||||
import Update from './_update.svelte';
|
||||
import Delete from './_deleteFile.svelte';
|
||||
import {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableRowLink,
|
||||
TableRow,
|
||||
TableCellHead,
|
||||
TableCellText
|
||||
TableCellText,
|
||||
TableCell
|
||||
} from '$lib/elements/table';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { bytesToSize } from '$lib/helpers/sizeConvertion';
|
||||
import { Container } from '$lib/layout';
|
||||
import { base } from '$app/paths';
|
||||
import { files } from './store';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { uploader } from '$lib/stores/uploader';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
let search = '';
|
||||
let showCreate = false;
|
||||
let showUpdate = false;
|
||||
let showDropdown = [];
|
||||
let showDelete = false;
|
||||
let selectedFile: Models.File = null;
|
||||
let offset = 0;
|
||||
let currentFile: Models.File;
|
||||
|
||||
const limit = 25;
|
||||
const limit = 5;
|
||||
const project = $page.params.project;
|
||||
const bucket = $page.params.bucket;
|
||||
const openFile = (file: Models.File) => {
|
||||
currentFile = file;
|
||||
showUpdate = true;
|
||||
};
|
||||
const getPreview = (fileId: string) =>
|
||||
sdkForProject.storage.getFilePreview(bucket, fileId, 40, 40).toString() + '&mode=admin';
|
||||
|
||||
$: request = sdkForProject.storage.listFiles(bucket, search, limit, offset);
|
||||
const getPreview = (fileId: string) =>
|
||||
sdkForProject.storage.getFilePreview(bucket, fileId, 32, 32).toString() + '&mode=admin';
|
||||
|
||||
const fileCreated = () => {
|
||||
showCreate = false;
|
||||
files.load(bucket, search, limit, offset);
|
||||
};
|
||||
|
||||
const fileDeleted = (event: CustomEvent<Models.File>) => {
|
||||
showDelete = false;
|
||||
uploader.removeFile(event.detail);
|
||||
files.load(bucket, search, limit, offset);
|
||||
};
|
||||
|
||||
const deleteFile = async (file) => {
|
||||
try {
|
||||
await sdkForProject.storage.deleteFile(file.bucketId, file.$id);
|
||||
uploader.removeFile(file);
|
||||
files.load(bucket, search, limit, offset);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$: files.load(bucket, search, limit, offset);
|
||||
$: if (search) offset = 0;
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
<div class="u-flex u-gap-12 common-section u-main-space-between">
|
||||
<div class="input-text-wrapper u-flex-basis-50-percent">
|
||||
<input
|
||||
type="search"
|
||||
placeholder="Search by Filename"
|
||||
class="input-text"
|
||||
bind:value={search} />
|
||||
<span class="icon-search" aria-hidden="true" />
|
||||
</div>
|
||||
|
||||
<Search bind:search placeholder="Search by Filename">
|
||||
<Button on:click={() => (showCreate = true)}>
|
||||
<span class="icon-plus" aria-hidden="true" /> <span class="text">Add File</span>
|
||||
</Button>
|
||||
</div>
|
||||
{#await request}
|
||||
<div aria-busy="true" />
|
||||
{:then response}
|
||||
{#if response.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Filename</TableCellHead>
|
||||
<TableCellHead>Type</TableCellHead>
|
||||
<TableCellHead>Size</TableCellHead>
|
||||
<TableCellHead>Date Created</TableCellHead>
|
||||
<TableCellHead width={30} />
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each response.files as file}
|
||||
</Search>
|
||||
{#if $files?.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Filename</TableCellHead>
|
||||
<TableCellHead>Type</TableCellHead>
|
||||
<TableCellHead>Size</TableCellHead>
|
||||
<TableCellHead>Date Created</TableCellHead>
|
||||
<TableCellHead width={30} />
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each $files.files as file, index}
|
||||
{#if file.chunksTotal / file.chunksUploaded !== 1}
|
||||
<TableRow>
|
||||
<TableCellText title="Name">
|
||||
<div class="u-flex u-gap-12">
|
||||
<span class="link" on:click={() => openFile(file)}>
|
||||
<Avatar
|
||||
size={40}
|
||||
src={getPreview(file.$id)}
|
||||
name={file.name} />
|
||||
{file.name}
|
||||
</span>
|
||||
<div class="avatar is-color-empty" />
|
||||
|
||||
<span> {file.name}</span>
|
||||
<Pill warning>Pending</Pill>
|
||||
</div>
|
||||
</TableCellText>
|
||||
<TableCellText title="Type">{file.mimeType}</TableCellText>
|
||||
<TableCellText title="Size">{file.sizeOriginal}</TableCellText>
|
||||
<TableCellText title="Size"
|
||||
>{bytesToSize(file.sizeOriginal)}</TableCellText>
|
||||
<TableCellText title="Date Created"
|
||||
>{toLocaleDate(file.$createdAt)}</TableCellText>
|
||||
<TableCell>
|
||||
<div class="u-flex u-main-center">
|
||||
<button
|
||||
class="button is-only-icon is-text"
|
||||
aria-label="Delete item"
|
||||
on:click|preventDefault={() => {
|
||||
console.log('Feel refreshed?');
|
||||
}}>
|
||||
<span class="icon-refresh" aria-hidden="true" />
|
||||
</button>
|
||||
<button
|
||||
class="button is-only-icon is-text"
|
||||
aria-label="Delete item"
|
||||
on:click|preventDefault={() => {
|
||||
deleteFile(file);
|
||||
}}>
|
||||
<span class="icon-trash" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div class="u-flex common-section u-main-space-between">
|
||||
<p class="text">Total results: {response.total}</p>
|
||||
<Pagination {limit} bind:offset sum={response.total} />
|
||||
</div>
|
||||
{:else if search}
|
||||
<Empty>
|
||||
<div class="u-flex u-flex-vertical">
|
||||
<b>Sorry, we couldn’t find ‘{search}’</b>
|
||||
<div class="common-section">
|
||||
<p>There are no files that match your search.</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
|
||||
</div>
|
||||
{:else}
|
||||
<TableRowLink
|
||||
href={`${base}/console/${project}/storage/bucket/${bucket}/file/${file.$id}`}>
|
||||
<TableCellText title="Name">
|
||||
<div class="u-flex u-gap-12">
|
||||
<Avatar size={32} src={getPreview(file.$id)} name={file.name} />
|
||||
<span> {file.name}</span>
|
||||
</div>
|
||||
</TableCellText>
|
||||
<TableCellText title="Type">{file.mimeType}</TableCellText>
|
||||
<TableCellText title="Size"
|
||||
>{bytesToSize(file.sizeOriginal)}</TableCellText>
|
||||
<TableCellText title="Date Created"
|
||||
>{toLocaleDate(file.$createdAt)}</TableCellText>
|
||||
<TableCell showOverflow>
|
||||
<DropList
|
||||
bind:show={showDropdown[index]}
|
||||
position="bottom"
|
||||
horizontal="left"
|
||||
arrow={false}>
|
||||
<button
|
||||
class="button is-only-icon is-text"
|
||||
aria-label="More options"
|
||||
on:click|preventDefault={() => {
|
||||
showDropdown[index] = !showDropdown[index];
|
||||
}}>
|
||||
<span class="icon-dots-horizontal" aria-hidden="true" />
|
||||
</button>
|
||||
<svelte:fragment slot="list">
|
||||
<DropListItem
|
||||
icon="pencil"
|
||||
on:click={(e) => {
|
||||
e.preventDefault();
|
||||
goto(
|
||||
`${base}/console/${project}/storage/bucket/${bucket}/file/${file.$id}`
|
||||
);
|
||||
}}>Update</DropListItem>
|
||||
<DropListItem
|
||||
icon="trash"
|
||||
on:click={(e) => {
|
||||
e.preventDefault();
|
||||
selectedFile = file;
|
||||
showDelete = true;
|
||||
}}>Delete</DropListItem>
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
</TableCell>
|
||||
</TableRowLink>
|
||||
{/if}
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {$files.total}</p>
|
||||
<Pagination {limit} bind:offset sum={$files.total} />
|
||||
</div>
|
||||
{:else if search}
|
||||
<Empty>
|
||||
<div class="u-flex u-flex-vertical">
|
||||
<b>Sorry, we couldn’t find ‘{search}’</b>
|
||||
<div class="common-section">
|
||||
<p>There are no files that match your search.</p>
|
||||
</div>
|
||||
</Empty>
|
||||
<div class="u-flex common-section u-main-space-between">
|
||||
<p class="text">Total results: {response.total}</p>
|
||||
<Pagination {limit} bind:offset sum={response.total} />
|
||||
</div>
|
||||
{:else}
|
||||
<Empty dashed centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<Button secondary round on:click={() => (showCreate = true)}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<p>Upload some files to get started</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary href="#">Documentation</Button>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
</Empty>
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {$files?.total}</p>
|
||||
<Pagination {limit} bind:offset sum={$files?.total} />
|
||||
</div>
|
||||
{:else}
|
||||
<Empty dashed centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<Button secondary round on:click={() => (showCreate = true)}>
|
||||
<i class="icon-plus" />
|
||||
</Button>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<p>Upload some files to get started</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary href="#">Documentation</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
</Container>
|
||||
|
||||
<Create bind:showCreate />
|
||||
<Update bind:showUpdate bind:file={currentFile} />
|
||||
<Create bind:showCreate on:created={fileCreated} />
|
||||
{#if selectedFile}
|
||||
<Delete file={selectedFile} bind:showDelete on:deleted={fileDeleted} />
|
||||
{/if}
|
||||
@@ -1,10 +1,469 @@
|
||||
<script>
|
||||
import { Card } from '$lib/components';
|
||||
<script lang="ts">
|
||||
import { Alert, CardGrid, Box } from '$lib/components';
|
||||
import { Container } from '$lib/layout';
|
||||
import {
|
||||
Button,
|
||||
InputText,
|
||||
InputTags,
|
||||
InputNumber,
|
||||
InputSelect,
|
||||
InputSwitch,
|
||||
Helper
|
||||
} from '$lib/elements/forms';
|
||||
import { bucket } from './store';
|
||||
import { toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { sizeToBytes } from '$lib/helpers/sizeConvertion';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import Delete from './_deleteBucket.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
let showDelete = false;
|
||||
let showError: false | 'name' | 'size' = false,
|
||||
errorMessage = 'Something went wrong',
|
||||
errorType: 'error' | 'warning' | 'success' = 'error';
|
||||
let enabled: boolean = null,
|
||||
bucketName: string = null,
|
||||
bucketPermissions: string = null,
|
||||
bucketRead: string[] = null,
|
||||
bucketWrite: string[] = null,
|
||||
arePermsDisabled = true,
|
||||
encryption: boolean = null,
|
||||
antivirus: boolean = null,
|
||||
maxSize: number;
|
||||
let byteUnit: 'Bytes' | 'KB' | 'MB' | 'GB' = 'Bytes',
|
||||
options = [
|
||||
{ label: 'Bytes', value: 'Bytes' },
|
||||
{ label: 'Kilobytes', value: 'KB' },
|
||||
{ label: 'Megabytes', value: 'MB' },
|
||||
{ label: 'Gigabytes', value: 'GB' }
|
||||
];
|
||||
let extensions = $bucket.allowedFileExtensions;
|
||||
let isExtensionsDisabled = true;
|
||||
|
||||
onMount(async () => {
|
||||
await bucket.load($page.params.bucket);
|
||||
enabled ??= $bucket.enabled;
|
||||
bucketName ??= $bucket.name;
|
||||
bucketName ??= $bucket.name;
|
||||
bucketPermissions ??= $bucket.permission;
|
||||
bucketRead ??= $bucket.$read;
|
||||
bucketWrite ??= $bucket.$write;
|
||||
encryption ??= $bucket.encryption;
|
||||
antivirus ??= $bucket.antivirus;
|
||||
});
|
||||
|
||||
$: if (bucketPermissions || bucketRead || bucketWrite) {
|
||||
if (bucketPermissions !== $bucket.permission) {
|
||||
arePermsDisabled = false;
|
||||
} else if (bucketRead) {
|
||||
if (JSON.stringify(bucketRead) !== JSON.stringify($bucket.$read)) {
|
||||
arePermsDisabled = false;
|
||||
} else arePermsDisabled = true;
|
||||
} else if (bucketWrite) {
|
||||
if (JSON.stringify(bucketWrite) !== JSON.stringify($bucket.$write)) {
|
||||
arePermsDisabled = false;
|
||||
} else arePermsDisabled = true;
|
||||
}
|
||||
}
|
||||
$: if (extensions) {
|
||||
if (JSON.stringify(extensions) !== JSON.stringify($bucket.allowedFileExtensions)) {
|
||||
isExtensionsDisabled = false;
|
||||
} else isExtensionsDisabled = true;
|
||||
}
|
||||
|
||||
function addError(location: typeof showError, message: string, type: typeof errorType) {
|
||||
showError = location;
|
||||
errorMessage = message;
|
||||
errorType = type;
|
||||
}
|
||||
|
||||
async function toggleBucket() {
|
||||
try {
|
||||
await sdkForProject.storage.updateBucket(
|
||||
$bucket.$id,
|
||||
$bucket.name,
|
||||
$bucket.permission,
|
||||
$bucket.$read,
|
||||
$bucket.$write,
|
||||
enabled
|
||||
);
|
||||
$bucket.enabled = enabled;
|
||||
addNotification({
|
||||
message: `${$bucket.name} has been updated`,
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
async function updateName() {
|
||||
try {
|
||||
await sdkForProject.storage.updateBucket($bucket.$id, $bucket.name, $bucket.permission);
|
||||
$bucket.name = bucketName;
|
||||
showError = false;
|
||||
addNotification({
|
||||
message: 'Name has been updated',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addError('name', error.message, 'error');
|
||||
}
|
||||
}
|
||||
async function updatePermissions() {
|
||||
try {
|
||||
await sdkForProject.storage.updateBucket(
|
||||
$bucket.$id,
|
||||
$bucket.name,
|
||||
bucketPermissions,
|
||||
bucketPermissions === 'bucket' ? bucketRead : $bucket.$read,
|
||||
bucketPermissions === 'bucket' ? bucketWrite : $bucket.$write
|
||||
);
|
||||
$bucket.permission = bucketPermissions;
|
||||
$bucket.$read = bucketRead;
|
||||
$bucket.$write = bucketWrite;
|
||||
arePermsDisabled = true;
|
||||
addNotification({
|
||||
message: 'Permissions have been updated',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function updateSecurity() {
|
||||
try {
|
||||
await sdkForProject.storage.updateBucket(
|
||||
$bucket.$id,
|
||||
$bucket.name,
|
||||
$bucket.permission,
|
||||
$bucket.$read,
|
||||
$bucket.$write,
|
||||
$bucket.enabled,
|
||||
$bucket.maximumFileSize,
|
||||
$bucket.allowedFileExtensions,
|
||||
encryption,
|
||||
antivirus
|
||||
);
|
||||
$bucket.encryption = encryption;
|
||||
$bucket.antivirus = antivirus;
|
||||
addNotification({
|
||||
message: `${$bucket.name} has been updatede`,
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
async function updateMaxSize() {
|
||||
let size = sizeToBytes(maxSize, byteUnit);
|
||||
console.log(size);
|
||||
try {
|
||||
await sdkForProject.storage.updateBucket(
|
||||
$bucket.$id,
|
||||
$bucket.name,
|
||||
$bucket.permission,
|
||||
$bucket.$read,
|
||||
$bucket.$write,
|
||||
$bucket.enabled,
|
||||
size
|
||||
);
|
||||
$bucket.maximumFileSize = maxSize;
|
||||
addNotification({
|
||||
message: `${$bucket.name} has been updatede`,
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function updateAllowedExtensions() {
|
||||
try {
|
||||
await sdkForProject.storage.updateBucket(
|
||||
$bucket.$id,
|
||||
$bucket.name,
|
||||
$bucket.permission,
|
||||
$bucket.$read,
|
||||
$bucket.$write,
|
||||
$bucket.enabled,
|
||||
$bucket.maximumFileSize,
|
||||
extensions
|
||||
);
|
||||
$bucket.allowedFileExtensions = extensions;
|
||||
addNotification({
|
||||
message: `${$bucket.name} has been updatede`,
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
<h1>Settings</h1>
|
||||
{#if $bucket}
|
||||
<CardGrid>
|
||||
<h2 class="heading-level-7">{$bucket.name}</h2>
|
||||
|
||||
<Card />
|
||||
<svelte:fragment slot="aside">
|
||||
<ul>
|
||||
<InputSwitch
|
||||
label={enabled ? 'Enabled' : 'Disabled'}
|
||||
id="toggle"
|
||||
bind:value={enabled} />
|
||||
</ul>
|
||||
<p>Created: {toLocaleDateTime($bucket.$createdAt)}</p>
|
||||
<p>Last Updated: {toLocaleDateTime($bucket.$updatedAt)}</p>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={enabled === $bucket.enabled}
|
||||
on:click={() => {
|
||||
toggleBucket();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Update Name</h6>
|
||||
|
||||
<svelte:fragment slot="aside">
|
||||
<ul>
|
||||
<InputText
|
||||
id="name"
|
||||
label="Name"
|
||||
placeholder="Enter name"
|
||||
autocomplete={false}
|
||||
bind:value={bucketName} />
|
||||
{#if showError === 'name'}
|
||||
<Helper type={errorType}>{errorMessage}</Helper>
|
||||
{/if}
|
||||
</ul>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={bucketName === $bucket.name || !bucketName}
|
||||
on:click={() => {
|
||||
updateName();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Update Permissions</h6>
|
||||
<p>
|
||||
Assign read or write permissions at the <b>Bucket Level</b> or
|
||||
<b>File Level</b>. If Bucket Level permissions are assigned, file permissions will
|
||||
be ignored.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<ul class="u-flex u-gap-12 common-section">
|
||||
<li>
|
||||
<label class="label">
|
||||
<input
|
||||
type="radio"
|
||||
class="is-small"
|
||||
name="level"
|
||||
bind:group={bucketPermissions}
|
||||
value="bucket" />
|
||||
<span>Bucket Level</span>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label class="label">
|
||||
<input
|
||||
type="radio"
|
||||
class="is-small"
|
||||
name="level"
|
||||
bind:group={bucketPermissions}
|
||||
value="file" />
|
||||
<span>File Level</span>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
<Alert type="info">
|
||||
<p>
|
||||
Tip: Add <b>role:all</b> for wildcards access. Check out our documentation
|
||||
for more on <a href="/#">Permissions</a>
|
||||
</p>
|
||||
</Alert>
|
||||
{#if bucketPermissions === 'bucket'}
|
||||
<ul class="common-section">
|
||||
<InputTags
|
||||
id="read"
|
||||
label="Read Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={bucketRead} />
|
||||
<InputTags
|
||||
id="write"
|
||||
label="Write Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={bucketWrite} />
|
||||
</ul>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={arePermsDisabled}
|
||||
on:click={() => {
|
||||
updatePermissions();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<CardGrid>
|
||||
<h2 class="heading-level-7">Update Security Settings</h2>
|
||||
<p>
|
||||
Enable or disable security services for the bucket including <b> Ecryption</b>
|
||||
and <b> Antivirus scanning.</b>
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<ul class="form-list">
|
||||
<li class="form-item">
|
||||
<label class="choice-item" for="encryption">
|
||||
<div class="input-text-wrapper">
|
||||
<input
|
||||
label="Encryption"
|
||||
id="encryption"
|
||||
type="checkbox"
|
||||
class="switch"
|
||||
role="switch"
|
||||
bind:checked={encryption} />
|
||||
</div>
|
||||
<div class="choice-item-content">
|
||||
<div class="choice-item-title">Encryption</div>
|
||||
|
||||
<div class="choice-item-paragraph">
|
||||
This parameter allows you to configure whether or not the files
|
||||
inside the bucket will be encrypted. We don't encrypt files
|
||||
bigger than 20MB.
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
</li>
|
||||
<li class="form-item">
|
||||
<label class="choice-item" for="antivirus">
|
||||
<div class="input-text-wrapper">
|
||||
<input
|
||||
label="Antivirus"
|
||||
id="antivirus"
|
||||
type="checkbox"
|
||||
class="switch"
|
||||
role="switch"
|
||||
bind:checked={antivirus} />
|
||||
</div>
|
||||
<div class="choice-item-content">
|
||||
<div class="choice-item-title">Antivirus</div>
|
||||
|
||||
<div class="choice-item-paragraph">
|
||||
This parameter allows you to configure whether or not the files
|
||||
inside the bucket should be scanned by the Appwrite Antivirus
|
||||
scanner.
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
</li>
|
||||
|
||||
<li />
|
||||
</ul>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={encryption === $bucket.encryption && antivirus === $bucket.antivirus}
|
||||
on:click={() => {
|
||||
updateSecurity();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<CardGrid>
|
||||
<h2 class="heading-level-6">Update Maximum File Size</h2>
|
||||
<p>Set the maximum file size allowed in the bucket.</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<ul class="u-flex u-gap-12">
|
||||
<InputNumber
|
||||
id="size"
|
||||
label="Size"
|
||||
placeholder={$bucket.maximumFileSize + ''}
|
||||
bind:value={maxSize} />
|
||||
<InputSelect id="bytes" label="Bytes" {options} bind:value={byteUnit} />
|
||||
</ul>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={!maxSize}
|
||||
on:click={() => {
|
||||
updateMaxSize();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Update Allowed File Extensions</h6>
|
||||
<p>
|
||||
A maxiumum of 100 file extensions can be added. Leave blank to allow all file types.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Alert type="info">
|
||||
<p>
|
||||
Tip: Commonly added extensions include JPG, PNG, SVG, GIF, HTML, PDF, MP4.
|
||||
</p>
|
||||
</Alert>
|
||||
<ul class="common-section">
|
||||
<InputTags
|
||||
id="read"
|
||||
label="Allowed file extensions"
|
||||
placeholder="Allowed file extensions (mp4, jpg, pdf, etc.)"
|
||||
bind:tags={extensions} />
|
||||
</ul>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={isExtensionsDisabled}
|
||||
on:click={() => {
|
||||
updateAllowedExtensions();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Delete Bucket</h6>
|
||||
<p>
|
||||
The bucket will be permanently deleted, including all the files within it. This
|
||||
action is irreversible.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Box>
|
||||
<svelte:fragment slot="title">
|
||||
<h6 class="u-bold">{$bucket.name}</h6>
|
||||
</svelte:fragment>
|
||||
<p>Last Updated: {toLocaleDateTime($bucket.$updatedAt)}</p>
|
||||
</Box>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
{/if}
|
||||
</Container>
|
||||
|
||||
<Delete bind:showDelete />
|
||||
@@ -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<Models.Bucket>();
|
||||
const { subscribe, set } = writable<Models.Bucket>(
|
||||
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<Models.FileList>(
|
||||
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 ?? '')));
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Empty, Pagination, Tiles, Tooltip, Copy } from '$lib/components';
|
||||
import { Empty, Pagination, Tooltip, Copy, Bucket } from '$lib/components';
|
||||
import { Pill } from '$lib/elements';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import Create from './_create.svelte';
|
||||
import { Container } from '$lib/layout';
|
||||
import { base } from '$app/paths';
|
||||
import { bucketList } from './store';
|
||||
|
||||
let showCreate = false;
|
||||
let search = '';
|
||||
@@ -21,7 +21,7 @@
|
||||
await goto(`${base}/console/${project}/storage/bucket/${event.detail.$id}`);
|
||||
};
|
||||
|
||||
$: request = sdkForProject.storage.listBuckets(search, limit, offset);
|
||||
$: bucketList.load(search, limit, offset ?? 0);
|
||||
$: if (search) offset = 0;
|
||||
</script>
|
||||
|
||||
@@ -30,87 +30,113 @@
|
||||
<h2 class="heading-level-5">Buckets</h2>
|
||||
|
||||
<Button on:click={() => (showCreate = true)}>
|
||||
<span class="icon-plus" aria-hidden="true" /> <span class="text">Add Bucket</span>
|
||||
<span class="icon-plus" aria-hidden="true" /> <span class="text">Add bucket</span>
|
||||
</Button>
|
||||
</div>
|
||||
{#await request}
|
||||
<div aria-busy="true" />
|
||||
{:then response}
|
||||
{#if response.total}
|
||||
<Tiles>
|
||||
{#each response.buckets as bucket}
|
||||
<a
|
||||
class="card"
|
||||
href={`${base}/console/${project}/storage/bucket/${bucket.$id}`}>
|
||||
<div class="u-flex u-main-space-between">
|
||||
<span class="is-small">XX Files</span>
|
||||
{#if !bucket.enabled}
|
||||
<Pill>Disabled</Pill>
|
||||
{/if}
|
||||
</div>
|
||||
<h3 class="tiles-title">{bucket.name}</h3>
|
||||
<div class="u-flex u-main-space-between">
|
||||
<Copy value={bucket.$id}>
|
||||
<Pill button
|
||||
><span class="icon-duplicate" aria-hidden="true" />Bucket ID</Pill>
|
||||
</Copy>
|
||||
<div class="">
|
||||
<Tooltip icon="lock-closed" aria="encryption">
|
||||
<span
|
||||
>{bucket.encryption
|
||||
? 'Encryption enabled'
|
||||
: 'Encryption disabled'}</span>
|
||||
</Tooltip>
|
||||
<Tooltip icon="shield-check" aria="antivirus">
|
||||
<span
|
||||
>{bucket.antivirus
|
||||
? 'Antivirus enabled'
|
||||
: 'Antivirus disabled'}</span>
|
||||
</Tooltip>
|
||||
|
||||
{#if $bucketList?.total}
|
||||
<li
|
||||
class="grid-box common-section"
|
||||
style={`--grid-gap:2rem; --grid-item-size:${
|
||||
$bucketList.total > 3 ? '22rem' : '25rem'
|
||||
};`}>
|
||||
{#each $bucketList.buckets as bucket}
|
||||
<Bucket href={`${base}/console/${project}/storage/bucket/${bucket.$id}`}>
|
||||
<svelte:fragment slot="eyebrow">XX Files</svelte:fragment>
|
||||
<svelte:fragment slot="title">{bucket.name}</svelte:fragment>
|
||||
<svelte:fragment slot="status">
|
||||
{#if !bucket.enabled}
|
||||
<Pill>Disabled</Pill>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
<Copy value={bucket.$id}>
|
||||
<Pill button><i class="icon-duplicate" />Bucket ID</Pill>
|
||||
</Copy>
|
||||
|
||||
<svelte:fragment slot="icons">
|
||||
<li>
|
||||
<Tooltip
|
||||
icon="lock-closed"
|
||||
aria="encryption"
|
||||
disabled={!bucket.encryption}>
|
||||
<span
|
||||
>{bucket.encryption
|
||||
? 'Encryption enabled'
|
||||
: 'Encryption disabled'}</span>
|
||||
</Tooltip>
|
||||
</li>
|
||||
<li>
|
||||
<Tooltip
|
||||
icon="shield-check"
|
||||
aria="antivirus"
|
||||
disabled={!bucket.antivirus}>
|
||||
<span
|
||||
>{bucket.antivirus
|
||||
? 'Antivirus enabled'
|
||||
: 'Antivirus disabled'}</span>
|
||||
</Tooltip>
|
||||
</li>
|
||||
</svelte:fragment>
|
||||
</Bucket>
|
||||
{/each}
|
||||
{#if $bucketList.total % 2 !== 0}
|
||||
<article class="card is-border-dashed">
|
||||
<div class="bucket">
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<Button secondary round on:click={() => (showCreate = true)}>
|
||||
<i class="icon-plus" />
|
||||
</Button>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<p>Add a new bucket</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{/each}
|
||||
</Tiles>
|
||||
</div>
|
||||
</article>
|
||||
{/if}
|
||||
</li>
|
||||
|
||||
<div class="u-flex common-section u-main-space-between">
|
||||
<p class="text">Total results: {response.total}</p>
|
||||
<Pagination {limit} bind:offset sum={response.total} />
|
||||
</div>
|
||||
{:else if search}
|
||||
<Empty>
|
||||
<div class="u-flex u-flex-vertical">
|
||||
<b>Sorry, we couldn’t find ‘{search}’</b>
|
||||
<div class="common-section">
|
||||
<p>There are no buckets that match your search.</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
|
||||
</div>
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {$bucketList.total}</p>
|
||||
<Pagination {limit} bind:offset sum={$bucketList.total} />
|
||||
</div>
|
||||
{:else if search}
|
||||
<Empty>
|
||||
<div class="u-flex u-flex-vertical">
|
||||
<b>Sorry, we couldn’t find ‘{search}’</b>
|
||||
<div class="common-section">
|
||||
<p>There are no buckets that match your search.</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
|
||||
</div>
|
||||
</Empty>
|
||||
<div class="u-flex common-section u-main-space-between">
|
||||
<p class="text">Total results: {response.total}</p>
|
||||
<Pagination {limit} bind:offset sum={response.total} />
|
||||
</div>
|
||||
{:else}
|
||||
<Empty dashed centered>
|
||||
</Empty>
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {$bucketList?.total}</p>
|
||||
<Pagination {limit} bind:offset sum={$bucketList?.total} />
|
||||
</div>
|
||||
{:else}
|
||||
<Empty dashed centered>
|
||||
<div class="bucket">
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<Button secondary round on:click={() => (showCreate = true)}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<i class="icon-plus" />
|
||||
</Button>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<p>Add Your First Bucket To Get Started</p>
|
||||
<p>Add your first bucket to get started</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary href="#">Documentation</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
</Container>
|
||||
|
||||
<Create bind:showCreate on:created={bucketCreated} />
|
||||
@@ -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<Models.BucketList>(
|
||||
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 ?? '')));
|
||||
}
|
||||
Reference in new issue
Block a user