mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
speed up char import by postponing tag import
This commit is contained in:
@@ -8851,22 +8851,43 @@ export async function processDroppedFiles(files, data = new Map()) {
|
|||||||
'charx',
|
'charx',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const avatarFileNames = [];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const extension = file.name.split('.').pop().toLowerCase();
|
const extension = file.name.split('.').pop().toLowerCase();
|
||||||
if (allowedMimeTypes.some(x => file.type.startsWith(x)) || allowedExtensions.includes(extension)) {
|
if (allowedMimeTypes.some(x => file.type.startsWith(x)) || allowedExtensions.includes(extension)) {
|
||||||
const preservedName = data instanceof Map && data.get(file);
|
const preservedName = data instanceof Map && data.get(file);
|
||||||
await importCharacter(file, preservedName);
|
const avatarFileName = await importCharacter(file, preservedName);
|
||||||
|
if (avatarFileName !== undefined){
|
||||||
|
avatarFileNames.push(avatarFileName);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toastr.warning(t`Unsupported file type: ` + file.name);
|
toastr.warning(t`Unsupported file type: ` + file.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await ImportMultipleCharactersTags(avatarFileNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports tags for the given characters
|
||||||
|
* @param {string[]} avatarFileNames character avatar filenames whose tags are to import
|
||||||
|
*/
|
||||||
|
async function ImportMultipleCharactersTags(avatarFileNames) {
|
||||||
|
await getCharacters();
|
||||||
|
const currentContext = getContext();
|
||||||
|
for (let i = 0; i < avatarFileNames.length; i++) {
|
||||||
|
if (power_user.tag_import_setting !== tag_import_setting.NONE) {
|
||||||
|
const importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileNames[i]);
|
||||||
|
await importTags(importedCharacter);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports a character from a file.
|
* Imports a character from a file.
|
||||||
* @param {File} file File to import
|
* @param {File} file File to import
|
||||||
* @param {string?} preserveFileName Whether to preserve original file name
|
* @param {string?} preserveFileName Whether to preserve original file name
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async function importCharacter(file, preserveFileName = '') {
|
async function importCharacter(file, preserveFileName = '') {
|
||||||
if (is_group_generating || is_send_press) {
|
if (is_group_generating || is_send_press) {
|
||||||
@@ -8909,14 +8930,9 @@ async function importCharacter(file, preserveFileName = '') {
|
|||||||
oldSelectedChar = characters[this_chid].avatar;
|
oldSelectedChar = characters[this_chid].avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
await getCharacters();
|
|
||||||
select_rm_info('char_import', data.file_name, oldSelectedChar);
|
select_rm_info('char_import', data.file_name, oldSelectedChar);
|
||||||
if (power_user.tag_import_setting !== tag_import_setting.NONE) {
|
let avatarFileName = `${data.file_name}.png`;
|
||||||
let currentContext = getContext();
|
return avatarFileName;
|
||||||
let avatarFileName = `${data.file_name}.png`;
|
|
||||||
let importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileName);
|
|
||||||
await importTags(importedCharacter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10795,9 +10811,15 @@ jQuery(async function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const avatarFileNames = [];
|
||||||
for (const file of e.target.files) {
|
for (const file of e.target.files) {
|
||||||
await importCharacter(file);
|
const avatarFileName = await importCharacter(file);
|
||||||
|
if (avatarFileName !== undefined){
|
||||||
|
avatarFileNames.push(avatarFileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await ImportMultipleCharactersTags(avatarFileNames);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#export_button').on('click', function () {
|
$('#export_button').on('click', function () {
|
||||||
|
Reference in New Issue
Block a user