fix: pre check

This commit is contained in:
tao.chen
2026-08-14 19:13:17 +08:00
parent 5c5dec9a4a
commit 2e070fae78
3 changed files with 34 additions and 11 deletions
@@ -392,6 +392,7 @@ export default function ScriptsPage() {
scripts={scripts.map((s) => ({
script_type: s.script_type,
script_name: s.script_name,
relative_path: s.relative_path,
}))}
onFormChange={setCreateForm}
onSubmit={handleCreateSubmit}
@@ -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;