π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
package
Manav Rathi4e1418b11a1a
diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.tsindex 09d63f2880..17034a4eb5 100644--- a/web/apps/photos/src/services/upload-manager.ts+++ b/web/apps/photos/src/services/upload-manager.ts@@ -581,8 +581,12 @@ class UploadManager {uiService.setFileProgress(localID, 0);await wait(0);- const updateUploadProgress =- uiService.updateUploadProgress.bind(uiService);+ const uploadContext = {+ isCFUploadProxyDisabled: shouldDisableCFUploadProxy(),+ abortIfCancelled: this.abortIfCancelled.bind(this),+ updateUploadProgress:+ uiService.updateUploadProgress.bind(uiService),+ };const { uploadResult, uploadedFile } = await upload(uploadableItem,@@ -590,10 +594,6 @@ class UploadManager {this.existingFiles,this.parsedMetadataJSONMap,worker,- shouldDisableCFUploadProxy(),- () => {- this.abortIfCancelled();- },(fileLocalID: number,percentPerPart?: number,@@ -604,7 +604,7 @@ class UploadManager {percentPerPart,index,),- updateUploadProgress+ uploadContext,);const finalUploadResult = await this.postUploadTask(diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.tsindex 65679aa6aa..0a42c9104a 100644--- a/web/packages/gallery/services/upload/upload-service.ts+++ b/web/packages/gallery/services/upload/upload-service.ts@@ -543,13 +543,34 @@ type MakeProgressTracker = () => unknown;/**- * A function that is called to update the upload progress for a given file.+ * Some state and callbacks used during upload that are not tied to a specific+ * file being uploaded.*/-type UpdateUploadProgress = (- fileLocalID: number,- percentPerPart: number,- uploadedPartCount: number,-) => void;+interface UploadContext {+ /**+ * If `true`, then the upload does not go via the worker.+ *+ * See {@link shouldDisableCFUploadProxy} for more details.+ */+ isCFUploadProxyDisabled: boolean;+ /**+ * A function that the upload sequence should use to periodically check in+ * 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}.+ */+ abortIfCancelled: () => void;+ /**+ * A function that gets called update the progress shown in the UI for a+ * particular file as the parts of that file get uploaded.+ */+ updateUploadProgress: (+ fileLocalID: number,+ percentPerPart: number,+ uploadedPartCount: number,+ ) => void;+}interface UploadResponse {uploadResult: UploadResult;@@ -563,14 +584,8 @@ interface UploadResponse {* {@link UploadManager} after it has assembled all the relevant bits we need to* go forth and upload.*- * @param abortIfCancelled A function that the upload flowchart should use- * periodically to check in 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}.- *- * @param updateUploadProgress A function that gets called update the progress- * shown in the UI as the parts of the file get uploaded. See- * {@link UpdateUploadProgress}.+ * @param uploadContext Some general state and callbacks for the entire set of+ * files being uploaded.*/export const upload = async ({ collection, localID, fileName, ...uploadAsset }: UploadableUploadItem,@@ -578,11 +593,11 @@ export const upload = async (existingFiles: EnteFile[],parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,worker: CryptoWorker,- isCFUploadProxyDisabled: boolean,- abortIfCancelled: () => void,makeProgressTracker: MakeProgressTracker,- updateUploadProgress: UpdateUploadProgress,+ uploadContext: UploadContext,): Promise<UploadResponse> => {+ const { abortIfCancelled } = uploadContext;+log.info(`Upload ${fileName} | start`);try {/*@@ -686,9 +701,7 @@ export const upload = async (const backupedFile = await uploadToBucket(encryptedFilePieces,makeProgressTracker,- isCFUploadProxyDisabled,- abortIfCancelled,- updateUploadProgress,+ uploadContext,);const uploadedFile = await uploadService.uploadFile({@@ -1478,10 +1491,10 @@ const encryptFileStream = async (const uploadToBucket = async (encryptedFilePieces: EncryptedFilePieces,makeProgressTracker: MakeProgressTracker,- isCFUploadProxyDisabled: boolean,- abortIfCancelled: () => void,- updateUploadProgress: UpdateUploadProgress,+ uploadContext: UploadContext,): Promise<BackupedFile> => {+ const { isCFUploadProxyDisabled } = uploadContext;+const { localID, file, thumbnail, metadata, pubMagicMetadata } =encryptedFilePieces;try {@@ -1499,9 +1512,7 @@ const uploadToBucket = async (await uploadStreamUsingMultipart(localID,encryptedData,- isCFUploadProxyDisabled,- abortIfCancelled,- updateUploadProgress,+ uploadContext,));} else {const data =@@ -1608,10 +1619,11 @@ const createAbortableRetryEnsuringHTTPOk =const uploadStreamUsingMultipart = async (fileLocalID: number,dataStream: EncryptedFileStream,- isCFUploadProxyDisabled: boolean,- abortIfCancelled: () => void,- updateUploadProgress: UpdateUploadProgress,+ uploadContext: UploadContext,) => {+ const { isCFUploadProxyDisabled, abortIfCancelled, updateUploadProgress } =+ uploadContext;+const abortableRetryEnsuringHTTPOk =createAbortableRetryEnsuringHTTPOk(abortIfCancelled);