node side
This commit is contained in:
@@ -56,8 +56,8 @@ import {
|
||||
import {
|
||||
clearPendingUploads,
|
||||
listZipItems,
|
||||
markUploadedFiles,
|
||||
markUploadedZipItems,
|
||||
markUploadedFile,
|
||||
markUploadedZipItem,
|
||||
pathOrZipItemSize,
|
||||
pendingUploads,
|
||||
setPendingUploads,
|
||||
@@ -211,13 +211,15 @@ export const attachIPCHandlers = () => {
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
"markUploadedFiles",
|
||||
(_, paths: PendingUploads["filePaths"]) => markUploadedFiles(paths),
|
||||
"markUploadedFile",
|
||||
(_, path: string, associatedPath: string | undefined) =>
|
||||
markUploadedFile(path, associatedPath),
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
"markUploadedZipItems",
|
||||
(_, items: PendingUploads["zipItems"]) => markUploadedZipItems(items),
|
||||
"markUploadedZipItem",
|
||||
(_, item: ZipItem, associatedItem: ZipItem | undefined) =>
|
||||
markUploadedZipItem(item, associatedItem),
|
||||
);
|
||||
|
||||
ipcMain.handle("clearPendingUploads", () => clearPendingUploads());
|
||||
|
||||
@@ -135,22 +135,34 @@ export const setPendingUploads = ({
|
||||
});
|
||||
};
|
||||
|
||||
export const markUploadedFiles = (paths: string[]) => {
|
||||
export const markUploadedFile = (
|
||||
path: string,
|
||||
associatedPath: string | undefined,
|
||||
) => {
|
||||
const existing = uploadStatusStore.get("filePaths") ?? [];
|
||||
const updated = existing.filter((p) => !paths.includes(p));
|
||||
const updated = existing.filter((p) => p != path && p != associatedPath);
|
||||
uploadStatusStore.set("filePaths", updated);
|
||||
return fs.stat(path).then((st) => st.mtime.getTime());
|
||||
};
|
||||
|
||||
export const markUploadedZipItems = (
|
||||
items: [zipPath: string, entryName: string][],
|
||||
export const markUploadedZipItem = (
|
||||
item: ZipItem,
|
||||
associatedItem: ZipItem | undefined,
|
||||
) => {
|
||||
const existing = uploadStatusStore.get("zipItems") ?? [];
|
||||
const updated = existing.filter(
|
||||
(z) => !items.some((e) => z[0] == e[0] && z[1] == e[1]),
|
||||
const updated = exceptZipItem(
|
||||
exceptZipItem(existing, item),
|
||||
associatedItem,
|
||||
);
|
||||
uploadStatusStore.set("zipItems", updated);
|
||||
return fs.stat(item[0]).then((st) => st.mtime.getTime());
|
||||
};
|
||||
|
||||
const exceptZipItem = (items: ZipItem[], item: ZipItem | undefined) =>
|
||||
item
|
||||
? items.filter((zi) => !(zi[0] == item[0] && zi[1] == item[1]))
|
||||
: items;
|
||||
|
||||
export const clearPendingUploads = () => {
|
||||
uploadStatusStore.clear();
|
||||
clearOpenZipCache();
|
||||
|
||||
@@ -290,11 +290,13 @@ const pendingUploads = () => ipcRenderer.invoke("pendingUploads");
|
||||
const setPendingUploads = (pendingUploads: PendingUploads) =>
|
||||
ipcRenderer.invoke("setPendingUploads", pendingUploads);
|
||||
|
||||
const markUploadedFiles = (paths: PendingUploads["filePaths"]) =>
|
||||
ipcRenderer.invoke("markUploadedFiles", paths);
|
||||
const markUploadedFile = (path: string, associatedPath: string | undefined) =>
|
||||
ipcRenderer.invoke("markUploadedFile", path, associatedPath);
|
||||
|
||||
const markUploadedZipItems = (items: PendingUploads["zipItems"]) =>
|
||||
ipcRenderer.invoke("markUploadedZipItems", items);
|
||||
const markUploadedZipItem = (
|
||||
item: ZipItem,
|
||||
associatedItem: ZipItem | undefined,
|
||||
) => ipcRenderer.invoke("markUploadedZipItem", item, associatedItem);
|
||||
|
||||
const clearPendingUploads = () => ipcRenderer.invoke("clearPendingUploads");
|
||||
|
||||
@@ -411,7 +413,7 @@ contextBridge.exposeInMainWorld("electron", {
|
||||
pathOrZipItemSize,
|
||||
pendingUploads,
|
||||
setPendingUploads,
|
||||
markUploadedFiles,
|
||||
markUploadedZipItems,
|
||||
markUploadedFile,
|
||||
markUploadedZipItem,
|
||||
clearPendingUploads,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user