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)

f302c67b955b479988df1ace5a600ba81bcabfc8

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +23 -2Ignore whitespace
public/script.js+10 -0
@@ -173,6 +173,7 @@ import {
173 escapeHtml,173 escapeHtml,
174 saveBase64AsFile,174 saveBase64AsFile,
175 uuidv4,175 uuidv4,
176 equalsIgnoreCaseAndAccents,
176} from './scripts/utils.js';177} from './scripts/utils.js';
177import { debounce_timeout, IGNORE_SYMBOL } from './scripts/constants.js';178import { debounce_timeout, IGNORE_SYMBOL } from './scripts/constants.js';
178179
@@ -9878,6 +9879,15 @@ export async function renameChat(oldFileName, newName) {
9878 renamed_file: `${newName.trim()}.jsonl`,9879 renamed_file: `${newName.trim()}.jsonl`,
9879 };9880 };
98809881
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 try {9891 try {
9882 showLoader();9892 showLoader();
9883 const response = await fetch('/api/chats/rename', {9893 const response = await fetch('/api/chats/rename', {
public/scripts/preset-manager.js+8 -1
@@ -36,7 +36,7 @@ import {
36 textgenerationwebui_presets,36 textgenerationwebui_presets,
37 textgenerationwebui_settings as textgen_settings,37 textgenerationwebui_settings as textgen_settings,
38} from './textgen-settings.js';38} from './textgen-settings.js';
39import { download, parseJsonFile, waitUntilCondition } from './utils.js';39import { download, equalsIgnoreCaseAndAccents, parseJsonFile, waitUntilCondition } from './utils.js';
40import { t } from './i18n.js';40import { t } from './i18n.js';
41import { reasoning_templates } from './reasoning.js';41import { reasoning_templates } from './reasoning.js';
4242
@@ -454,6 +454,9 @@ class PresetManager {
454454
455 async renamePreset(newName) {455 async renamePreset(newName) {
456 const oldName = this.getSelectedPresetName();456 const oldName = this.getSelectedPresetName();
457 if (equalsIgnoreCaseAndAccents(oldName, newName)) {
458 throw new Error('New name must be different from old name');
459 }
457 try {460 try {
458 await this.savePreset(newName);461 await this.savePreset(newName);
459 await this.deletePreset(oldName);462 await this.deletePreset(oldName);
@@ -892,6 +895,10 @@ export async function initPresetManager() {
892 console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled');895 console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled');
893 return;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 }
895902
896 await presetManager.renamePreset(newName);903 await presetManager.renamePreset(newName);
897904
public/scripts/world-info.js+5 -1
@@ -1,7 +1,7 @@
1import { Fuse } from '../lib.js';1import { Fuse } from '../lib.js';
22
3import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js';3import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js';
4import { 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';4import { 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';
5import { extension_settings, getContext } from './extensions.js';5import { extension_settings, getContext } from './extensions.js';
6import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js';6import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js';
7import { isMobile } from './RossAscends-mods.js';7import { isMobile } from './RossAscends-mods.js';
@@ -3586,6 +3586,10 @@ async function renameWorldInfo(name, data) {
3586 console.debug('World info rename cancelled');3586 console.debug('World info rename cancelled');
3587 return;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 }
35893593
3590 const entryPreviouslySelected = selected_world_info.findIndex((e) => e === oldName);3594 const entryPreviouslySelected = selected_world_info.findIndex((e) => e === oldName);
35913595