speed up char import by postponing tag import

c7cbeed9bb1b73ccb011ad2ba5da373837109360

d-ber <davide.bertalero@studenti.unimi.it>

1 files changed, +32 -10Ignore whitespace
public/script.js+32 -10
@@ -8851,22 +8851,43 @@ export async function processDroppedFiles(files, data = new Map()) {
88518851 'charx',
88528852 ];
88538853
8854+ const avatarFileNames = [];
88548855 for (const file of files) {
88558856 const extension = file.name.split('.').pop().toLowerCase();
88568857 if (allowedMimeTypes.some(x => file.type.startsWith(x)) || allowedExtensions.includes(extension)) {
88578858 const preservedName = data instanceof Map && data.get(file);
88588859 const avatarFileName = await importCharacter(file, preservedName);
8860+ if (avatarFileName !== undefined){
8861+ avatarFileNames.push(avatarFileName);
8862+ }
88598863 } else {
88608864 toastr.warning(t`Unsupported file type: ` + file.name);
88618865 }
88628866 }
8867+
8868+ await ImportMultipleCharactersTags(avatarFileNames);
8869+}
8870+
8871+/**
8872+ * Imports tags for the given characters
8873+ * @param {string[]} avatarFileNames character avatar filenames whose tags are to import
8874+ */
8875+async function ImportMultipleCharactersTags(avatarFileNames) {
8876+ await getCharacters();
8877+ const currentContext = getContext();
8878+ for (let i = 0; i < avatarFileNames.length; i++) {
8879+ if (power_user.tag_import_setting !== tag_import_setting.NONE) {
8880+ const importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileNames[i]);
8881+ await importTags(importedCharacter);
8882+ }
8883+ }
88638884}
88648885
88658886/**
88668887 * Imports a character from a file.
88678888 * @param {File} file File to import
88688889 * @param {string?} preserveFileName Whether to preserve original file name
88698890 * @returns {Promise<voidstring>}
88708891 */
88718892async function importCharacter(file, preserveFileName = '') {
88728893 if (is_group_generating || is_send_press) {
@@ -8909,14 +8930,9 @@ async function importCharacter(file, preserveFileName = '') {
89098930 oldSelectedChar = characters[this_chid].avatar;
89108931 }
89118932
8912- await getCharacters();
89138933 select_rm_info('char_import', data.file_name, oldSelectedChar);
8914- if (power_user.tag_import_setting !== tag_import_setting.NONE) {
8934+ let avatarFileName = `${data.file_name}.png`;
8915- let currentContext = getContext();
8935+ return avatarFileName;
8916- let avatarFileName = `${data.file_name}.png`;
8917- let importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileName);
8918- await importTags(importedCharacter);
8919- }
89208936 }
89218937}
89228938
@@ -10795,9 +10811,15 @@ jQuery(async function () {
1079510811 return;
1079610812 }
1079710813
10814+ const avatarFileNames = [];
1079810815 for (const file of e.target.files) {
1079910816 const avatarFileName = await importCharacter(file);
10817+ if (avatarFileName !== undefined){
10818+ avatarFileNames.push(avatarFileName);
10819+ }
1080010820 }
10821+
10822+ await ImportMultipleCharactersTags(avatarFileNames);
1080110823 });
1080210824
1080310825 $('#export_button').on('click', function () {