From 24373a109e6ea922d09e3ffc3bceedbb67d3f599 Mon Sep 17 00:00:00 2001 From: Weixuan Fu Date: Tue, 5 Mar 2024 00:35:58 +0800 Subject: [PATCH] fix bug --- service/file_sync_service.py | 9 +-- service/scan_my_workflows_folder.py | 4 +- service/twoway_sync_folder_service.py | 3 - ui/src/App.tsx | 31 ++++++++++- ui/src/components/AlertDialogProvider.tsx | 2 +- ui/src/const.ts | 1 + ui/src/db-tables/UserSettingsTable.ts | 7 --- ui/src/settings/EnableTwowaySyncConfirm.tsx | 43 ++++++++++++++ ui/src/settings/SelectMyWorkflowsDir.tsx | 2 +- ui/src/settings/TwoWaySyncSettings.tsx | 62 +++++---------------- 10 files changed, 97 insertions(+), 67 deletions(-) create mode 100644 ui/src/settings/EnableTwowaySyncConfirm.tsx diff --git a/service/file_sync_service.py b/service/file_sync_service.py index a52e3b9..c9a27e7 100644 --- a/service/file_sync_service.py +++ b/service/file_sync_service.py @@ -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} diff --git a/service/scan_my_workflows_folder.py b/service/scan_my_workflows_folder.py index fc8dbe0..9e5b096 100644 --- a/service/scan_my_workflows_folder.py +++ b/service/scan_my_workflows_folder.py @@ -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) diff --git a/service/twoway_sync_folder_service.py b/service/twoway_sync_folder_service.py index bbbb86f..efdc7d0 100644 --- a/service/twoway_sync_folder_service.py +++ b/service/twoway_sync_folder_service.py @@ -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) diff --git a/ui/src/App.tsx b/ui/src/App.tsx index 5a7e493..d27f94a 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -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( + , + [ + { + 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 = () => { diff --git a/ui/src/components/AlertDialogProvider.tsx b/ui/src/components/AlertDialogProvider.tsx index de39b15..c5ef867 100644 --- a/ui/src/components/AlertDialogProvider.tsx +++ b/ui/src/components/AlertDialogProvider.tsx @@ -73,7 +73,7 @@ export const AlertDialogProvider: React.FC<{ children: ReactNode }> = ({ isOpen={isOpen} leastDestructiveRef={cancelRef} onClose={handleClose} - size={"lg"} + size={"xl"} > diff --git a/ui/src/const.ts b/ui/src/const.ts index f0b376b..c2ba8e9 100644 --- a/ui/src/const.ts +++ b/ui/src/const.ts @@ -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"; diff --git a/ui/src/db-tables/UserSettingsTable.ts b/ui/src/db-tables/UserSettingsTable.ts index 885f0b7..8428a90 100644 --- a/ui/src/db-tables/UserSettingsTable.ts +++ b/ui/src/db-tables/UserSettingsTable.ts @@ -57,13 +57,6 @@ export class UserSettingsTable extends TableBase { }; } - public async getSettings(): Promise { - const settings = await this.get(this.DEFAULT_USER); - return { - ...this.defaultSettings, - ...settings, - }; - } public async getSetting( key: K, ): Promise { diff --git a/ui/src/settings/EnableTwowaySyncConfirm.tsx b/ui/src/settings/EnableTwowaySyncConfirm.tsx new file mode 100644 index 0000000..737c9ce --- /dev/null +++ b/ui/src/settings/EnableTwowaySyncConfirm.tsx @@ -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 ( + + 🦄 Upgrade to 2.0 - enable two way sync! +

Your workflows will be synced to and from path:

+

+ {myWorkflowsDir} +

+

+ 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 +

+

+ + Please download all your workflows before enabling two way sync as a + backup! + {" "} + So you can manually import some workflows into your workspace in case + something unexpected happens. +

+ +
+ ); +} diff --git a/ui/src/settings/SelectMyWorkflowsDir.tsx b/ui/src/settings/SelectMyWorkflowsDir.tsx index 8c4b7b4..00c29ae 100644 --- a/ui/src/settings/SelectMyWorkflowsDir.tsx +++ b/ui/src/settings/SelectMyWorkflowsDir.tsx @@ -159,7 +159,7 @@ export default function SelectMyWorkflowsDir() { <> - Workspace Save Directory + My Workflows Save Directory {!isEditDirectory ? ( diff --git a/ui/src/settings/TwoWaySyncSettings.tsx b/ui/src/settings/TwoWaySyncSettings.tsx index ff70431..3d9c186 100644 --- a/ui/src/settings/TwoWaySyncSettings.tsx +++ b/ui/src/settings/TwoWaySyncSettings.tsx @@ -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( - , [ @@ -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 ( - If enabled, your workflows will be synced to and from {savingDir} -
- 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.
- Enable two way sync (🧪🧪beta) + Enable two way sync
); } - -function EnableTwoWaySyncConfirm({ - myWorkflowsDir, -}: { - myWorkflowsDir: string; -}) { - return ( - -

Your workflows will be synced to and from path:

-

- {myWorkflowsDir} -

-

- Please make sure this path is valid. You can change this path anytime in - Settings {">"} Workspace Save Direcotry -

-

- Please download all your workflows before enabling two way sync!{" "} - So you can manually import some workflows into your my_workflows/ - directory on your disk in case something unexpected happens. -

- -
- ); -}