Ver código fonte

api => services

Manav Rathi 1 ano atrás
pai
commit
15e290a993

+ 0 - 11
desktop/src/api/electronStore.ts

@@ -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();
-};

+ 0 - 41
desktop/src/api/upload.ts

@@ -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";

+ 11 - 8
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,

+ 10 - 0
desktop/src/api/safeStorage.ts → 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);

+ 29 - 0
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(