Skip to content

Commit

Permalink
Merge pull request #1358 from appwrite/revert-1312-fix-upload-context…
Browse files Browse the repository at this point in the history
…-switches

Revert "Fix: Upload Context Switches"
  • Loading branch information
christyjacob4 committed Sep 19, 2024
2 parents 3acbaa2 + d1ca240 commit 0b146b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
18 changes: 3 additions & 15 deletions src/lib/stores/uploader.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Uploader>({
isOpen: false,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
});
</script>

<Container>
Expand Down

0 comments on commit 0b146b8

Please sign in to comment.