mirror of
https://github.com/immich-app/immich.git
synced 2025-06-03 13:44:16 -04:00
fix(web): album download progress bar (#925)
This commit is contained in:
parent
0d7ccc2b26
commit
86e50f97ba
@ -121,8 +121,9 @@ export class AlbumController {
|
|||||||
@Param('albumId', new ParseUUIDPipe({ version: '4' })) albumId: string,
|
@Param('albumId', new ParseUUIDPipe({ version: '4' })) albumId: string,
|
||||||
@Response({ passthrough: true }) res: Res,
|
@Response({ passthrough: true }) res: Res,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const { stream, filename } = await this.albumService.downloadArchive(authUser, albumId);
|
const { stream, filename, filesize } = await this.albumService.downloadArchive(authUser, albumId);
|
||||||
res.attachment(filename);
|
res.attachment(filename);
|
||||||
|
res.setHeader('X-Immich-Content-Length-Hint', filesize);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,11 +171,13 @@ export class AlbumService {
|
|||||||
try {
|
try {
|
||||||
const archive = archiver('zip', { store: true });
|
const archive = archiver('zip', { store: true });
|
||||||
const stream = new StreamableFile(archive);
|
const stream = new StreamableFile(archive);
|
||||||
|
let totalSize = 0;
|
||||||
|
|
||||||
for (const { assetInfo } of album.assets) {
|
for (const { assetInfo } of album.assets) {
|
||||||
const { originalPath } = assetInfo;
|
const { originalPath } = assetInfo;
|
||||||
const name = `${assetInfo.exifInfo?.imageName || assetInfo.id}${extname(originalPath)}`;
|
const name = `${assetInfo.exifInfo?.imageName || assetInfo.id}${extname(originalPath)}`;
|
||||||
archive.file(originalPath, { name });
|
archive.file(originalPath, { name });
|
||||||
|
totalSize += Number(assetInfo.exifInfo?.fileSizeInByte || 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
archive.finalize();
|
archive.finalize();
|
||||||
@ -183,6 +185,7 @@ export class AlbumService {
|
|||||||
return {
|
return {
|
||||||
stream,
|
stream,
|
||||||
filename: `${album.albumName}.zip`,
|
filename: `${album.albumName}.zip`,
|
||||||
|
filesize: totalSize,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.error(`Error downloading album ${e}`, 'downloadArchive');
|
Logger.error(`Error downloading album ${e}`, 'downloadArchive');
|
||||||
|
@ -322,8 +322,20 @@
|
|||||||
|
|
||||||
$downloadAssets[fileName] = 0;
|
$downloadAssets[fileName] = 0;
|
||||||
|
|
||||||
|
let total = 0;
|
||||||
const { data, status } = await api.albumApi.downloadArchive(album.id, {
|
const { data, status } = await api.albumApi.downloadArchive(album.id, {
|
||||||
responseType: 'blob'
|
responseType: 'blob',
|
||||||
|
onDownloadProgress: function (progressEvent) {
|
||||||
|
const request = this as XMLHttpRequest;
|
||||||
|
if (!total) {
|
||||||
|
total = Number(request.getResponseHeader('X-Immich-Content-Length-Hint')) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (total) {
|
||||||
|
const current = progressEvent.loaded;
|
||||||
|
$downloadAssets[fileName] = Math.floor((current / total) * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!(data instanceof Blob)) {
|
if (!(data instanceof Blob)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user