Require unique names for profiles

This commit is contained in:
Cohee 2024-09-07 21:21:46 +03:00
parent 827fce4542
commit 739d0c95c3
1 changed files with 7 additions and 2 deletions

View File

@ -147,14 +147,19 @@ async function createConnectionProfile(forceName = null) {
const profileForDisplay = makeFancyProfile(profile); const profileForDisplay = makeFancyProfile(profile);
const template = await renderExtensionTemplateAsync(MODULE_NAME, 'profile', { profile: profileForDisplay }); const template = await renderExtensionTemplateAsync(MODULE_NAME, 'profile', { profile: profileForDisplay });
const checkName = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n); const isNameTaken = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n);
const suggestedName = getUniqueName(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), checkName); const suggestedName = getUniqueName(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), isNameTaken);
const name = forceName ?? await callGenericPopup(template, POPUP_TYPE.INPUT, suggestedName, { rows: 2 }); const name = forceName ?? await callGenericPopup(template, POPUP_TYPE.INPUT, suggestedName, { rows: 2 });
if (!name) { if (!name) {
return null; return null;
} }
if (isNameTaken(name)) {
toastr.error('A profile with the same name already exists.');
return null;
}
profile.name = name; profile.name = name;
return profile; return profile;
} }