diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts index bde28d940..6e8bbe3f7 100644 --- a/desktop/src/main/ipc.ts +++ b/desktop/src/main/ipc.ts @@ -52,12 +52,11 @@ import { saveEncryptionKey, } from "./services/store"; import { - clearPendingUploads, - getElectronFilesFromGoogleZip, lsZip, pendingUploads, - setPendingUploadCollection, - setPendingUploadFiles, + setPendingUploads, + markUploaded, + clearPendingUploads, } from "./services/upload"; import { watchAdd, @@ -204,14 +203,11 @@ export const attachIPCHandlers = () => { ipcMain.handle("pendingUploads", () => pendingUploads()); - ipcMain.handle("setPendingUploadCollection", (_, collectionName: string) => - setPendingUploadCollection(collectionName), - ); + ipcMain.handle("setPendingUploads", (_, pendingUploads: PendingUploads) => + setPendingUploads(pendingUploads), - ipcMain.handle( - "setPendingUploadFiles", - (_, type: PendingUploads["type"], filePaths: string[]) => - setPendingUploadFiles(type, filePaths), + ipcMain.handle("markUploaded", (_, pathOrZipEntry: string | [zipPath: string, entryName: string]) => + markUploaded(pathOrZipEntry), ); ipcMain.handle("clearPendingUploads", () => clearPendingUploads()); diff --git a/desktop/src/main/services/upload.ts b/desktop/src/main/services/upload.ts index 1ca7c2bc4..66c97e34c 100644 --- a/desktop/src/main/services/upload.ts +++ b/desktop/src/main/services/upload.ts @@ -26,7 +26,8 @@ export const lsZip = async (zipPath: string) => { return [entryPaths]; }; -export const pendingUploads = async () => { +export const pendingUploads = async (): Promise => { + /* TODO */ const collectionName = uploadStatusStore.get("collectionName"); const filePaths = validSavedPaths("files"); const zipPaths = validSavedPaths("zips"); @@ -56,7 +57,14 @@ export const pendingUploads = async () => { }; }; -export const validSavedPaths = (type: PendingUploads["type"]) => { +export const setPendingUploads = async (pendingUploads: PendingUploads) => + uploadStatusStore.set(pendingUploads); + +export const markUploaded = async ( + pathOrZipEntry: string | [zipPath: string, entryName: string], +) => {}; + +const validSavedPaths = (type: PendingUploads["type"]) => { const key = storeKey(type); const savedPaths = (uploadStatusStore.get(key) as string[]) ?? []; const paths = savedPaths.filter((p) => existsSync(p)); @@ -64,12 +72,12 @@ export const validSavedPaths = (type: PendingUploads["type"]) => { return paths; }; -export const setPendingUploadCollection = (collectionName: string) => { +const setPendingUploadCollection = (collectionName: string) => { if (collectionName) uploadStatusStore.set("collectionName", collectionName); else uploadStatusStore.delete("collectionName"); }; -export const setPendingUploadFiles = ( +const setPendingUploadFiles = ( type: PendingUploads["type"], filePaths: string[], ) => { @@ -78,9 +86,7 @@ export const setPendingUploadFiles = ( else uploadStatusStore.delete(key); }; -export const clearPendingUploads = () => { - uploadStatusStore.clear(); -}; +export const clearPendingUploads = () => uploadStatusStore.clear(); const storeKey = (type: PendingUploads["type"]): keyof UploadStatusStore => { switch (type) { diff --git a/desktop/src/main/stores/upload-status.ts b/desktop/src/main/stores/upload-status.ts index 4a402333a..36a7d1fa7 100644 --- a/desktop/src/main/stores/upload-status.ts +++ b/desktop/src/main/stores/upload-status.ts @@ -10,7 +10,7 @@ export interface UploadStatusStore { */ zipEntries: [zipPath: string, entryName: string][]; /** Legacy paths to zip files, now subsumed into zipEntries */ - zipPaths: string[]; + zipPaths?: string[]; } const uploadStatusSchema: Schema = { diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts index ad93a40f6..c3737aceb 100644 --- a/desktop/src/preload.ts +++ b/desktop/src/preload.ts @@ -247,26 +247,16 @@ const lsZip = (zipPath: string): Promise => const pendingUploads = (): Promise => ipcRenderer.invoke("pendingUploads"); -const setPendingUploadCollection = (collectionName: string): Promise => - ipcRenderer.invoke("setPendingUploadCollection", collectionName); +const setPendingUploads = (pendingUploads: PendingUploads): Promise => + ipcRenderer.invoke("setPendingUploads", pendingUploads); -const setPendingUploadFiles = ( - type: PendingUploads["type"], - filePaths: string[], -): Promise => - ipcRenderer.invoke("setPendingUploadFiles", type, filePaths); +const markUploaded = ( + pathOrZipEntry: string | [zipPath: string, entryName: string], +): Promise => ipcRenderer.invoke("markUploaded", pathOrZipEntry); const clearPendingUploads = (): Promise => ipcRenderer.invoke("clearPendingUploads"); -// - TODO: AUDIT below this -// - - -const getElectronFilesFromGoogleZip = ( - filePath: string, -): Promise => - ipcRenderer.invoke("getElectronFilesFromGoogleZip", filePath); - /** * These objects exposed here will become available to the JS code in our * renderer (the web/ code) as `window.ElectronAPIs.*` @@ -378,11 +368,7 @@ contextBridge.exposeInMainWorld("electron", { lsZip, pendingUploads, - setPendingUploadCollection, - setPendingUploadFiles, + setPendingUploads, + markUploaded, clearPendingUploads, - - // - - - getElectronFilesFromGoogleZip, }); diff --git a/desktop/src/types/ipc.ts b/desktop/src/types/ipc.ts index 3fa375eab..f343e2bba 100644 --- a/desktop/src/types/ipc.ts +++ b/desktop/src/types/ipc.ts @@ -27,8 +27,8 @@ export interface FolderWatchSyncedFile { export interface PendingUploads { collectionName: string; - type: "files" | "zips"; - files: ElectronFile[]; + filePaths: string[]; + zipEntries: [zipPath: string, entryName: string][]; } /**