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 template = await renderExtensionTemplateAsync(MODULE_NAME, 'profile', { profile: profileForDisplay });
const checkName = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n);
const suggestedName = getUniqueName(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), checkName);
const isNameTaken = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n);
const suggestedName = getUniqueName(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), isNameTaken);
const name = forceName ?? await callGenericPopup(template, POPUP_TYPE.INPUT, suggestedName, { rows: 2 });
if (!name) {
return null;
}
if (isNameTaken(name)) {
toastr.error('A profile with the same name already exists.');
return null;
}
profile.name = name;
return profile;
}