From 339cd3ed892351d3d3dfbdb69a5fa58111c14f31 Mon Sep 17 00:00:00 2001 From: ItzNotABug Date: Sun, 14 Jul 2024 19:42:49 +0530 Subject: [PATCH 1/3] fix: stuck uploader progress. --- src/lib/stores/uploader.ts | 8 +++++++- .../storage/bucket-[bucket]/create-file/create.svelte | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/stores/uploader.ts b/src/lib/stores/uploader.ts index 867dc38564..c90d52891b 100644 --- a/src/lib/stores/uploader.ts +++ b/src/lib/stores/uploader.ts @@ -79,7 +79,7 @@ const createUploader = () => { (p) => { newFile.$id = p.$id; newFile.progress = p.progress; - newFile.completed = p.progress === 100 ? true : false; + newFile.completed = p.progress === 100; updateFile(p.$id, newFile); } ); @@ -94,6 +94,12 @@ const createUploader = () => { return n; }); }, + removeAtIndex: (itemIndex: number) => { + update((n) => { + n.files = n.files.filter((_file, index) => index !== itemIndex); + return n; + }); + }, removeFile: async (file: Models.File) => { if (file.chunksTotal === file.chunksUploaded) { return update((n) => { diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte index 66315f0ddd..57f75e9ea7 100644 --- a/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte +++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte @@ -29,7 +29,7 @@ async function create() { try { - uploader.uploadFile( + const uploadPromise = uploader.uploadFile( bucketId, $createFile.id ?? ID.unique(), $createFile.files[0], @@ -47,7 +47,11 @@ trackEvent(Submit.FileCreate, { customId: !!$createFile.id }); + + await uploadPromise; } catch (e) { + uploader.removeAtIndex(0); + addNotification({ type: 'error', message: e.message From 0bb957059396e162c85146e42fc518dacf89c9fe Mon Sep 17 00:00:00 2001 From: ItzNotABug Date: Wed, 17 Jul 2024 11:45:18 +0530 Subject: [PATCH 2/3] update: use file id to remove from queue. --- src/lib/stores/uploader.ts | 6 ------ .../storage/bucket-[bucket]/create-file/create.svelte | 6 ++++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/lib/stores/uploader.ts b/src/lib/stores/uploader.ts index c90d52891b..28bd29a813 100644 --- a/src/lib/stores/uploader.ts +++ b/src/lib/stores/uploader.ts @@ -94,12 +94,6 @@ const createUploader = () => { return n; }); }, - removeAtIndex: (itemIndex: number) => { - update((n) => { - n.files = n.files.filter((_file, index) => index !== itemIndex); - return n; - }); - }, removeFile: async (file: Models.File) => { if (file.chunksTotal === file.chunksUploaded) { return update((n) => { diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte index 57f75e9ea7..a82bf186ef 100644 --- a/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte +++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte @@ -28,10 +28,12 @@ }); async function create() { + const fileId = $createFile.id ?? ID.unique(); + try { const uploadPromise = uploader.uploadFile( bucketId, - $createFile.id ?? ID.unique(), + fileId, $createFile.files[0], $createFile.permissions ); @@ -50,7 +52,7 @@ await uploadPromise; } catch (e) { - uploader.removeAtIndex(0); + uploader.removeFromQueue(fileId); addNotification({ type: 'error', From dcc36e1ef9bfbd53f28978a571328a23f56999a4 Mon Sep 17 00:00:00 2001 From: ItzNotABug Date: Mon, 29 Jul 2024 12:19:09 +0530 Subject: [PATCH 3/3] fix: minor improvements. --- src/lib/stores/uploader.ts | 1 + .../storage/bucket-[bucket]/create-file/create.svelte | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/stores/uploader.ts b/src/lib/stores/uploader.ts index 28bd29a813..a0d2c562df 100644 --- a/src/lib/stores/uploader.ts +++ b/src/lib/stores/uploader.ts @@ -91,6 +91,7 @@ const createUploader = () => { removeFromQueue: (id: string) => { update((n) => { n.files = n.files.filter((f) => f.$id !== id); + n.isOpen = n.files.length !== 0; return n; }); }, diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte index a82bf186ef..92a1e965d5 100644 --- a/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte +++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/create-file/create.svelte @@ -40,7 +40,6 @@ createFile.reset(); wizard.hide(); - invalidate(Dependencies.FILES); addNotification({ type: 'success', @@ -51,6 +50,7 @@ }); await uploadPromise; + invalidate(Dependencies.FILES); } catch (e) { uploader.removeFromQueue(fileId);