Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): mismatched deviceAssetId when uploading images #15130

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading