diff --git a/public/script.js b/public/script.js index b57dad454..f602a20ac 100644 --- a/public/script.js +++ b/public/script.js @@ -173,6 +173,7 @@ import { escapeHtml, saveBase64AsFile, uuidv4, + equalsIgnoreCaseAndAccents, } from './scripts/utils.js'; import { debounce_timeout, IGNORE_SYMBOL } from './scripts/constants.js'; @@ -9878,6 +9879,15 @@ export async function renameChat(oldFileName, newName) { renamed_file: `${newName.trim()}.jsonl`, }; + if (body.original_file === body.renamed_file) { + console.debug('Chat rename cancelled, old and new names are the same'); + return; + } + if (equalsIgnoreCaseAndAccents(body.original_file, body.renamed_file)) { + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Chat`); + return; + } + try { showLoader(); const response = await fetch('/api/chats/rename', { diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index cdff9501c..5ddd42422 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -36,7 +36,7 @@ import { textgenerationwebui_presets, textgenerationwebui_settings as textgen_settings, } from './textgen-settings.js'; -import { download, parseJsonFile, waitUntilCondition } from './utils.js'; +import { download, equalsIgnoreCaseAndAccents, parseJsonFile, waitUntilCondition } from './utils.js'; import { t } from './i18n.js'; import { reasoning_templates } from './reasoning.js'; @@ -454,6 +454,9 @@ class PresetManager { async renamePreset(newName) { const oldName = this.getSelectedPresetName(); + if (equalsIgnoreCaseAndAccents(oldName, newName)) { + throw new Error('New name must be different from old name'); + } try { await this.savePreset(newName); await this.deletePreset(oldName); @@ -892,6 +895,10 @@ export async function initPresetManager() { console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled'); return; } + if (equalsIgnoreCaseAndAccents(oldName, newName)) { + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Preset`); + return; + } await presetManager.renamePreset(newName); diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index f0382065e..c1ff586a3 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1,7 +1,7 @@ import { Fuse } from '../lib.js'; import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js'; -import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique } from './utils.js'; +import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique, equalsIgnoreCaseAndAccents } from './utils.js'; import { extension_settings, getContext } from './extensions.js'; import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js'; import { isMobile } from './RossAscends-mods.js'; @@ -3586,6 +3586,10 @@ async function renameWorldInfo(name, data) { console.debug('World info rename cancelled'); return; } + if (equalsIgnoreCaseAndAccents(oldName, newName)) { + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename World Info`); + return; + } const entryPreviouslySelected = selected_world_info.findIndex((e) => e === oldName);