Skip to content

armgit / ente

Public Imported from GitHub
0

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

Outline

Manav Rathi8dd4a178dd19
diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.ts
index 060b34172e..5b22475e4a 100644
--- a/web/apps/photos/src/services/upload-manager.ts
+++ b/web/apps/photos/src/services/upload-manager.ts
@@ -257,9 +257,8 @@ const groupByResult = (finishedUploads: FinishedUploads) => {
};
class UploadManager {
- private comlinkCryptoWorkers = new Array<
- ComlinkWorker<typeof CryptoWorker>
- >(maxConcurrentUploads);
+ private comlinkCryptoWorkers: ComlinkWorker<typeof CryptoWorker>[] =
+ new Array(maxConcurrentUploads);
private parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>;
private itemsToBeUploaded: ClusteredUploadItem[];
private failedItems: ClusteredUploadItem[];
@@ -269,15 +268,14 @@ class UploadManager {
private uploadInProgress: boolean;
private publicAlbumsCredentials: PublicAlbumsCredentials | undefined;
private uploaderName: string;
- private uiService: UIService;
/**
* When `true`, then the next call to {@link abortIfCancelled} will throw.
+ *
+ * See: [Note: Upload cancellation]
*/
private shouldUploadBeCancelled = false;
- constructor() {
- this.uiService = new UIService();
- }
+ private uiService = new UIService();
public async init(
progressUpdater: ProgressUpdater,
diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts
index 4adeeececd..c1a4f1437e 100644
--- a/web/packages/gallery/services/upload/upload-service.ts
+++ b/web/packages/gallery/services/upload/upload-service.ts
@@ -539,6 +539,28 @@ const uploadItemCreationDate = async (
return parsedMetadata?.creationDate?.timestamp;
};
+/**
+ * The message of the {@link Error} that is thrown when the user cancels an
+ * upload.
+ *
+ * [Note: Upload cancellation]
+ *
+ * 1. User cancels the upload by pressing the cancel button on the upload
+ * progress indicator in the UI.
+ *
+ * 2. This sets the {@link shouldUploadBeCancelled} flag on
+ * {@link UploadManager}.
+ *
+ * 3. Periodically the code that is performing the upload calls the
+ * {@link abortIfCancelled} flag. This function is a no-op normally, but if
+ * the {@link shouldUploadBeCancelled} is set then it throws an {@link Error}
+ * with the message set to {@link uploadCancelledErrorMessage}.
+ *
+ * 4. The intermediate per-file try catch handlers do not intercept this error,
+ * and it bubbles all the way to the top of the call stack, ending the upload.
+ */
+export const uploadCancelledErrorMessage = "Upload cancelled";
+
/**
* Some state and callbacks used during upload that are not tied to a specific
* file being uploaded.
@@ -555,7 +577,9 @@ interface UploadContext {
* and see if the upload has been cancelled by the user.
*
* If the upload has been cancelled, it will throw an exception with the
- * message set to {@link CustomError.UPLOAD_CANCELLED}.
+ * message set to {@link uploadCancelledErrorMessage}.
+ *
+ * See: [Note: Upload cancellation]
*/
abortIfCancelled: () => void;
/**