From 24b003c9ff0735ef0348eaf5e687294136928906 Mon Sep 17 00:00:00 2001 From: Aller05 <421361608@qq.com> Date: Wed, 6 Mar 2024 03:08:25 +0000 Subject: [PATCH] fix: compatible with windows file path separators --- ui/src/settings/SelectMyWorkflowsDir.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ui/src/settings/SelectMyWorkflowsDir.tsx b/ui/src/settings/SelectMyWorkflowsDir.tsx index 00c29ae..29716a9 100644 --- a/ui/src/settings/SelectMyWorkflowsDir.tsx +++ b/ui/src/settings/SelectMyWorkflowsDir.tsx @@ -25,6 +25,8 @@ import { userSettingsTable } from "../db-tables/WorkspaceDB"; import { validateOrSaveAllJsonFileMyWorkflows } from "../utils"; export default function SelectMyWorkflowsDir() { + const isWindows = navigator.userAgent.indexOf("Window") > 0; + const slash = isWindows ? "\\" : "/"; const [isManualEntry, setIsManualEntry] = useState(false); const [isEditDirectory, setIsEditDirectory] = useState(false); const [subdirectoryList, setSubdirectoryList] = useState([]); @@ -69,7 +71,7 @@ export default function SelectMyWorkflowsDir() { setIsEditDirectory(true); setDirPathList( (currentDirectory && - currentDirectory.split(/[\\|\/]/).filter((p) => !!p)) || + currentDirectory.split(slash).filter((p) => !!p)) || [], ); } @@ -96,7 +98,8 @@ export default function SelectMyWorkflowsDir() { return; } } - const newPath = manualEntry ?? `/${dirPathList.join("/")}`; + const newPath = + manualEntry ?? `${isWindows ? "" : slash}${dirPathList.join(slash)}`; await userSettingsTable?.upsert({ myWorkflowsDir: newPath, }); @@ -111,22 +114,26 @@ export default function SelectMyWorkflowsDir() { const onReset = async () => { const { dirPath, dirList } = await getDir(""); - setDirPathList(dirPath.split("/").filter((p: string) => !!p)); + setDirPathList(dirPath.split(slash).filter((p: string) => !!p)); setSubdirectoryList(dirList); }; const onDirJump = async (index: number, nextDir?: string) => { let nextDirPath = ""; if (index === -1 && nextDir) { - nextDirPath = `/${dirPathList.concat([nextDir]).join("/")}`; + nextDirPath = `${isWindows ? "" : slash}${dirPathList.concat([nextDir]).join(slash)}`; } else { - nextDirPath = `/${dirPathList.slice(0, index + 1).join("/")}`; + nextDirPath = `${isWindows ? "" : slash}${dirPathList.slice(0, index + 1).join(slash)}`; } const { isError = false, dirList = [] } = await getDir(nextDirPath); if (!isError) { setSubdirectoryList(dirList); - setDirPathList(nextDirPath.slice(1)?.split("/")); + setDirPathList( + isWindows + ? nextDirPath.split(slash) + : nextDirPath.slice(1)?.split(slash), + ); } }; const enterFolderAddressComp = ( @@ -214,7 +221,7 @@ export default function SelectMyWorkflowsDir() { {dirPathList.map((dir, index) => ( <> - / + {index > 0 && slash}