diff --git a/desktop/src/main/stores/upload-status.ts b/desktop/src/main/stores/upload-status.ts index 5b7f7c112..4a402333a 100644 --- a/desktop/src/main/stores/upload-status.ts +++ b/desktop/src/main/stores/upload-status.ts @@ -1,10 +1,16 @@ import Store, { Schema } from "electron-store"; export interface UploadStatusStore { + /* The collection to which we're uploading, or the root collection. */ collectionName: string; + /** Paths to regular files that are pending upload */ filePaths: string[]; + /** + * Each item is the path to a zip file and the name of an entry within it. + */ + zipEntries: [zipPath: string, entryName: string][]; + /** Legacy paths to zip files, now subsumed into zipEntries */ zipPaths: string[]; - zipEntries: Record; } const uploadStatusSchema: Schema = { @@ -17,15 +23,21 @@ const uploadStatusSchema: Schema = { type: "string", }, }, + zipEntries: { + type: "array", + items: { + type: "array", + items: { + type: "string", + }, + }, + }, zipPaths: { type: "array", items: { type: "string", }, }, - zipEntries: { - type: "object", - }, }; export const uploadStatusStore = new Store({ diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts index 105661036..e340e7a06 100644 --- a/web/packages/next/types/ipc.ts +++ b/web/packages/next/types/ipc.ts @@ -465,32 +465,6 @@ export interface Electron { // - Upload - /** - * Return any pending uploads that were previously enqueued but haven't yet - * been completed. - * - * The state of pending uploads is persisted in the Node.js layer. - * - * Note that we might have both outstanding zip and regular file uploads at - * the same time. In such cases, the zip file ones get precedence. - */ - pendingUploads: () => Promise; - - /** - * Set or clear the name of the collection where the pending upload is - * directed to. - */ - setPendingUploadCollection: (collectionName: string) => Promise; - - /** - * Update the list of files (of {@link type}) associated with the pending - * upload. - */ - setPendingUploadFiles: ( - type: PendingUploads["type"], - filePaths: string[], - ) => Promise; - /** * Get the list of files that are present in the given zip file. * @@ -498,24 +472,46 @@ export interface Electron { * * @returns A list of paths, one for each file in the given zip. Directories * are traversed recursively, but the directory entries themselves will be - * excluded from the returned list. + * excluded from the returned list. File entries whose file name begins with + * a dot (i.e. "hidden" files) will also be excluded. * * To read the contents of the files themselves, see [Note: IPC streams]. */ lsZip: (zipPath: string) => Promise; - /* - * TODO: AUDIT below this - Some of the types we use below are not copyable - * across process boundaries, and such functions will (expectedly) fail at - * runtime. For such functions, find an efficient alternative or refactor - * the dataflow. + /** + * Return any pending uploads that were previously enqueued but haven't yet + * been completed. + * + * The state of pending uploads is persisted in the Node.js layer. Or app + * start, we read in this data from the Node.js layer via this IPC method. + * The Node.js code returns the persisted data after filtering out any files + * that no longer exist on disk. */ + pendingUploads: () => Promise; - // - + /** + * Set the state of pending uploads. + * + * Typically, this would be called at the start of an upload. Thereafter, as + * each item gets uploaded one by one, we'd call {@link markUploaded}. + * Finally, once the upload completes (or gets cancelled), we'd call + * {@link clearPendingUploads} to complete the circle. + */ + setPendingUploads: (pendingUploads: PendingUploads) => Promise; - getElectronFilesFromGoogleZip: ( - filePath: string, - ) => Promise; + /** + * Update the list of files (of {@link type}) associated with the pending + * upload. + */ + markUploaded: ( + pathOrZipEntry: string | [zipPath: string, entryName: string], + ) => Promise; + + /** + * Clear any pending uploads. + */ + clearPendingUploads: () => Promise; } /** @@ -622,12 +618,12 @@ export interface PendingUploads { */ filePaths: string[]; /** - * Paths of zip files that need to be uploaded. + * When the user uploads a zip file, we create a "zip entry" for each entry + * within that zip file. Such an entry is a tuple containin the path to a + * zip file itself, and the name of an entry within it. + * + * These are the remaining of those zip entries that still need to be + * uploaded. */ - zipPaths: string[]; - /** - * For each zip file, which of its entries (paths) within the zip file that - * need to be uploaded. - */ - zipEntries: Record; + zipEntries: [zipPath: string, entryName: string][]; }