π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Desktop side
Manav Rathi0668490f8af6
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex bc41545f7c..2bc8128d96 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -10,7 +10,7 @@import type { FSWatcher } from "chokidar";import { ipcMain } from "electron/main";-import type { ElectronFile, FILE_PATH_TYPE, FolderWatch } from "../types/ipc";+import type { ElectronFile, FolderWatch, PendingUploads } from "../types/ipc";import {selectDirectory,showUploadDirsDialog,@@ -49,9 +49,8 @@ import {} from "./services/store";import {getElectronFilesFromGoogleZip,- getPendingUploads,- setToUploadCollection,- setToUploadFiles,+ setPendingUploadCollection,+ setPendingUploadFiles,} from "./services/upload";import {addWatchMapping,@@ -188,22 +187,24 @@ export const attachIPCHandlers = () => {// - Upload- ipcMain.handle("getPendingUploads", () => getPendingUploads());+ ipcMain.handle("pendingUploads", () => pendingUploads());++ ipcMain.handle("setPendingUploadCollection", (_, collectionName: string) =>+ setPendingUploadCollection(collectionName),+ );ipcMain.handle(- "setToUploadFiles",- (_, type: FILE_PATH_TYPE, filePaths: string[]) =>- setToUploadFiles(type, filePaths),+ "setPendingUploadFiles",+ (_, type: PendingUploads["type"], filePaths: string[]) =>+ setPendingUploadFiles(type, filePaths),);+ // -+ipcMain.handle("getElectronFilesFromGoogleZip", (_, filePath: string) =>getElectronFilesFromGoogleZip(filePath),);- ipcMain.handle("setToUploadCollection", (_, collectionName: string) =>- setToUploadCollection(collectionName),- );-ipcMain.handle("getDirFiles", (_, dirPath: string) => getDirFiles(dirPath));};diff --git a/desktop/src/main/services/upload.ts b/desktop/src/main/services/upload.tsindex 2bf941bcf5..bdd90c7310 100644--- a/desktop/src/main/services/upload.ts+++ b/desktop/src/main/services/upload.ts@@ -1,11 +1,18 @@import StreamZip from "node-stream-zip";import path from "path";-import { ElectronFile, FILE_PATH_TYPE } from "../../types/ipc";+import {+ ElectronFile,+ FILE_PATH_TYPE,+ type PendingUploads,+} from "../../types/ipc";import { FILE_PATH_KEYS } from "../../types/main";-import { uploadStatusStore } from "../stores/upload-status";+import {+ uploadStatusStore,+ type UploadStatusStore,+} from "../stores/upload-status";import { getElectronFile, getValidPaths, getZipFileStream } from "./fs";-export const getPendingUploads = async () => {+export const pendingUploads = async () => {const filePaths = getSavedFilePaths(FILE_PATH_TYPE.FILES);const zipPaths = getSavedFilePaths(FILE_PATH_TYPE.ZIPS);const collectionName = uploadStatusStore.get("collectionName");@@ -70,20 +77,26 @@ export async function getZipEntryAsElectronFile(};}-export const setToUploadFiles = (type: FILE_PATH_TYPE, filePaths: string[]) => {- const key = FILE_PATH_KEYS[type];- if (filePaths) {- uploadStatusStore.set(key, filePaths);- } else {- uploadStatusStore.delete(key);- }+export const setPendingUploadCollection = (collectionName: string) => {+ if (collectionName) uploadStatusStore.set("collectionName", collectionName);+ else uploadStatusStore.delete("collectionName");+};++export const setPendingUploadFiles = (+ type: PendingUploads["type"],+ filePaths: string[],+) => {+ const key = storeKey(type);+ if (filePaths) uploadStatusStore.set(key, filePaths);+ else uploadStatusStore.delete(key);};-export const setToUploadCollection = (collectionName: string) => {- if (collectionName) {- uploadStatusStore.set("collectionName", collectionName);- } else {- uploadStatusStore.delete("collectionName");+const storeKey = (type: PendingUploads["type"]): keyof UploadStatusStore => {+ switch (type) {+ case "zips":+ return "zipPaths";+ case "files":+ return "filePaths";}};diff --git a/desktop/src/main/stores/upload-status.ts b/desktop/src/main/stores/upload-status.tsindex 2acaea2ba1..25af7a49e2 100644--- a/desktop/src/main/stores/upload-status.ts+++ b/desktop/src/main/stores/upload-status.ts@@ -1,6 +1,6 @@import Store, { Schema } from "electron-store";-interface UploadStatusStore {+export interface UploadStatusStore {filePaths: string[];zipPaths: string[];collectionName: string;diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex 53df1c968a..39d01a66d6 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -44,8 +44,8 @@ import { contextBridge, ipcRenderer } from "electron/renderer";import type {AppUpdateInfo,ElectronFile,- FILE_PATH_TYPE,FolderWatch,+ PendingUploads,} from "./types/ipc";// - General@@ -243,25 +243,25 @@ const updateWatchMappingIgnoredFiles = (// - Upload-const getPendingUploads = (): Promise<{- files: ElectronFile[];- collectionName: string;- type: string;-}> => ipcRenderer.invoke("getPendingUploads");+const pendingUploads = (): Promise<PendingUploads | undefined> =>+ ipcRenderer.invoke("pendingUploads");++const setPendingUploadCollection = (collectionName: string): Promise<void> =>+ ipcRenderer.invoke("setPendingUploadCollection", collectionName);-const setToUploadFiles = (- type: FILE_PATH_TYPE,+const setPendingUploadFiles = (+ type: PendingUploads["type"],filePaths: string[],-): Promise<void> => ipcRenderer.invoke("setToUploadFiles", type, filePaths);+): Promise<void> =>+ ipcRenderer.invoke("setPendingUploadFiles", type, filePaths);++// -const getElectronFilesFromGoogleZip = (filePath: string,): Promise<ElectronFile[]> =>ipcRenderer.invoke("getElectronFilesFromGoogleZip", filePath);-const setToUploadCollection = (collectionName: string): Promise<void> =>- ipcRenderer.invoke("setToUploadCollection", collectionName);-const getDirFiles = (dirPath: string): Promise<ElectronFile[]> =>ipcRenderer.invoke("getDirFiles", dirPath);@@ -300,6 +300,7 @@ const getDirFiles = (dirPath: string): Promise<ElectronFile[]> =>// alternative, see [Note: IPC streams].contextBridge.exposeInMainWorld("electron", {// - General+appVersion,logToDisk,openDirectory,@@ -310,12 +311,14 @@ contextBridge.exposeInMainWorld("electron", {onMainWindowFocus,// - App update+onAppUpdateAvailable,updateAndRestart,updateOnNextRestart,skipAppUpdate,// - FS+fs: {exists: fsExists,rename: fsRename,@@ -328,23 +331,27 @@ contextBridge.exposeInMainWorld("electron", {},// - Conversion+convertToJPEG,generateImageThumbnail,runFFmpegCmd,// - ML+clipImageEmbedding,clipTextEmbedding,detectFaces,faceEmbedding,// - File selection+selectDirectory,showUploadFilesDialog,showUploadDirsDialog,showUploadZipDialog,// - Watch+watch: {findFiles,},@@ -357,9 +364,12 @@ contextBridge.exposeInMainWorld("electron", {// - Upload- getPendingUploads,- setToUploadFiles,+ pendingUploads,+ setPendingUploadCollection,+ setPendingUploadFiles,++ // -+getElectronFilesFromGoogleZip,- setToUploadCollection,getDirFiles,});diff --git a/desktop/src/types/ipc.ts b/desktop/src/types/ipc.tsindex a568ad6e5b..864c6ab113 100644--- a/desktop/src/types/ipc.ts+++ b/desktop/src/types/ipc.ts@@ -19,6 +19,14 @@ export interface FolderWatchSyncedFile {collectionID: number;}+export interface PendingUploads {+ /** The collection to which we're uploading */+ collectionName: string;+ /* The upload can be either of a Google Takeout zip, or regular files */+ type: "files" | "zips";+ files: ElectronFile[];+}+/*** Errors that have special semantics on the web side.*