Skip to content

Commit

Permalink
fix(web): download livephotos video part correctly (immich-app#3230)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextran1502 authored Jul 13, 2023
1 parent b71d7e3 commit 863e983
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions web/src/lib/utils/asset-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,35 @@ export const downloadArchive = async (
};

export const downloadFile = async (asset: AssetResponseDto, key?: string) => {
const filenames = [`${asset.originalFileName}.${getFilenameExtension(asset.originalPath)}`];
const assets = [{ filename: `${asset.originalFileName}.${getFilenameExtension(asset.originalPath)}`, id: asset.id }];
if (asset.livePhotoVideoId) {
filenames.push(`${asset.originalFileName}.mov`);
assets.push({
filename: `${asset.originalFileName}.mov`,
id: asset.livePhotoVideoId,
});
}

for (const filename of filenames) {
for (const asset of assets) {
try {
updateDownload(filename, 0);
updateDownload(asset.filename, 0);

const { data } = await api.assetApi.downloadFile(
{ id: asset.id, key },
{
responseType: 'blob',
onDownloadProgress: (event: ProgressEvent) => {
if (event.lengthComputable) {
updateDownload(filename, Math.floor((event.loaded / event.total) * 100));
updateDownload(asset.filename, Math.floor((event.loaded / event.total) * 100));
}
},
},
);

downloadBlob(data, filename);
downloadBlob(data, asset.filename);
} catch (e) {
handleError(e, `Error downloading ${filename}`);
handleError(e, `Error downloading ${asset.filename}`);
} finally {
setTimeout(() => clearDownload(filename), 3_000);
setTimeout(() => clearDownload(asset.filename), 3_000);
}
}
};
Expand Down

0 comments on commit 863e983

Please sign in to comment.