π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
File sizes
Manav Rathica0afc2f3a97
diff --git a/desktop/src/main/fs.ts b/desktop/src/main/fs.tsindex 2428d3a80c..fc181cf46c 100644--- a/desktop/src/main/fs.ts+++ b/desktop/src/main/fs.ts@@ -27,3 +27,5 @@ 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 15d51530df..2475d77892 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -29,6 +29,7 @@ import {fsRename,fsRm,fsRmdir,+ fsSize,fsWriteFile,} from "./fs";import { logToDisk } from "./log";@@ -139,6 +140,8 @@ export const attachIPCHandlers = () => {ipcMain.handle("fsIsDir", (_, dirPath: string) => fsIsDir(dirPath));+ ipcMain.handle("fsSize", (_, path: string) => fsSize(path));+// - ConversionipcMain.handle("convertToJPEG", (_, imageData: Uint8Array) =>diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex ea3cf1e054..68308aea9f 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -122,6 +122,9 @@ 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> =>@@ -331,6 +334,7 @@ contextBridge.exposeInMainWorld("electron", {readTextFile: fsReadTextFile,writeFile: fsWriteFile,isDir: fsIsDir,+ size: fsSize,},// - Conversiondiff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.tsindex fef3ee4308..4f8486f933 100644--- a/web/apps/photos/src/services/upload/uploadManager.ts+++ b/web/apps/photos/src/services/upload/uploadManager.ts@@ -50,6 +50,7 @@ import {} from "./takeout";import UploadService, {assetName,+ fopSize,getAssetName,getFileName,uploader,@@ -396,7 +397,7 @@ class UploadManager {if (mediaFiles.length) {/* TODO(MR): ElectronFile changes */- const clusteredMediaFiles = clusterLivePhotos(+ const clusteredMediaFiles = await clusterLivePhotos(mediaFiles as ClusterableFile[],);@@ -775,7 +776,7 @@ type ClusteredFile = {* Go through the given files, combining any sibling image + video assets into a* single live photo when appropriate.*/-const clusterLivePhotos = (files: ClusterableFile[]) => {+const clusterLivePhotos = async (files: ClusterableFile[]) => {const result: ClusteredFile[] = [];const filesWithName: (ClusterableFile & { fileName: string })[] = files.map((f) => {@@ -799,17 +800,15 @@ const clusterLivePhotos = (files: ClusterableFile[]) => {fileName: f.fileName,fileType: fFileType,collectionID: f.collectionID,- /* TODO(MR): ElectronFile changes */- size: (f as FileWithCollection).file.size,+ fileOrPath: f.file,};const ga: PotentialLivePhotoAsset = {fileName: g.fileName,fileType: gFileType,collectionID: g.collectionID,- /* TODO(MR): ElectronFile changes */- size: (g as FileWithCollection).file.size,+ fileOrPath: g.file,};- if (areLivePhotoAssets(fa, ga)) {+ if (await areLivePhotoAssets(fa, ga)) {result.push({localID: f.localID,collectionID: f.collectionID,@@ -841,10 +840,10 @@ interface PotentialLivePhotoAsset {fileName: string;fileType: FILE_TYPE;collectionID: number;- size: number;+ fileOrPath: File | string;}-const areLivePhotoAssets = (+const areLivePhotoAssets = async (f: PotentialLivePhotoAsset,g: PotentialLivePhotoAsset,) => {@@ -884,9 +883,11 @@ const areLivePhotoAssets = (// we use doesn't support stream as a input.const maxAssetSize = 20 * 1024 * 1024; /* 20MB */- if (f.size > maxAssetSize || g.size > maxAssetSize) {+ const fSize = await fopSize(f.fileOrPath);+ const gSize = await fopSize(g.fileOrPath);+ if (fSize > maxAssetSize || gSize > maxAssetSize) {log.info(- `Not classifying assets with too large sizes ${[f.size, g.size]} as a live photo`,+ `Not classifying assets with too large sizes ${[fSize, gSize]} as a live photo`,);return false;}diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.tsindex dc83aa6c9f..c8e56c77eb 100644--- a/web/apps/photos/src/services/upload/uploadService.ts+++ b/web/apps/photos/src/services/upload/uploadService.ts@@ -318,6 +318,17 @@ export const uploader = async (}};+/**+ * Return the size of the given file+ *+ * @param fileOrPath The {@link File}, or the path to it. Note that it is only+ * valid to specify a path if we are running in the context of our desktop app.+ */+export const fopSize = async (fileOrPath: File | string): Promise<number> =>+ fileOrPath instanceof File+ ? fileOrPath.size+ : await ensureElectron().fs.size(fileOrPath);+export const getFileName = (file: File | ElectronFile | string) =>typeof file == "string" ? basename(file) : file.name;diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.tsindex cdc3597ec9..91a9927f2c 100644--- a/web/packages/next/types/ipc.ts+++ b/web/packages/next/types/ipc.ts@@ -189,6 +189,11 @@ 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