diff --git a/web/src/lib/utils/file-uploader.ts b/web/src/lib/utils/file-uploader.ts index 2e31605e91605..407501e6229f1 100644 --- a/web/src/lib/utils/file-uploader.ts +++ b/web/src/lib/utils/file-uploader.ts @@ -83,14 +83,19 @@ export const openFileUploadDialog = async (options: FileUploadParam = {}) => { }); }; -export const fileUploadHandler = async (files: File[], albumId?: string, assetId?: string): Promise => { +export const fileUploadHandler = async ( + files: File[], + albumId?: string, + replaceAssetId?: string, +): Promise => { const extensions = await getExtensions(); const promises = []; for (const file of files) { const name = file.name.toLowerCase(); if (extensions.some((extension) => name.endsWith(extension))) { - uploadAssetsStore.addItem({ id: getDeviceAssetId(file), file, albumId }); - promises.push(uploadExecutionQueue.addTask(() => fileUploader(file, albumId, assetId))); + const deviceAssetId = getDeviceAssetId(file); + uploadAssetsStore.addItem({ id: deviceAssetId, file, albumId }); + promises.push(uploadExecutionQueue.addTask(() => fileUploader(file, deviceAssetId, albumId, replaceAssetId))); } } @@ -103,9 +108,13 @@ function getDeviceAssetId(asset: File) { } // TODO: should probably use the @api SDK -async function fileUploader(assetFile: File, albumId?: string, replaceAssetId?: string): Promise { +async function fileUploader( + assetFile: File, + deviceAssetId: string, + albumId?: string, + replaceAssetId?: string, +): Promise { const fileCreatedAt = new Date(assetFile.lastModified).toISOString(); - const deviceAssetId = getDeviceAssetId(assetFile); const $t = get(t); uploadAssetsStore.markStarted(deviceAssetId); @@ -148,6 +157,7 @@ async function fileUploader(assetFile: File, albumId?: string, replaceAssetId?: } } catch (error) { console.error(`Error calculating sha1 file=${assetFile.name})`, error); + throw error; } }