π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
impl
Manav Rathifca398f296a8
diff --git a/desktop/src/main/fs.ts b/desktop/src/main/fs.tsindex fc181cf46c..2428d3a80c 100644--- a/desktop/src/main/fs.ts+++ b/desktop/src/main/fs.ts@@ -27,5 +27,3 @@ export const fsIsDir = async (dirPath: string) => {const stat = await fs.stat(dirPath);return stat.isDirectory();};--export const fsSize = (path: string) => fs.stat(path).then((s) => s.size);diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex a99a32d097..01f481f8eb 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -14,6 +14,7 @@ import type {CollectionMapping,FolderWatch,PendingUploads,+ ZipEntry,} from "../types/ipc";import {selectDirectory,@@ -29,7 +30,6 @@ import {fsRename,fsRm,fsRmdir,- fsSize,fsWriteFile,} from "./fs";import { logToDisk } from "./log";@@ -54,6 +54,7 @@ import {import {clearPendingUploads,listZipEntries,+ pathOrZipEntrySize,markUploadedFiles,markUploadedZipEntries,pendingUploads,@@ -141,8 +142,6 @@ export const attachIPCHandlers = () => {ipcMain.handle("fsIsDir", (_, dirPath: string) => fsIsDir(dirPath));- ipcMain.handle("fsSize", (_, path: string) => fsSize(path));-// - ConversionipcMain.handle("convertToJPEG", (_, imageData: Uint8Array) =>@@ -204,6 +203,12 @@ export const attachIPCHandlers = () => {listZipEntries(zipPath),);+ ipcMain.handle(+ "pathOrZipEntrySize",+ (_, pathOrZipEntry: string | ZipEntry) =>+ pathOrZipEntrySize(pathOrZipEntry),+ );+ipcMain.handle("pendingUploads", () => pendingUploads());ipcMain.handle("setPendingUploads", (_, pendingUploads: PendingUploads) =>diff --git a/desktop/src/main/services/upload.ts b/desktop/src/main/services/upload.tsindex 1f52fe1e7c..a26722cb80 100644--- a/desktop/src/main/services/upload.ts+++ b/desktop/src/main/services/upload.ts@@ -1,4 +1,5 @@import StreamZip from "node-stream-zip";+import fs from "node:fs/promises";import { existsSync } from "original-fs";import path from "path";import type { ElectronFile, PendingUploads, ZipEntry } from "../../types/ipc";@@ -23,6 +24,20 @@ export const listZipEntries = async (zipPath: string): Promise<ZipEntry[]> => {return entryNames.map((entryName) => [zipPath, entryName]);};+export const pathOrZipEntrySize = async (+ pathOrZipEntry: string | ZipEntry,+): Promise<number> => {+ if (typeof pathOrZipEntry == "string") {+ const stat = await fs.stat(pathOrZipEntry);+ return stat.size;+ } else {+ const [zipPath, entryName] = pathOrZipEntry;+ const zip = new StreamZip.async({ file: zipPath });+ const entry = await zip.entry(entryName);+ return entry.size;+ }+};+export const pendingUploads = async (): Promise<PendingUploads | undefined> => {const collectionName = uploadStatusStore.get("collectionName");diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex 4bb23b9ac6..226a80767a 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -123,9 +123,6 @@ const fsWriteFile = (path: string, contents: string): Promise<void> =>const fsIsDir = (dirPath: string): Promise<boolean> =>ipcRenderer.invoke("fsIsDir", dirPath);-const fsSize = (path: string): Promise<number> =>- ipcRenderer.invoke("fsSize", path);-// - Conversionconst convertToJPEG = (imageData: Uint8Array): Promise<Uint8Array> =>@@ -247,6 +244,10 @@ const pathForFile = (file: File) => webUtils.getPathForFile(file);const listZipEntries = (zipPath: string): Promise<ZipEntry[]> =>ipcRenderer.invoke("listZipEntries", zipPath);+const pathOrZipEntrySize = (+ pathOrZipEntry: string | ZipEntry,+): Promise<number> => ipcRenderer.invoke("pathOrZipEntrySize", pathOrZipEntry);+const pendingUploads = (): Promise<PendingUploads | undefined> =>ipcRenderer.invoke("pendingUploads");@@ -333,7 +334,6 @@ contextBridge.exposeInMainWorld("electron", {readTextFile: fsReadTextFile,writeFile: fsWriteFile,isDir: fsIsDir,- size: fsSize,},// - Conversion@@ -374,6 +374,7 @@ contextBridge.exposeInMainWorld("electron", {pathForFile,listZipEntries,+ pathOrZipEntrySize,pendingUploads,setPendingUploads,markUploadedFiles,diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.tsindex a93d98975d..954f171f9a 100644--- a/web/apps/photos/src/services/upload/uploadService.ts+++ b/web/apps/photos/src/services/upload/uploadService.ts@@ -197,13 +197,12 @@ export const uploadItemSize = async (uploadItem: UploadItem,): Promise<number> => {if (uploadItem instanceof File) return uploadItem.size;- if (typeof uploadItem == "string") return basename(uploadItem);- if (Array.isArray(uploadItem)) return basename(uploadItem[1]);+ if (typeof uploadItem == "string")+ return ensureElectron().pathOrZipEntrySize(uploadItem);+ if (Array.isArray(uploadItem))+ return ensureElectron().pathOrZipEntrySize(uploadItem);return uploadItem.file.size;};-uploadItem instanceof File- ? uploadItem.size- : await ensureElectron().fs.size(uploadItem);/* -- Various intermediate type used during upload -- */diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.tsindex dab10cc8e0..34bb9196a2 100644--- a/web/packages/next/types/ipc.ts+++ b/web/packages/next/types/ipc.ts@@ -189,11 +189,6 @@ export interface Electron {* directory.*/isDir: (dirPath: string) => Promise<boolean>;-- /**- * Return the size in bytes of the file at {@link path}.- */- size: (path: string) => Promise<number>;};// - Conversion@@ -492,6 +487,12 @@ export interface Electron {*/listZipEntries: (zipPath: string) => Promise<ZipEntry[]>;+ /**+ * Return the size in bytes of the file at the given path or of a particular+ * entry within a zip file.+ */+ pathOrZipEntrySize: (pathOrZipEntry: string | ZipEntry) => Promise<number>;+/*** Return any pending uploads that were previously enqueued but haven't yet* been completed.