Skip to content

Commit

Permalink
Create new version on file upload conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
TimCsaky committed Dec 6, 2024
1 parent 3fc8bfd commit 3d643d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion frontend/src/components/object/ObjectUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/store/objectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3d643d2

Please sign in to comment.