Skip to content

Commit

Permalink
fix(web): mismatched deviceAssetId when uploading images
Browse files Browse the repository at this point in the history
  • Loading branch information
jinxuan-owyong committed Jan 7, 2025
1 parent 6fd9f93 commit 1ef38cb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions web/src/lib/utils/file-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,19 @@ export const openFileUploadDialog = async (options: FileUploadParam = {}) => {
});
};

export const fileUploadHandler = async (files: File[], albumId?: string, assetId?: string): Promise<string[]> => {
export const fileUploadHandler = async (
files: File[],
albumId?: string,
replaceAssetId?: string,
): Promise<string[]> => {
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)));
}
}

Expand All @@ -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<string | undefined> {
async function fileUploader(
assetFile: File,
deviceAssetId: string,
albumId?: string,
replaceAssetId?: string,
): Promise<string | undefined> {
const fileCreatedAt = new Date(assetFile.lastModified).toISOString();
const deviceAssetId = getDeviceAssetId(assetFile);
const $t = get(t);

uploadAssetsStore.markStarted(deviceAssetId);
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 1ef38cb

Please sign in to comment.