Merge pull request #3827 from SillyTavern/fix/wi-rename-same-name Prevent similarily-ish world info, preset and chat file renames (preventing data loss on on case-insensitive systems)
Signed| @@ -173,6 +173,7 @@ import { | ||
| 173 | 173 | escapeHtml, |
| 174 | 174 | saveBase64AsFile, |
| 175 | 175 | uuidv4, |
| 176 | + equalsIgnoreCaseAndAccents, | |
| 176 | 177 | } from './scripts/utils.js'; |
| 177 | 178 | import { debounce_timeout, IGNORE_SYMBOL } from './scripts/constants.js'; |
| 178 | 179 | |
| @@ -9878,6 +9879,15 @@ export async function renameChat(oldFileName, newName) { | ||
| 9878 | 9879 | renamed_file: `${newName.trim()}.jsonl`, |
| 9879 | 9880 | }; |
| 9880 | 9881 | |
| 9882 | + if (body.original_file === body.renamed_file) { | |
| 9883 | + console.debug('Chat rename cancelled, old and new names are the same'); | |
| 9884 | + return; | |
| 9885 | + } | |
| 9886 | + if (equalsIgnoreCaseAndAccents(body.original_file, body.renamed_file)) { | |
| 9887 | + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Chat`); | |
| 9888 | + return; | |
| 9889 | + } | |
| 9890 | + | |
| 9881 | 9891 | try { |
| 9882 | 9892 | showLoader(); |
| 9883 | 9893 | const response = await fetch('/api/chats/rename', { |
| @@ -36,7 +36,7 @@ import { | ||
| 36 | 36 | textgenerationwebui_presets, |
| 37 | 37 | textgenerationwebui_settings as textgen_settings, |
| 38 | 38 | } from './textgen-settings.js'; |
| 39 | 39 | import { download, equalsIgnoreCaseAndAccents, parseJsonFile, waitUntilCondition } from './utils.js'; |
| 40 | 40 | import { t } from './i18n.js'; |
| 41 | 41 | import { reasoning_templates } from './reasoning.js'; |
| 42 | 42 | |
| @@ -454,6 +454,9 @@ class PresetManager { | ||
| 454 | 454 | |
| 455 | 455 | async renamePreset(newName) { |
| 456 | 456 | const oldName = this.getSelectedPresetName(); |
| 457 | + if (equalsIgnoreCaseAndAccents(oldName, newName)) { | |
| 458 | + throw new Error('New name must be different from old name'); | |
| 459 | + } | |
| 457 | 460 | try { |
| 458 | 461 | await this.savePreset(newName); |
| 459 | 462 | await this.deletePreset(oldName); |
| @@ -892,6 +895,10 @@ export async function initPresetManager() { | ||
| 892 | 895 | console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled'); |
| 893 | 896 | return; |
| 894 | 897 | } |
| 898 | + if (equalsIgnoreCaseAndAccents(oldName, newName)) { | |
| 899 | + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Preset`); | |
| 900 | + return; | |
| 901 | + } | |
| 895 | 902 | |
| 896 | 903 | await presetManager.renamePreset(newName); |
| 897 | 904 | |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import { Fuse } from '../lib.js'; |
| 2 | 2 | |
| 3 | 3 | import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js'; |
| 4 | 4 | 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'; |
| 5 | 5 | import { extension_settings, getContext } from './extensions.js'; |
| 6 | 6 | import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js'; |
| 7 | 7 | import { isMobile } from './RossAscends-mods.js'; |
| @@ -3586,6 +3586,10 @@ async function renameWorldInfo(name, data) { | ||
| 3586 | 3586 | console.debug('World info rename cancelled'); |
| 3587 | 3587 | return; |
| 3588 | 3588 | } |
| 3589 | + if (equalsIgnoreCaseAndAccents(oldName, newName)) { | |
| 3590 | + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename World Info`); | |
| 3591 | + return; | |
| 3592 | + } | |
| 3589 | 3593 | |
| 3590 | 3594 | const entryPreviouslySelected = selected_world_info.findIndex((e) => e === oldName); |
| 3591 | 3595 | |