Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Retry a file download once if its cached object URL fails

Manav Rathida02b0c7e632
diff --git a/web/apps/albums/src/public-album/download/services/download-manager.ts b/web/apps/albums/src/public-album/download/services/download-manager.ts
index 56f16a1991..02a829fa6b 100644
--- a/web/apps/albums/src/public-album/download/services/download-manager.ts
+++ b/web/apps/albums/src/public-album/download/services/download-manager.ts
@@ -356,9 +356,24 @@ class DownloadManager {
* it into a {@link Blob}.
*/
async fileBlob(file: EnteFile, opts?: FileDownloadOpts) {
- return this.fileStream(file, opts).then((stream) =>
- this.blobWithInferredType(file, stream),
- );
+ const _fileBlob = () =>
+ this.fileStream(file, opts).then((stream) =>
+ this.blobWithInferredType(file, stream),
+ );
+
+ const cachedURL = this.fileURLPromises.get(file.id);
+ try {
+ return await _fileBlob();
+ } catch (e) {
+ // If the stream came from a cached object URL then retry once
+ // to rule out issues with the cache.
+ if (cachedURL && this.fileURLPromises.get(file.id) == cachedURL) {
+ this.fileURLPromises.delete(file.id);
+ return _fileBlob();
+ } else {
+ throw e;
+ }
+ }
}
/**
diff --git a/web/packages/gallery/services/download.ts b/web/packages/gallery/services/download.ts
index 7b3fa9727c..05db7bacf7 100644
--- a/web/packages/gallery/services/download.ts
+++ b/web/packages/gallery/services/download.ts
@@ -402,9 +402,24 @@ class DownloadManager {
* it into a {@link Blob}.
*/
async fileBlob(file: EnteFile, opts?: FileDownloadOpts) {
- return this.fileStream(file, opts).then((stream) =>
- this.blobWithInferredType(file, stream),
- );
+ const _fileBlob = () =>
+ this.fileStream(file, opts).then((stream) =>
+ this.blobWithInferredType(file, stream),
+ );
+
+ const cachedURL = this.fileURLPromises.get(file.id);
+ try {
+ return await _fileBlob();
+ } catch (e) {
+ // If the stream came from a cached object URL then retry once
+ // to rule out issues with the cache.
+ if (cachedURL && this.fileURLPromises.get(file.id) == cachedURL) {
+ this.fileURLPromises.delete(file.id);
+ return _fileBlob();
+ } else {
+ throw e;
+ }
+ }
}
/**