mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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)
This commit is contained in:
@ -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', {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user