fix: pre check
This commit is contained in:
@@ -758,12 +758,19 @@ export const useScriptWorkspaceStore = create<State>((set, get) => {
|
||||
const normalizedName = requestedName.toLocaleLowerCase().endsWith(suffix)
|
||||
? requestedName
|
||||
: `${requestedName}${suffix}`;
|
||||
const duplicate = get().scripts.some(
|
||||
(script) =>
|
||||
script.script_type === form.scriptType
|
||||
&& script.script_name.toLocaleLowerCase()
|
||||
=== normalizedName.toLocaleLowerCase(),
|
||||
);
|
||||
const duplicate = get().scripts.some((script) => {
|
||||
if (script.script_type !== form.scriptType) return false;
|
||||
if (script.script_name.toLocaleLowerCase()
|
||||
!== normalizedName.toLocaleLowerCase()) return false;
|
||||
// Same name in a different subdirectory is allowed: mirror the
|
||||
// backend name_clash check, which JOINs StorageObjects and scopes
|
||||
// by relative_path.
|
||||
const existingUserPath = ownedScriptPath(script);
|
||||
const existingParent = existingUserPath.includes("/")
|
||||
? existingUserPath.slice(0, existingUserPath.lastIndexOf("/"))
|
||||
: "";
|
||||
return existingParent === form.parentPath;
|
||||
});
|
||||
if (duplicate) {
|
||||
pushToast("error", `${normalizedName} 已存在,请更换名称`);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user