π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
api => services
Manav Rathi15e290a99386
diff --git a/desktop/src/api/electronStore.ts b/desktop/src/api/electronStore.tsdeleted file mode 100644index 30fc5427d0..0000000000--- a/desktop/src/api/electronStore.ts+++ /dev/null@@ -1,11 +0,0 @@-import { keysStore } from "../stores/keys.store";-import { safeStorageStore } from "../stores/safeStorage.store";-import { uploadStatusStore } from "../stores/upload.store";-import { watchStore } from "../stores/watch.store";--export const clearElectronStore = () => {- uploadStatusStore.clear();- keysStore.clear();- safeStorageStore.clear();- watchStore.clear();-};diff --git a/desktop/src/api/upload.ts b/desktop/src/api/upload.tsdeleted file mode 100644index 24d0283ffd..0000000000--- a/desktop/src/api/upload.ts+++ /dev/null@@ -1,41 +0,0 @@-import { getElectronFile } from "../services/fs";-import {- getElectronFilesFromGoogleZip,- getSavedFilePaths,-} from "../services/upload";-import { uploadStatusStore } from "../stores/upload.store";-import { ElectronFile, FILE_PATH_TYPE } from "../types/ipc";--export const getPendingUploads = async () => {- const filePaths = getSavedFilePaths(FILE_PATH_TYPE.FILES);- const zipPaths = getSavedFilePaths(FILE_PATH_TYPE.ZIPS);- const collectionName = uploadStatusStore.get("collectionName");-- let files: ElectronFile[] = [];- let type: FILE_PATH_TYPE;- if (zipPaths.length) {- type = FILE_PATH_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 = FILE_PATH_TYPE.FILES;- files = await Promise.all(filePaths.map(getElectronFile));- }- return {- files,- collectionName,- type,- };-};--export {- getElectronFilesFromGoogleZip,- setToUploadCollection,- setToUploadFiles,-} from "../services/upload";diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex be97981867..2ab8360fe3 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -10,14 +10,6 @@import type { FSWatcher } from "chokidar";import { ipcMain } from "electron/main";-import { clearElectronStore } from "../api/electronStore";-import { getEncryptionKey, setEncryptionKey } from "../api/safeStorage";-import {- getElectronFilesFromGoogleZip,- getPendingUploads,- setToUploadCollection,- setToUploadFiles,-} from "../api/upload";import {appVersion,muteUpdateNotification,@@ -34,6 +26,17 @@ import {convertToJPEG,generateImageThumbnail,} from "../services/imageProcessor";+import {+ clearElectronStore,+ getEncryptionKey,+ setEncryptionKey,+} from "../services/store";+import {+ getElectronFilesFromGoogleZip,+ getPendingUploads,+ setToUploadCollection,+ setToUploadFiles,+} from "../services/upload";import {addWatchMapping,getWatchMappings,diff --git a/desktop/src/api/safeStorage.ts b/desktop/src/services/store.tssimilarity index 68%rename from desktop/src/api/safeStorage.tsrename to desktop/src/services/store.tsindex cf5106d898..20326dee11 100644--- a/desktop/src/api/safeStorage.ts+++ b/desktop/src/services/store.ts@@ -1,5 +1,15 @@import { safeStorage } from "electron/main";+import { keysStore } from "../stores/keys.store";import { safeStorageStore } from "../stores/safeStorage.store";+import { uploadStatusStore } from "../stores/upload.store";+import { watchStore } from "../stores/watch.store";++export const clearElectronStore = () => {+ uploadStatusStore.clear();+ keysStore.clear();+ safeStorageStore.clear();+ watchStore.clear();+};export async function setEncryptionKey(encryptionKey: string) {const encryptedKey: Buffer = await safeStorage.encryptString(encryptionKey);diff --git a/desktop/src/services/upload.ts b/desktop/src/services/upload.tsindex 2fc56fef53..ae51e82180 100644--- a/desktop/src/services/upload.ts+++ b/desktop/src/services/upload.ts@@ -1,10 +1,39 @@import StreamZip from "node-stream-zip";import path from "path";+import { getElectronFile } from "../services/fs";import { uploadStatusStore } from "../stores/upload.store";import { ElectronFile, FILE_PATH_TYPE } from "../types/ipc";import { FILE_PATH_KEYS } from "../types/main";import { getValidPaths, getZipFileStream } from "./fs";+export const getPendingUploads = async () => {+ const filePaths = getSavedFilePaths(FILE_PATH_TYPE.FILES);+ const zipPaths = getSavedFilePaths(FILE_PATH_TYPE.ZIPS);+ const collectionName = uploadStatusStore.get("collectionName");++ let files: ElectronFile[] = [];+ let type: FILE_PATH_TYPE;+ if (zipPaths.length) {+ type = FILE_PATH_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 = FILE_PATH_TYPE.FILES;+ files = await Promise.all(filePaths.map(getElectronFile));+ }+ return {+ files,+ collectionName,+ type,+ };+};+export const getSavedFilePaths = (type: FILE_PATH_TYPE) => {const paths =getValidPaths(