From 3d643d291df614ced678de45f8ebda440d39acef Mon Sep 17 00:00:00 2001 From: Csaky Date: Thu, 5 Dec 2024 16:57:34 -0800 Subject: [PATCH] Create new version on file upload conflict --- frontend/src/components/object/ObjectUpload.vue | 6 +++++- frontend/src/store/objectStore.ts | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/object/ObjectUpload.vue b/frontend/src/components/object/ObjectUpload.vue index a34921b4..da3438f9 100644 --- a/frontend/src/components/object/ObjectUpload.vue +++ b/frontend/src/components/object/ObjectUpload.vue @@ -55,12 +55,16 @@ const onUpload = async (event: any) => { const data = formData.find((x: ObjectMetadataTagFormType) => x.filename === file.name); - await objectStore.createObject( + const response = await objectStore.createObject( file, { metadata: data?.metadata }, { bucketId: bucketId, tagset: data?.tagset }, { timeout: 0 } // Infinite timeout for big files upload to avoid timeout error ); + + // show toast for any object updates + if (response?.newVersionId) toast.info(`New version created for ${file.name}`,''); + successfulFiles.value.push(file); } catch (error: any) { toast.error(`Failed to upload file ${file.name}`, error, { life: 0 }); diff --git a/frontend/src/store/objectStore.ts b/frontend/src/store/objectStore.ts index 58b60ffe..6c40322a 100644 --- a/frontend/src/store/objectStore.ts +++ b/frontend/src/store/objectStore.ts @@ -66,8 +66,20 @@ export const useObjectStore = defineStore('object', () => { await objectService.createObject(object, headers, params, axiosOptions); } catch(error: any) { if (error.response?.status === 409){ - throw new Error(error.response.data.detail); - } else { + // New behaviour: + // if file already exists in bucket + // do updateObject operation instead + const newVersionId = await updateObject( + error.response.data.existingObjectId, + object, + headers, + params, + axiosOptions + ); + return { newVersionId: newVersionId }; + } + + else { throw new Error('Network error'); } } finally {