π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(shared-album):fixed-edge-case-of-adding-symlink-to-uncategorized-for-already-existing-files
Aswin Asok9008d59658f5
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex a27b7b79ec..9d3c48267d 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -155,6 +155,11 @@ interface UploadProps {type UploadType = "files" | "folders" | "zips";+interface UploadFilesOptions {+ persistPendingUploads?: boolean;+ postUploadTargetCollection?: Collection;+}+/*** Top level component that houses the infrastructure for handling uploads.*/@@ -762,10 +767,7 @@ export const Upload: React.FC<UploadProps> = ({const waitInQueueAndUploadFiles = async (uploadItemsWithCollection: UploadItemWithCollection[],collections: Collection[],- opts?: {- persistPendingUploads?: boolean;- postUploadTargetCollection?: Collection;- },+ opts?: UploadFilesOptions,) => {const currentPromise = currentUploadPromise.current;currentUploadPromise.current = (async () => {@@ -791,10 +793,7 @@ export const Upload: React.FC<UploadProps> = ({const uploadFiles = async (uploadItemsWithCollection: UploadItemWithCollection[],collections: Collection[],- opts?: {- persistPendingUploads?: boolean;- postUploadTargetCollection?: Collection;- },+ opts?: UploadFilesOptions,) => {try {retrySharedAlbumUploadTarget.current =@@ -817,6 +816,10 @@ export const Upload: React.FC<UploadProps> = ({const batchResult = await uploadManager.uploadItems(uploadItemsWithCollection,collections,+ {+ skipDuplicateAddToUploadCollection:+ !!opts?.postUploadTargetCollection,+ },);if (!batchResult.processedAny) closeUploadProgress();await handlePostUploadBatchResult(@@ -850,6 +853,10 @@ export const Upload: React.FC<UploadProps> = ({const batchResult = await uploadManager.uploadItems(items,collections,+ {+ skipDuplicateAddToUploadCollection:+ !!retrySharedAlbumUploadTarget.current,+ },);if (!batchResult.processedAny) closeUploadProgress();await handlePostUploadBatchResult(diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.tsindex df7d1a23b3..5e280d5f53 100644--- a/web/apps/photos/src/services/upload-manager.ts+++ b/web/apps/photos/src/services/upload-manager.ts@@ -90,6 +90,10 @@ export interface UploadBatchResult {itemResults: UploadBatchItemResult[];}+interface UploadItemsOptions {+ skipDuplicateAddToUploadCollection?: boolean;+}+/**** @param batchResult@@ -374,6 +378,7 @@ class UploadManager {public async uploadItems(itemsWithCollection: UploadItemWithCollection[],collections: Collection[],+ options?: UploadItemsOptions,): Promise<UploadBatchResult> {if (this.uploadInProgress)throw new Error("Cannot run multiple uploads at once");@@ -416,7 +421,7 @@ class UploadManager {mediaItems.length != clusteredMediaItems.length,);- await this.uploadMediaItems(clusteredMediaItems);+ await this.uploadMediaItems(clusteredMediaItems, options);}} catch (e) {if (!isUploadCancelledError(e)) {@@ -526,7 +531,10 @@ class UploadManager {}}- private async uploadMediaItems(mediaItems: ClusteredUploadItem[]) {+ private async uploadMediaItems(+ mediaItems: ClusteredUploadItem[],+ options?: UploadItemsOptions,+ ) {this.itemsToBeUploaded = [...this.itemsToBeUploaded, ...mediaItems];this.uiService.reset(mediaItems.length);await UploadService.setFileCount(mediaItems.length);@@ -540,15 +548,20 @@ class UploadManager {) {this.comlinkCryptoWorkers[i] = createComlinkCryptoWorker();const worker = await this.comlinkCryptoWorkers[i]!.remote;- uploadProcesses.push(this.uploadNextItemInQueue(worker));+ uploadProcesses.push(this.uploadNextItemInQueue(worker, options));}await Promise.all(uploadProcesses);}- private async uploadNextItemInQueue(worker: CryptoWorker) {+ private async uploadNextItemInQueue(+ worker: CryptoWorker,+ options?: UploadItemsOptions,+ ) {const uiService = this.uiService;const uploadContext = {isCFUploadProxyDisabled: shouldDisableCFUploadProxy(),+ skipDuplicateAddToUploadCollection:+ options?.skipDuplicateAddToUploadCollection,abortIfCancelled: this.abortIfCancelled.bind(this),updateUploadProgress:uiService.updateUploadProgress.bind(uiService),diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.tsindex 4439f1f97e..5983b20e12 100644--- a/web/packages/gallery/services/upload/upload-service.ts+++ b/web/packages/gallery/services/upload/upload-service.ts@@ -675,6 +675,12 @@ interface UploadContext {* See {@link shouldDisableCFUploadProxy} for more details.*/isCFUploadProxyDisabled: boolean;+ /**+ * If true, duplicate files already owned by the user are reused without+ * being added to the current upload collection.+ * This is used when the current collection is only an upload staging target.+ */+ skipDuplicateAddToUploadCollection?: boolean;/*** If present, then the upload is happening in the context of the public* albums app and these are the credentials that should be used for@@ -724,7 +730,8 @@ export const upload = async (worker: CryptoWorker,uploadContext: UploadContext,): Promise<UploadResult> => {- const { abortIfCancelled } = uploadContext;+ const { abortIfCancelled, skipDuplicateAddToUploadCollection } =+ uploadContext;log.info(`Upload ${fileName} | start`);try {@@ -784,15 +791,25 @@ export const upload = async (const matchInSameCollection = matches.find((f) => f.collectionID == collection.id,);- if (matchInSameCollection) {+ if (matchInSameCollection && !skipDuplicateAddToUploadCollection) {return { type: "alreadyUploaded", file: matchInSameCollection };- } else {- // Any of the matching files can be used to add a symlink.- const symlink = Object.assign({}, anyMatch);- symlink.collectionID = collection.id;- await addToCollection(collection, [symlink]);- return { type: "addedSymlink", file: symlink };}++ if (skipDuplicateAddToUploadCollection) {+ // The real target collection is updated after the upload batch.+ // Report duplicate reuse as a success without creating a staging+ // collection symlink.+ return {+ type: "addedSymlink",+ file: matchInSameCollection ?? anyMatch,+ };+ }++ // Any of the matching files can be used to add a symlink.+ const symlink = Object.assign({}, anyMatch);+ symlink.collectionID = collection.id;+ await addToCollection(collection, [symlink]);+ return { type: "addedSymlink", file: symlink };}abortIfCancelled();