From d1ca240a5ad76bbd3a40c1d90f139b95ed9c1583 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 20 Sep 2024 01:32:49 +0400 Subject: [PATCH] Revert "Fix: Upload Context Switches" --- src/lib/stores/uploader.ts | 18 +++---------- .../storage/bucket-[bucket]/+page.svelte | 25 ------------------- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/src/lib/stores/uploader.ts b/src/lib/stores/uploader.ts index 7bc15b88cb..a0d2c562df 100644 --- a/src/lib/stores/uploader.ts +++ b/src/lib/stores/uploader.ts @@ -1,7 +1,6 @@ -import { Client, type Models, Storage } from '@appwrite.io/console'; +import type { Models } from '@appwrite.io/console'; import { writable } from 'svelte/store'; -import { getProjectId } from '$lib/helpers/project'; -import { VARS } from '$lib/system'; +import { sdk } from './sdk'; type UploaderFile = { $id: string; @@ -18,17 +17,6 @@ export type Uploader = { files: UploaderFile[]; }; -const temporaryStorage = () => { - const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`; - - const clientProject = new Client() - .setEndpoint(endpoint) - .setMode('admin') - .setProject(getProjectId()); - - return new Storage(clientProject); -}; - const createUploader = () => { const { subscribe, set, update } = writable({ isOpen: false, @@ -83,7 +71,7 @@ const createUploader = () => { n.files.unshift(newFile); return n; }); - const uploadedFile = await temporaryStorage().createFile( + const uploadedFile = await sdk.forProject.storage.createFile( bucketId, id ?? 'unique()', file, diff --git a/src/routes/(console)/project-[project]/storage/bucket-[bucket]/+page.svelte b/src/routes/(console)/project-[project]/storage/bucket-[bucket]/+page.svelte index 26761846df..e9a7fc50b3 100644 --- a/src/routes/(console)/project-[project]/storage/bucket-[bucket]/+page.svelte +++ b/src/routes/(console)/project-[project]/storage/bucket-[bucket]/+page.svelte @@ -50,7 +50,6 @@ import Create from './create-file/create.svelte'; import DeleteFile from './deleteFile.svelte'; import { isCloud } from '$lib/system'; - import { onMount } from 'svelte'; export let data; @@ -91,30 +90,6 @@ $: maxFileSize = isCloud ? humanFileSize(sizeToBytes(getServiceLimit('fileSize'), 'MB', 1000)) : null; - - let isUploading = false; - - const handleBeforeUnload = (event: BeforeUnloadEvent) => { - if (isUploading) { - event.preventDefault(); - event.returnValue = 'An upload is in progress. Are you sure you want to leave?'; - } - }; - - onMount(() => { - const unsubscribe = uploader.subscribe(() => { - isUploading = $uploader.files.some( - (file) => (!file.completed || file.progress < 100) && !file.failed - ); - }); - - window.addEventListener('beforeunload', handleBeforeUnload); - - return () => { - unsubscribe(); - window.removeEventListener('beforeunload', handleBeforeUnload); - }; - });