π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathiaa3c212b2602
diff --git a/web/apps/photos/src/services/upload/publicUploadHttpClient.ts b/web/apps/photos/src/services/upload/publicUploadHttpClient.tsindex 3019025627..dafd3faea9 100644--- a/web/apps/photos/src/services/upload/publicUploadHttpClient.ts+++ b/web/apps/photos/src/services/upload/publicUploadHttpClient.ts@@ -1,10 +1,10 @@import log from "@/base/log";import { apiURL } from "@/base/origins";+import { retryHTTPCall } from "@/gallery/retry-async";import { EnteFile } from "@/media/file";import { CustomError, handleUploadError } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";import { MultipartUploadURLs, UploadFile, UploadURL } from "./upload-service";-import { retryHTTPCall } from "./uploadHttpClient";const MAX_URL_REQUESTS = 50;diff --git a/web/apps/photos/src/services/upload/uploadHttpClient.ts b/web/apps/photos/src/services/upload/uploadHttpClient.tsindex 98b5a7cc0f..01be5cc922 100644--- a/web/apps/photos/src/services/upload/uploadHttpClient.ts+++ b/web/apps/photos/src/services/upload/uploadHttpClient.ts@@ -1,7 +1,7 @@import log from "@/base/log";import { apiURL, uploaderOrigin } from "@/base/origins";+import { retryHTTPCall } from "@/gallery/retry-async";import { EnteFile } from "@/media/file";-import { wait } from "@/utils/promise";import { CustomError, handleUploadError } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";import { getToken } from "@ente/shared/storage/localStorage/helpers";@@ -235,31 +235,3 @@ class UploadHttpClient {}export default new UploadHttpClient();--const retrySleepTimeInMilliSeconds = [2000, 5000, 10000];--export async function retryHTTPCall(- func: () => Promise<any>,- checkForBreakingError?: (error) => void,-): Promise<any> {- const retrier = async (- func: () => Promise<any>,- attemptNumber: number = 0,- ) => {- try {- const resp = await func();- return resp;- } catch (e) {- if (checkForBreakingError) {- checkForBreakingError(e);- }- if (attemptNumber < retrySleepTimeInMilliSeconds.length) {- await wait(retrySleepTimeInMilliSeconds[attemptNumber]);- return await retrier(func, attemptNumber + 1);- } else {- throw e;- }- }- };- return await retrier(func);-}diff --git a/web/packages/gallery/retry-async.ts b/web/packages/gallery/retry-async.tsnew file mode 100644index 0000000000..cbea2002cb--- /dev/null+++ b/web/packages/gallery/retry-async.ts@@ -0,0 +1,48 @@+/* eslint-disable @typescript-eslint/no-unsafe-return */+/* eslint-disable @typescript-eslint/no-unsafe-assignment */+/* eslint-disable @typescript-eslint/no-inferrable-types */+/* eslint-disable @typescript-eslint/no-explicit-any */+import { wait } from "@/utils/promise";++const retrySleepTimeInMilliSeconds = [2000, 5000, 10000];++/**+ * Retry a HTTP request 3 (+ 1 original) times with exponential backoff.+ *+ * @param func A function that perform the operation, returning the promise for+ * its completion.+ *+ * @param checkForBreakingError A function that is passed the error with which+ * {@link func} rejects. It should throw the error if the retries should+ * immediately be aborted.+ *+ * @returns A promise that fulfills with to the result of a successfully+ * fulfilled promise of the 4 (1 + 3) attempts, or rejects with the error of+ * either when {@link checkForBreakingError} throws, or with the error from the+ * last attempt otherwise.+ */+export async function retryHTTPCall(+ func: () => Promise<any>,+ checkForBreakingError?: (error: unknown) => void,+): Promise<any> {+ const retrier = async (+ func: () => Promise<any>,+ attemptNumber: number = 0,+ ) => {+ try {+ const resp = await func();+ return resp;+ } catch (e) {+ if (checkForBreakingError) {+ checkForBreakingError(e);+ }+ if (attemptNumber < retrySleepTimeInMilliSeconds.length) {+ await wait(retrySleepTimeInMilliSeconds[attemptNumber]!);+ return await retrier(func, attemptNumber + 1);+ } else {+ throw e;+ }+ }+ };+ return await retrier(func);+}