π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Discr union
Manav Rathi498a60d7522b
diff --git a/web/apps/photos/src/components/UploadProgress.tsx b/web/apps/photos/src/components/UploadProgress.tsxindex 4af28ab8e0..9b762c5189 100644--- a/web/apps/photos/src/components/UploadProgress.tsx+++ b/web/apps/photos/src/components/UploadProgress.tsx@@ -45,7 +45,7 @@ import {ListItemKeySelector,} from "react-window";import type {- FinishedUploadResult,+ FinishedUploadType,InProgressUpload,SegregatedFinishedUploads,UploadCounter,@@ -321,11 +321,11 @@ function UploadProgressDialog() {<DialogContent sx={{ "&&&": { px: 0 } }}>{uploadPhase == "uploading" && <InProgressSection />}<ResultSection- uploadResult="uploaded"+ resultType="uploaded"sectionTitle={t("successful_uploads")}/><ResultSection- uploadResult="uploadedWithStaticThumbnail"+ resultType="uploadedWithStaticThumbnail"sectionTitle={t("thumbnail_generation_failed")}sectionInfo={t("thumbnail_generation_failed_hint")}/>@@ -335,12 +335,12 @@ function UploadProgressDialog() {</NotUploadSectionHeader>)}<ResultSection- uploadResult="blocked"+ resultType="blocked"sectionTitle={t("blocked_uploads")}sectionInfo={<Trans i18nKey={"blocked_uploads_hint"} />}/><ResultSection- uploadResult="failed"+ resultType="failed"sectionTitle={t("failed_uploads")}sectionInfo={uploadPhase == "done"@@ -349,22 +349,22 @@ function UploadProgressDialog() {}/><ResultSection- uploadResult="alreadyUploaded"+ resultType="alreadyUploaded"sectionTitle={t("ignored_uploads")}sectionInfo={t("ignored_uploads_hint")}/><ResultSection- uploadResult="largerThanAvailableStorage"+ resultType="largerThanAvailableStorage"sectionTitle={t("insufficient_storage")}sectionInfo={t("insufficient_storage_hint")}/><ResultSection- uploadResult="unsupported"+ resultType="unsupported"sectionTitle={t("unsupported_files")}sectionInfo={t("unsupported_files_hint")}/><ResultSection- uploadResult="tooLarge"+ resultType="tooLarge"sectionTitle={t("large_files")}sectionInfo={t("large_files_hint")}/>@@ -482,20 +482,20 @@ const NotUploadSectionHeader = styled("div")();interface ResultSectionProps {- uploadResult: FinishedUploadResult;+ resultType: FinishedUploadType;sectionTitle: string;sectionInfo?: React.ReactNode;}const ResultSection: React.FC<ResultSectionProps> = ({- uploadResult,+ resultType,sectionTitle,sectionInfo,}) => {const { finishedUploads, uploadFileNames } = useContext(UploadProgressContext,);- const fileList = finishedUploads.get(uploadResult);+ const fileList = finishedUploads.get(resultType);if (!fileList?.length) {return <></>;diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.tsindex 61f4e23a31..3ce335d739 100644--- a/web/apps/photos/src/services/upload-manager.ts+++ b/web/apps/photos/src/services/upload-manager.ts@@ -29,11 +29,7 @@ import UploadService, {} from "ente-gallery/services/upload/upload-service";import { processVideoNewUpload } from "ente-gallery/services/video";import type { Collection } from "ente-media/collection";-import {- decryptRemoteFile,- type EnteFile,- type RemoteEnteFile,-} from "ente-media/file";+import { decryptRemoteFile, type EnteFile } from "ente-media/file";import {fileCreationTime,type ParsedMetadata,@@ -67,22 +63,17 @@ export interface InProgressUpload {}/**- * A variant of {@link UploadResult} used when segregating finished uploads in- * the UI. "addedSymlink" is treated as "uploaded", everything else remains as- * it were.+ * A variant of {@link UploadResult}'s {@link type} values used when segregating+ * finished uploads in the UI. "addedSymlink" is treated as "uploaded",+ * everything else remains as it were.*/-export type FinishedUploadResult = Exclude<UploadResult, "addedSymlink">;--export interface FinishedUpload {- localFileID: FileID;- result: FinishedUploadResult;-}+export type FinishedUploadType = Exclude<UploadResult["type"], "addedSymlink">;export type InProgressUploads = Map<FileID, PercentageUploaded>;-export type FinishedUploads = Map<FileID, FinishedUploadResult>;+export type FinishedUploads = Map<FileID, FinishedUploadType>;-export type SegregatedFinishedUploads = Map<FinishedUploadResult, FileID[]>;+export type SegregatedFinishedUploads = Map<FinishedUploadType, FileID[]>;export interface ProgressUpdater {setPercentComplete: React.Dispatch<React.SetStateAction<number>>;@@ -145,7 +136,7 @@ class UIService {this.setTotalFileCount(count);this.filesUploadedCount = 0;this.inProgressUploads = new Map<number, number>();- this.finishedUploads = new Map<number, FinishedUploadResult>();+ this.finishedUploads = new Map<number, FinishedUploadType>();this.updateProgressBarUI();}@@ -189,8 +180,8 @@ class UIService {this.updateProgressBarUI();}- moveFileToResultList(key: number, uploadResult: FinishedUploadResult) {- this.finishedUploads.set(key, uploadResult);+ moveFileToResultList(key: number, type: FinishedUploadType) {+ this.finishedUploads.set(key, type);this.inProgressUploads.delete(key);this.updateProgressBarUI();}@@ -523,7 +514,7 @@ class UploadManager {uiService.setFileProgress(localID, 0);await wait(0);- const { uploadResult, uploadedFile } = await upload(+ const uploadResult = await upload(uploadableItem,this.uploaderName,this.existingFiles,@@ -532,13 +523,12 @@ class UploadManager {uploadContext,);- const finalUploadResult = await this.postUploadTask(+ const finishedUploadType = await this.postUploadTask(uploadableItem,uploadResult,- uploadedFile,);- uiService.moveFileToResultList(localID, finalUploadResult);+ uiService.moveFileToResultList(localID, finishedUploadType);uiService.increaseFileUploaded();UploadService.reducePendingUploadCount();}@@ -547,29 +537,29 @@ class UploadManager {private async postUploadTask(uploadableItem: UploadableUploadItem,uploadResult: UploadResult,- uploadedFile: RemoteEnteFile | EnteFile | undefined,- ): Promise<FinishedUploadResult> {- log.info(`Upload ${uploadableItem.fileName} | ${uploadResult}`);- const finishedUploadResult =- uploadResult == "addedSymlink" ? "uploaded" : uploadResult;+ ): Promise<FinishedUploadType> {+ const type = uploadResult.type;+ log.info(`Upload ${uploadableItem.fileName} | ${type}`);+try {const processableUploadItem =await markUploadedAndObtainProcessableItem(uploadableItem);let decryptedFile: EnteFile;- switch (uploadResult) {+ switch (uploadResult.type) {case "failed":case "blocked":+ // Retriable.this.failedItems.push(uploadableItem);break;case "alreadyUploaded":case "addedSymlink":- decryptedFile = uploadedFile as EnteFile;+ decryptedFile = uploadResult.file;break;case "uploaded":case "uploadedWithStaticThumbnail":decryptedFile = await decryptRemoteFile(- uploadedFile as RemoteEnteFile,+ uploadResult.file,uploadableItem.collection.key,);break;@@ -578,23 +568,21 @@ class UploadManager {case "tooLarge":// no-opbreak;- default:- throw new Error(`Invalid Upload Result ${uploadResult}`);}if (["addedSymlink","uploaded","uploadedWithStaticThumbnail",- ].includes(uploadResult)+ ].includes(type)) {const uploadItem =uploadableItem.uploadItem ??uploadableItem.livePhotoAssets.image;if (uploadItem &&- (uploadResult == "uploaded" ||- uploadResult == "uploadedWithStaticThumbnail")+ (type == "uploaded" ||+ type == "uploadedWithStaticThumbnail")) {indexNewUpload(decryptedFile, processableUploadItem);processVideoNewUpload(decryptedFile, processableUploadItem);@@ -602,17 +590,11 @@ class UploadManager {this.updateExistingFiles(decryptedFile);}- if (isDesktop) {- if (watcher.isUploadRunning()) {- await watcher.onFileUpload(- uploadResult,- uploadableItem,- uploadedFile,- );- }+ if (isDesktop && watcher.isUploadRunning()) {+ await watcher.onFileUpload(uploadableItem, uploadResult);}- return finishedUploadResult;+ return type == "addedSymlink" ? "uploaded" : type;} catch (e) {log.error("Post file upload action failed", e);return "failed";diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.tsindex cde7a69fad..6997596239 100644--- a/web/apps/photos/src/services/watch.ts+++ b/web/apps/photos/src/services/watch.ts@@ -326,47 +326,54 @@ class FolderWatcher {* {@link upload} gets uploaded.*/async onFileUpload(- fileUploadResult: UploadResult,item: UploadItemWithCollection,- file: FolderWatchUploadedFile,+ uploadResult: UploadResult,) {// Re the usage of ensureString: For desktop watch, the only possibility// for a UploadItem is for it to be a string (the absolute path to a// file on disk).- if (- [- "addedSymlink",- "uploaded",- "uploadedWithStaticThumbnail",- "alreadyUploaded",- ].includes(fileUploadResult)- ) {- if (item.isLivePhoto) {- this.uploadedFileForPath.set(- ensureString(item.livePhotoAssets.image),- file,- );- this.uploadedFileForPath.set(- ensureString(item.livePhotoAssets.video),- file,- );- } else {- this.uploadedFileForPath.set(- ensureString(item.uploadItem),- file,- );- }- } else if (["unsupported", "tooLarge"].includes(fileUploadResult)) {- if (item.isLivePhoto) {- this.unUploadableFilePaths.add(- ensureString(item.livePhotoAssets.image),- );- this.unUploadableFilePaths.add(- ensureString(item.livePhotoAssets.video),- );- } else {- this.unUploadableFilePaths.add(ensureString(item.uploadItem));- }+ switch (uploadResult.type) {+ case "alreadyUploaded":+ case "addedSymlink":+ case "uploaded":+ case "uploadedWithStaticThumbnail":+ {+ // Done.+ if (item.isLivePhoto) {+ this.uploadedFileForPath.set(+ ensureString(item.livePhotoAssets.image),+ uploadResult.file,+ );+ this.uploadedFileForPath.set(+ ensureString(item.livePhotoAssets.video),+ uploadResult.file,+ );+ } else {+ this.uploadedFileForPath.set(+ ensureString(item.uploadItem),+ uploadResult.file,+ );+ }+ }+ break;+ case "unsupported":+ case "tooLarge":+ {+ // Non-retriable error.+ if (item.isLivePhoto) {+ this.unUploadableFilePaths.add(+ ensureString(item.livePhotoAssets.image),+ );+ this.unUploadableFilePaths.add(+ ensureString(item.livePhotoAssets.video),+ );+ } else {+ this.unUploadableFilePaths.add(+ ensureString(item.uploadItem),+ );+ }+ }+ break;}}diff --git a/web/packages/gallery/services/upload/index.ts b/web/packages/gallery/services/upload/index.tsindex 7af420aff0..b100323ccf 100644--- a/web/packages/gallery/services/upload/index.ts+++ b/web/packages/gallery/services/upload/index.ts@@ -4,6 +4,7 @@ import { customAPIOrigin } from "ente-base/origins";import type { ZipItem } from "ente-base/types/ipc";import { exportMetadataDirectoryName } from "ente-gallery/export-dirs";import type { Collection } from "ente-media/collection";+import type { EnteFile, RemoteEnteFile } from "ente-media/file";import { nullToUndefined } from "ente-utils/transform";import { z } from "zod/v4";@@ -432,15 +433,15 @@ export type UploadPhase =| "done";export type UploadResult =- | "failed"- | "alreadyUploaded"- | "unsupported"- | "blocked"- | "tooLarge"- | "largerThanAvailableStorage"- | "uploaded"- | "uploadedWithStaticThumbnail"- | "addedSymlink";+ | { type: "unsupported" }+ | { type: "tooLarge" }+ | { type: "largerThanAvailableStorage" }+ | { type: "blocked" }+ | { type: "failed" }+ | { type: "alreadyUploaded"; file: EnteFile }+ | { type: "addedSymlink"; file: EnteFile }+ | { type: "uploadedWithStaticThumbnail"; file: RemoteEnteFile }+ | { type: "uploaded"; file: RemoteEnteFile };/*** Return true to disable the upload of files via Cloudflare Workers.diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.tsindex 04ba1a22b4..d462eaf07a 100644--- a/web/packages/gallery/services/upload/upload-service.ts+++ b/web/packages/gallery/services/upload/upload-service.ts@@ -24,7 +24,7 @@ import {isFileTypeNotSupportedError,} from "ente-gallery/utils/detect-type";import { readStream } from "ente-gallery/utils/native-stream";-import type { EnteFile, RemoteEnteFile } from "ente-media/file";+import type { EnteFile } from "ente-media/file";import {fileFileName,metadataHash,@@ -42,8 +42,13 @@ import {import { addToCollection } from "ente-new/photos/services/collection";import { mergeUint8Arrays } from "ente-utils/array";import { ensureInteger, ensureNumber } from "ente-utils/ensure";-import type { UploadableUploadItem, UploadItem, UploadPathPrefix } from ".";-import { type LivePhotoAssets, type UploadResult } from ".";+import type {+ UploadableUploadItem,+ UploadItem,+ UploadPathPrefix,+ UploadResult,+} from ".";+import { type LivePhotoAssets } from ".";import { tryParseEpochMicrosecondsFromFileName } from "./date";import { matchJSONMetadata, type ParsedMetadataJSON } from "./metadata-json";import {@@ -635,11 +640,6 @@ interface UploadContext {updateUploadProgress: (fileLocalID: number, percentage: number) => void;}-interface UploadResponse {- uploadResult: UploadResult;- uploadedFile?: RemoteEnteFile | EnteFile;-}-/*** Upload the given {@link UploadableUploadItem}*@@ -657,7 +657,7 @@ export const upload = async (parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,worker: CryptoWorker,uploadContext: UploadContext,-): Promise<UploadResponse> => {+): Promise<UploadResult> => {const { abortIfCancelled } = uploadContext;log.info(`Upload ${fileName} | start`);@@ -685,7 +685,7 @@ export const upload = async (} catch (e) {if (isFileTypeNotSupportedError(e)) {log.error(`Not uploading ${fileName}`, e);- return { uploadResult: "unsupported" };+ return { type: "unsupported" };}throw e;}@@ -693,7 +693,7 @@ export const upload = async (const { fileTypeInfo, fileSize, lastModifiedMs } = assetDetails;const maxFileSize = 10 * 1024 * 1024 * 1024; /* 10 GB */- if (fileSize >= maxFileSize) return { uploadResult: "tooLarge" };+ if (fileSize >= maxFileSize) return { type: "tooLarge" };abortIfCancelled();@@ -717,16 +717,13 @@ export const upload = async ((f) => f.collectionID == collection.id,);if (matchInSameCollection) {- return {- uploadResult: "alreadyUploaded",- uploadedFile: matchInSameCollection,- };+ 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 { uploadResult: "addedSymlink", uploadedFile: symlink };+ return { type: "addedSymlink", file: symlink };}}@@ -778,10 +775,10 @@ export const upload = async ();return {- uploadResult: metadata.hasStaticThumbnail+ type: metadata.hasStaticThumbnail? "uploadedWithStaticThumbnail": "uploaded",- uploadedFile,+ file: uploadedFile,};} catch (e) {if (isUploadCancelledError(e)) {@@ -799,11 +796,11 @@ export const upload = async (/* file specific */case eTagMissingErrorMessage:- return { uploadResult: "blocked" };+ return { type: "blocked" };case fileTooLargeErrorMessage:- return { uploadResult: "largerThanAvailableStorage" };+ return { type: "largerThanAvailableStorage" };default:- return { uploadResult: "failed" };+ return { type: "failed" };}}};