π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
impl
Manav Rathi2fa1fcac6552
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex d7d4fdc098..a99a32d097 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -53,11 +53,11 @@ import {} from "./services/store";import {clearPendingUploads,+ listZipEntries,markUploadedFiles,markUploadedZipEntries,pendingUploads,setPendingUploads,- zipEntries,} from "./services/upload";import {watchAdd,@@ -200,7 +200,9 @@ export const attachIPCHandlers = () => {// - Upload- ipcMain.handle("zipEntries", (_, zipPath: string) => zipEntries(zipPath));+ ipcMain.handle("listZipEntries", (_, zipPath: string) =>+ listZipEntries(zipPath),+ );ipcMain.handle("pendingUploads", () => pendingUploads());diff --git a/desktop/src/main/services/upload.ts b/desktop/src/main/services/upload.tsindex c5a987e7bc..8487f8327e 100644--- a/desktop/src/main/services/upload.ts+++ b/desktop/src/main/services/upload.ts@@ -2,13 +2,10 @@ import StreamZip from "node-stream-zip";import { existsSync } from "original-fs";import path from "path";import type { ElectronFile, PendingUploads, ZipEntry } from "../../types/ipc";-import {- uploadStatusStore,- type UploadStatusStore,-} from "../stores/upload-status";-import { getElectronFile, getZipFileStream } from "./fs";+import { uploadStatusStore } from "../stores/upload-status";+import { getZipFileStream } from "./fs";-export const zipEntries = async (zipPath: string): Promise<ZipEntry[]> => {+export const listZipEntries = async (zipPath: string): Promise<ZipEntry[]> => {const zip = new StreamZip.async({ file: zipPath });const entries = await zip.entries();@@ -33,7 +30,9 @@ export const pendingUploads = async (): Promise<PendingUploads | undefined> => {const allFilePaths = uploadStatusStore.get("filePaths");const filePaths = allFilePaths.filter((f) => existsSync(f));- let allZipEntries = uploadStatusStore.get("zipEntries");+ const allZipEntries = uploadStatusStore.get("zipEntries");+ let zipEntries: typeof allZipEntries;+// Migration code - May 2024. Remove after a bit.//// The older store formats will not have zipEntries and instead will have@@ -44,34 +43,17 @@ export const pendingUploads = async (): Promise<PendingUploads | undefined> => {if (allZipEntries === undefined) {const allZipPaths = uploadStatusStore.get("filePaths");const zipPaths = allZipPaths.filter((f) => existsSync(f));- lsZip();- }-- if (allZipEntries) "files";- const zipPaths = validSavedPaths("zips");-- let files: ElectronFile[] = [];- let type: PendingUploads["type"];-- if (zipPaths.length) {- type = "zips";- for (const zipPath of zipPaths) {- files = [- ...files,- ...(await getElectronFilesFromGoogleZip(zipPath)),- ];- }- const pendingFilePaths = new Set(filePaths);- files = files.filter((file) => pendingFilePaths.has(file.path));- } else if (filePaths.length) {- type = "files";- files = await Promise.all(filePaths.map(getElectronFile));+ zipEntries = [];+ for (const zip of zipPaths)+ zipEntries = zipEntries.concat(await listZipEntries(zip));+ } else {+ zipEntries = allZipEntries.filter(([z]) => existsSync(z));}return {- files,collectionName,- type,+ filePaths,+ zipEntries,};};@@ -94,39 +76,8 @@ export const markUploadedZipEntries = async (uploadStatusStore.set("zipEntries", updated);};-const validSavedPaths = (type: PendingUploads["type"]) => {- const key = storeKey(type);- const savedPaths = (uploadStatusStore.get(key) as string[]) ?? [];- const paths = savedPaths.filter((p) => existsSync(p));- uploadStatusStore.set(key, paths);- return paths;-};--const setPendingUploadCollection = (collectionName: string) => {- if (collectionName) uploadStatusStore.set("collectionName", collectionName);- else uploadStatusStore.delete("collectionName");-};--const setPendingUploadFiles = (- type: PendingUploads["type"],- filePaths: string[],-) => {- const key = storeKey(type);- if (filePaths) uploadStatusStore.set(key, filePaths);- else uploadStatusStore.delete(key);-};-export const clearPendingUploads = () => uploadStatusStore.clear();-const storeKey = (type: PendingUploads["type"]): keyof UploadStatusStore => {- switch (type) {- case "zips":- return "zipPaths";- case "files":- return "filePaths";- }-};-export const getElectronFilesFromGoogleZip = async (filePath: string) => {const zip = new StreamZip.async({file: filePath,diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex ac149ad133..e80625de99 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -242,8 +242,8 @@ const watchFindFiles = (folderPath: string): Promise<string[]> =>// - Upload-const zipEntries = (zipPath: string): Promise<ZipEntry[]> =>- ipcRenderer.invoke("zipEntries", zipPath);+const listZipEntries = (zipPath: string): Promise<ZipEntry[]> =>+ ipcRenderer.invoke("listZipEntries", zipPath);const pendingUploads = (): Promise<PendingUploads | undefined> =>ipcRenderer.invoke("pendingUploads");@@ -370,7 +370,7 @@ contextBridge.exposeInMainWorld("electron", {// - Upload- zipEntries,+ listZipEntries,pendingUploads,setPendingUploads,markUploadedFiles,diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.tsindex 6aa394c6c5..7198a2ebce 100644--- a/web/packages/next/types/ipc.ts+++ b/web/packages/next/types/ipc.ts@@ -478,7 +478,7 @@ export interface Electron {** To read the contents of the files themselves, see [Note: IPC streams].*/- zipEntries : (zipPath: string) => Promise<ZipEntry[]>+ listZipEntries : (zipPath: string) => Promise<ZipEntry[]>/*** Return any pending uploads that were previously enqueued but haven't yet