π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
log
Manav Rathia2debd67462f
diff --git a/desktop/src/main/stream.ts b/desktop/src/main/stream.tsindex abae9b9ec6..db7cae901a 100644--- a/desktop/src/main/stream.ts+++ b/desktop/src/main/stream.ts@@ -366,10 +366,7 @@ export const uploadVideoSegments = async (if (!t) {throw e;} else {- log.warn(- "Ignoring potentially transient failure when uploading video",- e,- );+ log.warn("Will retry potentially transient request failure", e);}await wait(t);}diff --git a/web/apps/photos/src/services/upload/remote.ts b/web/apps/photos/src/services/upload/remote.tsindex d99f9a5379..8d92d42a49 100644--- a/web/apps/photos/src/services/upload/remote.ts+++ b/web/apps/photos/src/services/upload/remote.ts@@ -10,7 +10,7 @@ import { EnteFile } from "ente-media/file";import { CustomError, handleUploadError } from "ente-shared/error";import HTTPService from "ente-shared/network/HTTPService";import { getToken } from "ente-shared/storage/localStorage/helpers";-import { retryAsyncOperation } from "ente-utils/promise";+import { retryAsyncOperation } from "ente-base/http";import { z } from "zod";import { MultipartUploadURLs, UploadFile } from "./upload-service";diff --git a/web/packages/base/http.ts b/web/packages/base/http.tsindex f9786ea904..10eca5ba96 100644--- a/web/packages/base/http.ts+++ b/web/packages/base/http.ts@@ -1,4 +1,4 @@-import { retryAsyncOperation } from "ente-utils/promise";+import { wait } from "ente-utils/promise";import { z } from "zod";import { clientPackageName } from "./app";import { ensureAuthToken } from "./local-user";@@ -164,6 +164,43 @@ export const isMuseumHTTPError = async (return false;};+/**+ * Retry a async operation like a HTTP request 3 (+ 1 original) times with+ * exponential backoff.+ *+ * @param op A function that performs the operation, returning the promise for+ * its completion.+ *+ * @param abortIfNeeded An optional function that is called with the+ * corresponding error whenever {@link op} rejects. It should throw the error if+ * the retries should immediately be aborted.+ *+ * @returns A promise that fulfills with to the result of a first successfully+ * fulfilled promise of the 4 (1 + 3) attempts, or rejects with the error+ * obtained either when {@link abortIfNeeded} throws, or with the error from the+ * last attempt otherwise.+ */+export const retryAsyncOperation = async <T>(+ op: () => Promise<T>,+ abortIfNeeded?: (error: unknown) => void,+): Promise<T> => {+ const waitTimeBeforeNextTry = [2000, 5000, 10000];++ while (true) {+ try {+ return await op();+ } catch (e) {+ if (abortIfNeeded) {+ abortIfNeeded(e);+ }+ const t = waitTimeBeforeNextTry.shift();+ if (!t) throw e;+ log.info("Will retry potentially transient request failure", e);+ await wait(t);+ }+ }+};+/*** A helper function to adapt {@link retryAsyncOperation} for HTTP fetches.*diff --git a/web/packages/utils/promise.ts b/web/packages/utils/promise.tsindex f5a39b62ee..19a0311a7e 100644--- a/web/packages/utils/promise.ts+++ b/web/packages/utils/promise.ts@@ -113,42 +113,6 @@ export const withTimeout = async <T>(return Promise.race([promiseAndCancelTimeout(), rejectOnTimeout]);};-/**- * Retry a async operation like a HTTP request 3 (+ 1 original) times with- * exponential backoff.- *- * @param op A function that performs the operation, returning the promise for- * its completion.- *- * @param abortIfNeeded An optional function that is called with the- * corresponding error whenever {@link op} rejects. It should throw the error if- * the retries should immediately be aborted.- *- * @returns A promise that fulfills with to the result of a first successfully- * fulfilled promise of the 4 (1 + 3) attempts, or rejects with the error- * obtained either when {@link abortIfNeeded} throws, or with the error from the- * last attempt otherwise.- */-export const retryAsyncOperation = async <T>(- op: () => Promise<T>,- abortIfNeeded?: (error: unknown) => void,-): Promise<T> => {- const waitTimeBeforeNextTry = [2000, 5000, 10000];-- while (true) {- try {- return await op();- } catch (e) {- if (abortIfNeeded) {- abortIfNeeded(e);- }- const t = waitTimeBeforeNextTry.shift();- if (!t) throw e;- await wait(t);- }- }-};-/*** A promise queue to serialize execution of bunch of promises.*