This commit is contained in:
Weixuan Fu
2024-03-05 00:35:58 +08:00
parent 1b11dca467
commit 24373a109e
10 changed files with 97 additions and 67 deletions
+5 -4
View File
@@ -233,11 +233,12 @@ def count_files_sync(reqJson):
if not directory_path:
return {"success": False, "error": "Directory path is required"}
path = Path(directory_path)
path = Path(get_my_workflows_dir()) / directory_path
if not path.is_dir():
return {"success": False, "error": "Provided path is not a directory"}
file_count = sum(1 for _ in path.rglob('*') if _.is_file())
file_count = 0
for file in path.rglob('*.json'): # Only consider .json files
if file.is_file():
file_count += 1
return {"success": True, "count": file_count}
+2 -2
View File
@@ -7,13 +7,13 @@ import glob
from threading import Lock
import server
import uuid
from .twoway_sync_folder_service import get_my_workflows_abs_path
from .db_service import get_my_workflows_dir
@server.PromptServer.instance.routes.post('/workspace/file/scan_my_workflows_folder')
async def scan_my_workflows_files(request):
reqJson = await request.json()
path = reqJson['path']
path = get_my_workflows_abs_path(path)
path = os.path.join(get_my_workflows_dir(), path)
recursive = reqJson.get('recursive', False)
metaInfoOnly = reqJson.get('metaInfoOnly', False)
-3
View File
@@ -69,6 +69,3 @@ def move_folder_sync(reqJson):
except Exception as e:
return {"success": False, "error": str(e)}
def get_my_workflows_abs_path(rel_path: str):
myworkflows = get_my_workflows_dir()
return os.path.join(myworkflows, rel_path)
+30 -1
View File
@@ -39,11 +39,13 @@ const RecentFilesDrawer = React.lazy(
);
const GalleryModal = React.lazy(() => import("./gallery/GalleryModal"));
import { IconExternalLink } from "@tabler/icons-react";
import { DRAWER_Z_INDEX } from "./const";
import { DRAWER_Z_INDEX, UPGRADE_TO_2WAY_SYNC_KEY } from "./const";
import ServerEventListener from "./model-manager/hooks/ServerEventListener";
import { v4 } from "uuid";
import { WorkspaceRoute } from "./types/types";
import { useStateRef } from "./customHooks/useStateRef";
import { indexdb } from "./db-tables/indexdb";
import EnableTwowaySyncConfirm from "./settings/EnableTwowaySyncConfirm";
const ModelManagerTopbar = React.lazy(
() => import("./model-manager/topbar/ModelManagerTopbar"),
@@ -187,6 +189,33 @@ export default function App() {
await rewriteAllLocalFiles();
localStorage.setItem("REWRITTEN_ALL_LOCAL_DISK_FILE", "true");
}
indexdb.cache.get(UPGRADE_TO_2WAY_SYNC_KEY).then(async (value) => {
if (value?.value !== "true") {
const myWorkflowsDir =
await userSettingsTable?.getSetting("myWorkflowsDir");
showDialog(
<EnableTwowaySyncConfirm
myWorkflowsDir={myWorkflowsDir ?? "undefined"}
/>,
[
{
label: "I have downloaded all my workflows and ready to enable",
onClick: async () => {
await userSettingsTable?.upsert({ twoWaySync: true });
if (await userSettingsTable?.getSetting("twoWaySync")) {
indexdb.cache.put({
id: UPGRADE_TO_2WAY_SYNC_KEY,
value: "true",
});
location.reload();
}
},
colorScheme: "red",
},
],
);
}
});
};
const subsribeToWsToStopWarning = () => {
+1 -1
View File
@@ -73,7 +73,7 @@ export const AlertDialogProvider: React.FC<{ children: ReactNode }> = ({
isOpen={isOpen}
leastDestructiveRef={cancelRef}
onClose={handleClose}
size={"lg"}
size={"xl"}
>
<DarkMode>
<AlertDialogOverlay>
+1
View File
@@ -3,3 +3,4 @@ export const COMFYSPACE_TRACKING_FIELD_NAME = "workspace_info";
export const COMFYSPACE_AUTH_ENDPOINT = "comfyspace_auth";
export const COMFYSPACE_AUTH_REDIRECT_URL = "http://localhost:8188/";
export const DRAWER_Z_INDEX = 9999999;
export const UPGRADE_TO_2WAY_SYNC_KEY = "upgrade_to_2way_sync";
-7
View File
@@ -57,13 +57,6 @@ export class UserSettingsTable extends TableBase<UserSettings> {
};
}
public async getSettings(): Promise<UserSettings | undefined> {
const settings = await this.get(this.DEFAULT_USER);
return {
...this.defaultSettings,
...settings,
};
}
public async getSetting<K extends keyof UserSettings>(
key: K,
): Promise<UserSettings[K]> {
@@ -0,0 +1,43 @@
import { Button, Heading, Stack } from "@chakra-ui/react";
import { downloadWorkflowsZip } from "../utils/downloadWorkflowsZip";
import { workflowsTable } from "../db-tables/WorkspaceDB";
export default function EnableTwoWaySyncConfirm({
myWorkflowsDir,
}: {
myWorkflowsDir: string;
}) {
return (
<Stack gap={3}>
<Heading size={"md"}>🦄 Upgrade to 2.0 - enable two way sync!</Heading>
<p>Your workflows will be synced to and from path:</p>
<p>
<b>{myWorkflowsDir}</b>
</p>
<p>
You can manually put workflow files into this folder using File Explorer
to sync them with your workspace. You can change this path anytime in
Settings {">"} Workspace Save Directory
</p>
<p>
<b>
Please download all your workflows before enabling two way sync as a
backup!
</b>{" "}
So you can manually import some workflows into your workspace in case
something unexpected happens.
</p>
<Button
colorScheme="teal"
variant={"outline"}
width={"fit-content"}
onClick={async () => {
const workflows = await workflowsTable?.listAll();
downloadWorkflowsZip(workflows ?? []);
}}
>
👉 Download All My Workflows
</Button>
</Stack>
);
}
+1 -1
View File
@@ -159,7 +159,7 @@ export default function SelectMyWorkflowsDir() {
<>
<Box mb={4}>
<Text mb={2} fontWeight={500}>
Workspace Save Directory
My Workflows Save Directory
</Text>
{!isEditDirectory ? (
<Flex>
+14 -48
View File
@@ -1,17 +1,19 @@
import { Button, Checkbox, Stack, Text } from "@chakra-ui/react";
import { Checkbox, Stack, Text } from "@chakra-ui/react";
import { useState, useEffect } from "react";
import { userSettingsTable, workflowsTable } from "../db-tables/WorkspaceDB";
import { userSettingsTable } from "../db-tables/WorkspaceDB";
import { useDialog } from "../components/AlertDialogProvider";
import { downloadWorkflowsZip } from "../utils/downloadWorkflowsZip";
import EnableTwowaySyncConfirm from "./EnableTwowaySyncConfirm";
export default function TwoWaySyncSettings() {
const [checked, setChecked] = useState(false);
const [savingDir, setSavingDir] = useState("");
const { showDialog } = useDialog();
const getTwoWaySync = () => {
userSettingsTable?.getSettings().then((res) => {
setSavingDir(res?.myWorkflowsDir ?? "undefined");
setChecked(!!res?.twoWaySync);
userSettingsTable?.getSetting("myWorkflowsDir").then((res) => {
setSavingDir(res ?? "undefined");
});
userSettingsTable?.getSetting("twoWaySync").then((res) => {
setChecked(res ?? false);
});
};
@@ -28,7 +30,7 @@ export default function TwoWaySyncSettings() {
const myWorkflowsDir =
await userSettingsTable?.getSetting("myWorkflowsDir");
showDialog(
<EnableTwoWaySyncConfirm
<EnableTwowaySyncConfirm
myWorkflowsDir={myWorkflowsDir ?? "undefined"}
/>,
[
@@ -38,6 +40,7 @@ export default function TwoWaySyncSettings() {
await userSettingsTable?.upsert({ twoWaySync: true });
getTwoWaySync();
},
colorScheme: "red",
},
],
);
@@ -46,50 +49,13 @@ export default function TwoWaySyncSettings() {
return (
<Stack>
<Text>
If enabled, your workflows will be synced to and from <b>{savingDir}</b>
<br />
You can manually move files into this folder using File Explorer or
Finder to import them into your workspace.
Only for legacy two way sync users to get back their data. Do not
disable two way sync if you have already enabled it. It may cause some
unexpected issues.
</Text>
<Checkbox isChecked={checked} onChange={onTwoWaySyncChange}>
Enable two way sync (🧪🧪beta)
Enable two way sync
</Checkbox>
</Stack>
);
}
function EnableTwoWaySyncConfirm({
myWorkflowsDir,
}: {
myWorkflowsDir: string;
}) {
return (
<Stack gap={3}>
<p>Your workflows will be synced to and from path:</p>
<p>
<b>{myWorkflowsDir}</b>
</p>
<p>
Please make sure this path is valid. You can change this path anytime in
Settings {">"} Workspace Save Direcotry
</p>
<p>
<b>Please download all your workflows before enabling two way sync!</b>{" "}
So you can manually import some workflows into your my_workflows/
directory on your disk in case something unexpected happens.
</p>
<Button
colorScheme="teal"
variant={"outline"}
width={"fit-content"}
size={"sm"}
onClick={async () => {
const workflows = await workflowsTable?.listAll();
downloadWorkflowsZip(workflows ?? []);
}}
>
Download All My Workflows
</Button>
</Stack>
);
}