|
@@ -1,10 +1,39 @@
|
|
import StreamZip from "node-stream-zip";
|
|
import StreamZip from "node-stream-zip";
|
|
import path from "path";
|
|
import path from "path";
|
|
|
|
+import { getElectronFile } from "../services/fs";
|
|
import { uploadStatusStore } from "../stores/upload.store";
|
|
import { uploadStatusStore } from "../stores/upload.store";
|
|
import { ElectronFile, FILE_PATH_TYPE } from "../types/ipc";
|
|
import { ElectronFile, FILE_PATH_TYPE } from "../types/ipc";
|
|
import { FILE_PATH_KEYS } from "../types/main";
|
|
import { FILE_PATH_KEYS } from "../types/main";
|
|
import { getValidPaths, getZipFileStream } from "./fs";
|
|
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) => {
|
|
export const getSavedFilePaths = (type: FILE_PATH_TYPE) => {
|
|
const paths =
|
|
const paths =
|
|
getValidPaths(
|
|
getValidPaths(
|