π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(save.ts):if-single-zip-hide-part
Aswin Asok2e18799da46f
diff --git a/web/apps/photos/src/components/DownloadStatusNotifications.tsx b/web/apps/photos/src/components/DownloadStatusNotifications.tsxindex d3e05e2fac..abac34ab23 100644--- a/web/apps/photos/src/components/DownloadStatusNotifications.tsx+++ b/web/apps/photos/src/components/DownloadStatusNotifications.tsx@@ -111,6 +111,9 @@ export const DownloadStatusNotifications: React.FC<// Determine if this is a ZIP download (web with multiple files or live photo)const isZipDownload = !group.downloadDirPath && group.total > 1;+ const shouldShowZipPart =+ isZipDownload &&+ (group.includeZipNumber || (group.currentPart ?? 1) > 1);const isDesktopOrSingleFile =!!group.downloadDirPath || group.total === 1;@@ -127,11 +130,15 @@ export const DownloadStatusNotifications: React.FC<}} else if (isComplete) {statusText = t("download_complete");- } else if (isZipDownload) {+ } else if (shouldShowZipPart) {const part = group.currentPart ?? 1;statusText = group.isDownloadingZip? t("downloading_part", { part }): t("preparing_part", { part });+ } else if (isZipDownload) {+ statusText = group.isDownloadingZip+ ? t("downloading")+ : t("preparing");} else if (isDesktopOrSingleFile) {statusText =group.total === 1diff --git a/web/packages/gallery/components/utils/save-groups.ts b/web/packages/gallery/components/utils/save-groups.tsindex 22a776bdf5..013055f078 100644--- a/web/packages/gallery/components/utils/save-groups.ts+++ b/web/packages/gallery/components/utils/save-groups.ts@@ -82,6 +82,11 @@ export interface SaveGroup {* - undefined: No specific reason (generic error)*/failureReason?: "network_offline" | "file_error";+ /**+ * `true` when we expect the ZIP download to span multiple parts, so part+ * numbers should be shown from the first part.+ */+ includeZipNumber?: boolean;/*** `true` when the ZIP file is being downloaded from memory to the user's* device. This is only relevant for web downloads where files are first@@ -129,6 +134,7 @@ export type AddSaveGroup = (| "isHiddenCollectionSummary"| "downloadDirPath"| "total"+ | "includeZipNumber"| "canceller"| "retry">,diff --git a/web/packages/gallery/services/save.ts b/web/packages/gallery/services/save.tsindex 6554beb771..1314973d76 100644--- a/web/packages/gallery/services/save.ts+++ b/web/packages/gallery/services/save.ts@@ -57,6 +57,24 @@ const getDownloadLimits = (): DownloadLimits => {return cachedLimits;};+const shouldIncludeZipNumber = (+ files: EnteFile[],+ maxZipSize: number,+): boolean => {+ let totalSize = 0;+ for (const file of files) {+ const size = file.info?.fileSize;+ if (size == null) {+ return true;+ }+ totalSize += size;+ if (totalSize > maxZipSize) {+ return true;+ }+ }+ return false;+};+/*** Save the given {@link files} to the user's device.*@@ -150,6 +168,15 @@ const downloadAndSave = async (}}+ const shouldZipOnWeb =+ !electron &&+ (files.length > 1 ||+ (files.length === 1 &&+ files[0]?.metadata.fileType === FileType.livePhoto));+ const includeZipNumber =+ shouldZipOnWeb &&+ shouldIncludeZipNumber(files, getDownloadLimits().maxZipSize);+const canceller = new AbortController();const failedFiles: EnteFile[] = [];let isDownloading = false;@@ -268,6 +295,7 @@ const downloadAndSave = async (canceller,updateSaveGroup,nextZipBatchIndex,+ includeZipNumber,);}@@ -293,6 +321,7 @@ const downloadAndSave = async (isHiddenCollectionSummary,downloadDirPath,total,+ includeZipNumber,canceller,retry,});@@ -312,6 +341,7 @@ class ZipBatcher {private usedNames = new Set<string>();private baseName: string;private maxZipSize: number;+ private includePartNumber: boolean;private onStateChange?: (isDownloading: boolean,partNumber: number,@@ -322,11 +352,13 @@ class ZipBatcher {maxZipSize: number,startingBatchIndex = 1,onStateChange?: (isDownloading: boolean, partNumber: number) => void,+ includePartNumber = false,) {this.baseName = baseName;this.maxZipSize = maxZipSize;this.batchIndex = startingBatchIndex;this.onStateChange = onStateChange;+ this.includePartNumber = includePartNumber || startingBatchIndex > 1;}/**@@ -357,6 +389,7 @@ class ZipBatcher {this.currentBatchSize > 0 &&this.currentBatchSize + size > this.maxZipSize) {+ this.includePartNumber = true;await this.downloadCurrentBatch();// Notify that we're now preparing a new partthis.onStateChange?.(false, this.batchIndex);@@ -387,7 +420,9 @@ class ZipBatcher {this.currentFileCount === 1? "1 file": `${this.currentFileCount} files`;- const zipName = `${this.baseName} Part ${this.batchIndex} - ${fileLabel}.zip`;+ const zipName = this.includePartNumber+ ? `${this.baseName} Part ${this.batchIndex} - ${fileLabel}.zip`+ : `${this.baseName} - ${fileLabel}.zip`;const url = URL.createObjectURL(zipBlob);saveAsFileAndRevokeObjectURL(url, zipName);@@ -485,6 +520,7 @@ const saveAsZip = async (canceller: AbortController,updateSaveGroup: UpdateSaveGroup,startingBatchIndex = 1,+ includePartNumber = false,): Promise<number> => {const { concurrency, maxZipSize } = getDownloadLimits();const batcher = new ZipBatcher(@@ -497,6 +533,7 @@ const saveAsZip = async (isDownloadingZip: isDownloading,currentPart: partNumber,})),+ includePartNumber,);// Set initial part number