π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathif8c2f4b9dd5b
diff --git a/web/apps/photos/src/components/Upload/UploadProgress.tsx b/web/apps/photos/src/components/Upload/UploadProgress.tsxindex 592ec8fce5..451d19ba54 100644--- a/web/apps/photos/src/components/Upload/UploadProgress.tsx+++ b/web/apps/photos/src/components/Upload/UploadProgress.tsx@@ -1,9 +1,6 @@import { FilledIconButton } from "@/base/components/mui";import { useBaseContext } from "@/base/context";-import {- UPLOAD_RESULT,- type UploadPhase,-} from "@/new/photos/services/upload/types";+import { UPLOAD_RESULT, type UploadPhase } from "@/gallery/services/upload";import { SpaceBetweenFlex } from "@ente/shared/components/Container";import CloseIcon from "@mui/icons-material/Close";import ExpandMoreIcon from "@mui/icons-material/ExpandMore";diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsxindex fc967da7a3..9c8f1f0005 100644--- a/web/apps/photos/src/components/Upload/Uploader.tsx+++ b/web/apps/photos/src/components/Upload/Uploader.tsx@@ -4,6 +4,11 @@ import { useBaseContext } from "@/base/context";import { basename } from "@/base/file-name";import log from "@/base/log";import type { CollectionMapping, Electron, ZipItem } from "@/base/types/ipc";+import type {+ FileAndPath,+ UploadItem,+ UploadPhase,+} from "@/gallery/services/upload";import type { Collection } from "@/media/collection";import type { EnteFile } from "@/media/file";import { UploaderNameInput } from "@/new/albums/components/UploaderNameInput";@@ -12,11 +17,6 @@ import type { CollectionSelectorAttributes } from "@/new/photos/components/Colleimport { downloadAppDialogAttributes } from "@/new/photos/components/utils/download";import { getLatestCollections } from "@/new/photos/services/collections";import { exportMetadataDirectoryName } from "@/new/photos/services/export";-import type {- FileAndPath,- UploadItem,- UploadPhase,-} from "@/new/photos/services/upload/types";import { redirectToCustomerPortal } from "@/new/photos/services/user-details";import { usePhotosAppContext } from "@/new/photos/types/context";import { firstNonEmpty } from "@/utils/array";diff --git a/web/apps/photos/src/services/upload/takeout.ts b/web/apps/photos/src/services/upload/takeout.tsindex 78527f9325..4d8c740832 100644--- a/web/apps/photos/src/services/upload/takeout.ts+++ b/web/apps/photos/src/services/upload/takeout.ts@@ -5,8 +5,8 @@ import { ensureElectron } from "@/base/electron";import { nameAndExtension } from "@/base/file-name";import log from "@/base/log";import { type Location } from "@/base/types";+import type { UploadItem } from "@/gallery/services/upload";import { readStream } from "@/gallery/utils/native-stream";-import type { UploadItem } from "@/new/photos/services/upload/types";import { maybeParseInt } from "@/utils/parse";/**diff --git a/web/apps/photos/src/services/upload/thumbnail.ts b/web/apps/photos/src/services/upload/thumbnail.tsindex fd7c81e852..943d724b38 100644--- a/web/apps/photos/src/services/upload/thumbnail.ts+++ b/web/apps/photos/src/services/upload/thumbnail.ts@@ -1,14 +1,14 @@import log from "@/base/log";import { type Electron } from "@/base/types/ipc";import * as ffmpeg from "@/gallery/services/ffmpeg";+import {+ toDataOrPathOrZipEntry,+ type DesktopUploadItem,+} from "@/gallery/services/upload";import { FileType, type FileTypeInfo } from "@/media/file-type";import { isHEICExtension } from "@/media/formats";import { heicToJPEG } from "@/media/heic-convert";import { scaledImageDimensions } from "@/media/image";-import {- toDataOrPathOrZipEntry,- type DesktopUploadItem,-} from "@/new/photos/services/upload/types";import { withTimeout } from "@/utils/promise";/** Maximum width or height of the generated thumbnail */diff --git a/web/apps/photos/src/services/upload/upload-service.ts b/web/apps/photos/src/services/upload/upload-service.tsindex 0ac2d066c5..c26f14b23b 100644--- a/web/apps/photos/src/services/upload/upload-service.ts+++ b/web/apps/photos/src/services/upload/upload-service.ts@@ -10,6 +10,11 @@ import {getNonEmptyMagicMetadataProps,updateMagicMetadata,} from "@/gallery/services/magic-metadata";+import type { UploadItem } from "@/gallery/services/upload";+import {+ RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,+ UPLOAD_RESULT,+} from "@/gallery/services/upload";import {detectFileTypeInfoFromChunk,isFileTypeNotSupportedError,@@ -34,11 +39,6 @@ import { FileType, type FileTypeInfo } from "@/media/file-type";import { encodeLivePhoto } from "@/media/live-photo";import { addToCollection } from "@/new/photos/services/collection";import { extractExif } from "@/new/photos/services/exif";-import type { UploadItem } from "@/new/photos/services/upload/types";-import {- RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,- UPLOAD_RESULT,-} from "@/new/photos/services/upload/types";import { mergeUint8Arrays } from "@/utils/array";import { ensureInteger, ensureNumber } from "@/utils/ensure";import { CustomError, handleUploadError } from "@ente/shared/error";diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.tsindex 6e006797ac..46e72fa316 100644--- a/web/apps/photos/src/services/upload/uploadManager.ts+++ b/web/apps/photos/src/services/upload/uploadManager.ts@@ -6,7 +6,13 @@ import type { PublicAlbumsCredentials } from "@/base/http";import log from "@/base/log";import type { Electron } from "@/base/types/ipc";import { ComlinkWorker } from "@/base/worker/comlink-worker";-import { shouldDisableCFUploadProxy } from "@/gallery/services/upload";+import type { UploadItem } from "@/gallery/services/upload";+import {+ RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,+ UPLOAD_RESULT,+ shouldDisableCFUploadProxy,+ type UploadPhase,+} from "@/gallery/services/upload";import type { Collection } from "@/media/collection";import {decryptFile,@@ -18,12 +24,6 @@ import { FileType } from "@/media/file-type";import { potentialFileTypeFromExtension } from "@/media/live-photo";import { getLocalFiles } from "@/new/photos/services/files";import { indexNewUpload } from "@/new/photos/services/ml";-import type { UploadItem } from "@/new/photos/services/upload/types";-import {- RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,- UPLOAD_RESULT,- type UploadPhase,-} from "@/new/photos/services/upload/types";import { wait } from "@/utils/promise";import { CustomError } from "@ente/shared/error";import { Canceler } from "axios";diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.tsindex af090d347f..8266a5e0f3 100644--- a/web/apps/photos/src/services/watch.ts+++ b/web/apps/photos/src/services/watch.ts@@ -11,13 +11,13 @@ import type {FolderWatch,FolderWatchSyncedFile,} from "@/base/types/ipc";+import { UPLOAD_RESULT } from "@/gallery/services/upload";import type { Collection } from "@/media/collection";import { EncryptedEnteFile } from "@/media/file";import {getLocalFiles,groupFilesByCollectionID,} from "@/new/photos/services/files";-import { UPLOAD_RESULT } from "@/new/photos/services/upload/types";import { ensureString } from "@/utils/ensure";import debounce from "debounce";import uploadManager, {diff --git a/web/packages/gallery/services/ffmpeg/index.ts b/web/packages/gallery/services/ffmpeg/index.tsindex 2141dfec23..18303461c3 100644--- a/web/packages/gallery/services/ffmpeg/index.ts+++ b/web/packages/gallery/services/ffmpeg/index.ts@@ -1,17 +1,17 @@import { ensureElectron } from "@/base/electron";import log from "@/base/log";import type { Electron } from "@/base/types/ipc";+import {+ toDataOrPathOrZipEntry,+ type DesktopUploadItem,+ type UploadItem,+} from "@/gallery/services/upload";import {readConvertToMP4Done,readConvertToMP4Stream,writeConvertToMP4Stream,} from "@/gallery/utils/native-stream";import { parseMetadataDate, type ParsedMetadata } from "@/media/file-metadata";-import {- toDataOrPathOrZipEntry,- type DesktopUploadItem,- type UploadItem,-} from "@/new/photos/services/upload/types";import {ffmpegPathPlaceholder,inputPathPlaceholder,diff --git a/web/packages/gallery/services/upload.ts b/web/packages/gallery/services/upload.tsindex 868b9caf3d..e6b1040d73 100644--- a/web/packages/gallery/services/upload.ts+++ b/web/packages/gallery/services/upload.ts@@ -1,5 +1,6 @@import log from "@/base/log";import { customAPIOrigin } from "@/base/origins";+import type { ZipItem } from "@/base/types/ipc";import { nullToUndefined } from "@/utils/transform";import { z } from "zod";@@ -28,6 +29,83 @@ export const resetUploadState = () => {_state = new UploadState();};+/**+ * An item to upload is one of the following:+ *+ * 1. A file drag-and-dropped or selected by the user when we are running in the+ * web browser. These is the {@link File} case.+ *+ * 2. A file drag-and-dropped or selected by the user when we are running in the+ * context of our desktop app. In such cases, we also have the absolute path+ * of the file in the user's local file system. This is the+ * {@link FileAndPath} case.+ *+ * 3. A file path programmatically requested by the desktop app. For example, we+ * might be resuming a previously interrupted upload after an app restart+ * (thus we no longer have access to the {@link File} from case 2). Or we+ * could be uploading a file this is in one of the folders the user has asked+ * us to watch for changes. This is the `string` case.+ *+ * 4. A file within a zip file on the user's local file system. This too is only+ * possible when we are running in the context of our desktop app. The user+ * might have drag-and-dropped or selected a zip file, or it might be a zip+ * file that they'd previously selected but we now are resuming an+ * interrupted upload of. Either ways, what we have is a tuple containing the+ * (path to zip file, and the name of an entry within that zip file). This is+ * the {@link ZipItem} case.+ *+ * Also see: [Note: Reading a UploadItem].+ */+export type UploadItem = File | FileAndPath | string | ZipItem;++/**+ * When we are running in the context of our desktop app, we have access to the+ * absolute path of {@link File} objects. This convenience type clubs these two+ * bits of information, saving us the need to query the path again and again+ * using the {@link getPathForFile} method of {@link Electron}.+ */+export interface FileAndPath {+ file: File;+ path: string;+}++/**+ * The of cases of {@link UploadItem} that apply when we're running in the+ * context of our desktop app.+ */+export type DesktopUploadItem = Exclude<UploadItem, File>;++/**+ * For each of cases of {@link UploadItem} that apply when we're running in the+ * context of our desktop app, return a value that can be passed to+ * {@link Electron} functions over IPC.+ */+export const toDataOrPathOrZipEntry = (desktopUploadItem: DesktopUploadItem) =>+ typeof desktopUploadItem == "string" || Array.isArray(desktopUploadItem)+ ? desktopUploadItem+ : desktopUploadItem.path;++export const RANDOM_PERCENTAGE_PROGRESS_FOR_PUT = () => 90 + 10 * Math.random();++export type UploadPhase =+ | "preparing"+ | "readingMetadata"+ | "uploading"+ | "cancelling"+ | "done";++export enum UPLOAD_RESULT {+ FAILED,+ ALREADY_UPLOADED,+ UNSUPPORTED,+ BLOCKED,+ TOO_LARGE,+ LARGER_THAN_AVAILABLE_STORAGE,+ UPLOADED,+ UPLOADED_WITH_STATIC_THUMBNAIL,+ ADDED_SYMLINK,+}+/*** Return true to disable the upload of files via Cloudflare Workers.*diff --git a/web/packages/new/photos/services/upload/types.ts b/web/packages/new/photos/services/upload/types.tsindex 8055bd9dfd..e69de29bb2 100644--- a/web/packages/new/photos/services/upload/types.ts+++ b/web/packages/new/photos/services/upload/types.ts@@ -1,78 +0,0 @@-import type { ZipItem } from "@/base/types/ipc";--/**- * An item to upload is one of the following:- *- * 1. A file drag-and-dropped or selected by the user when we are running in the- * web browser. These is the {@link File} case.- *- * 2. A file drag-and-dropped or selected by the user when we are running in the- * context of our desktop app. In such cases, we also have the absolute path- * of the file in the user's local file system. This is the- * {@link FileAndPath} case.- *- * 3. A file path programmatically requested by the desktop app. For example, we- * might be resuming a previously interrupted upload after an app restart- * (thus we no longer have access to the {@link File} from case 2). Or we- * could be uploading a file this is in one of the folders the user has asked- * us to watch for changes. This is the `string` case.- *- * 4. A file within a zip file on the user's local file system. This too is only- * possible when we are running in the context of our desktop app. The user- * might have drag-and-dropped or selected a zip file, or it might be a zip- * file that they'd previously selected but we now are resuming an- * interrupted upload of. Either ways, what we have is a tuple containing the- * (path to zip file, and the name of an entry within that zip file). This is- * the {@link ZipItem} case.- *- * Also see: [Note: Reading a UploadItem].- */-export type UploadItem = File | FileAndPath | string | ZipItem;--/**- * When we are running in the context of our desktop app, we have access to the- * absolute path of {@link File} objects. This convenience type clubs these two- * bits of information, saving us the need to query the path again and again- * using the {@link getPathForFile} method of {@link Electron}.- */-export interface FileAndPath {- file: File;- path: string;-}--/**- * The of cases of {@link UploadItem} that apply when we're running in the- * context of our desktop app.- */-export type DesktopUploadItem = Exclude<UploadItem, File>;--/**- * For each of cases of {@link UploadItem} that apply when we're running in the- * context of our desktop app, return a value that can be passed to- * {@link Electron} functions over IPC.- */-export const toDataOrPathOrZipEntry = (desktopUploadItem: DesktopUploadItem) =>- typeof desktopUploadItem == "string" || Array.isArray(desktopUploadItem)- ? desktopUploadItem- : desktopUploadItem.path;--export const RANDOM_PERCENTAGE_PROGRESS_FOR_PUT = () => 90 + 10 * Math.random();--export type UploadPhase =- | "preparing"- | "readingMetadata"- | "uploading"- | "cancelling"- | "done";--export enum UPLOAD_RESULT {- FAILED,- ALREADY_UPLOADED,- UNSUPPORTED,- BLOCKED,- TOO_LARGE,- LARGER_THAN_AVAILABLE_STORAGE,- UPLOADED,- UPLOADED_WITH_STATIC_THUMBNAIL,- ADDED_SYMLINK,-}