mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	#1250 Fix multiple card import tags
This commit is contained in:
		| @@ -6970,7 +6970,7 @@ function connectAPISlash(_, text) { | |||||||
|     toastr.info(`API set to ${text}, trying to connect..`); |     toastr.info(`API set to ${text}, trying to connect..`); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function processDroppedFiles(files) { | export async function processDroppedFiles(files) { | ||||||
|     const allowedMimeTypes = [ |     const allowedMimeTypes = [ | ||||||
|         'application/json', |         'application/json', | ||||||
|         'image/png', |         'image/png', | ||||||
| @@ -6978,14 +6978,14 @@ export function processDroppedFiles(files) { | |||||||
|  |  | ||||||
|     for (const file of files) { |     for (const file of files) { | ||||||
|         if (allowedMimeTypes.includes(file.type)) { |         if (allowedMimeTypes.includes(file.type)) { | ||||||
|             importCharacter(file); |             await importCharacter(file); | ||||||
|         } else { |         } else { | ||||||
|             toastr.warning('Unsupported file type: ' + file.name); |             toastr.warning('Unsupported file type: ' + file.name); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function importCharacter(file) { | async function importCharacter(file) { | ||||||
|     const ext = file.name.match(/\.(\w+)$/); |     const ext = file.name.match(/\.(\w+)$/); | ||||||
|     if ( |     if ( | ||||||
|         !ext || |         !ext || | ||||||
| @@ -7000,44 +7000,38 @@ function importCharacter(file) { | |||||||
|     formData.append('avatar', file); |     formData.append('avatar', file); | ||||||
|     formData.append('file_type', format); |     formData.append('file_type', format); | ||||||
|  |  | ||||||
|     jQuery.ajax({ |     const data = await jQuery.ajax({ | ||||||
|         type: "POST", |         type: "POST", | ||||||
|         url: "/importcharacter", |         url: "/importcharacter", | ||||||
|         data: formData, |         data: formData, | ||||||
|         async: false, |         async: true, | ||||||
|         beforeSend: function () { |  | ||||||
|         }, |  | ||||||
|         cache: false, |         cache: false, | ||||||
|         contentType: false, |         contentType: false, | ||||||
|         processData: false, |         processData: false, | ||||||
|         success: async function (data) { |  | ||||||
|             if (data.error) { |  | ||||||
|                 toastr.error('The file is likely invalid or corrupted.', 'Could not import character'); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (data.file_name !== undefined) { |  | ||||||
|                 $('#character_search_bar').val('').trigger('input'); |  | ||||||
|  |  | ||||||
|                 let oldSelectedChar = null; |  | ||||||
|                 if (this_chid != undefined && this_chid != "invalid-safety-id") { |  | ||||||
|                     oldSelectedChar = characters[this_chid].avatar; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 await getCharacters(); |  | ||||||
|                 select_rm_info(`char_import`, data.file_name, oldSelectedChar); |  | ||||||
|                 if (power_user.import_card_tags) { |  | ||||||
|                     let currentContext = getContext(); |  | ||||||
|                     let avatarFileName = `${data.file_name}.png`; |  | ||||||
|                     let importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileName); |  | ||||||
|                     await importTags(importedCharacter); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         }, |  | ||||||
|         error: function (jqXHR, exception) { |  | ||||||
|             $("#create_button").removeAttr("disabled"); |  | ||||||
|         }, |  | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     if (data.error) { | ||||||
|  |         toastr.error('The file is likely invalid or corrupted.', 'Could not import character'); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (data.file_name !== undefined) { | ||||||
|  |         $('#character_search_bar').val('').trigger('input'); | ||||||
|  |  | ||||||
|  |         let oldSelectedChar = null; | ||||||
|  |         if (this_chid != undefined && this_chid != "invalid-safety-id") { | ||||||
|  |             oldSelectedChar = characters[this_chid].avatar; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         await getCharacters(); | ||||||
|  |         select_rm_info(`char_import`, data.file_name, oldSelectedChar); | ||||||
|  |         if (power_user.import_card_tags) { | ||||||
|  |             let currentContext = getContext(); | ||||||
|  |             let avatarFileName = `${data.file_name}.png`; | ||||||
|  |             let importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileName); | ||||||
|  |             await importTags(importedCharacter); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function importFromURL(items, files) { | async function importFromURL(items, files) { | ||||||
| @@ -8966,7 +8960,7 @@ jQuery(async function () { | |||||||
|  |  | ||||||
|         switch (customContentType) { |         switch (customContentType) { | ||||||
|             case 'character': |             case 'character': | ||||||
|                 processDroppedFiles([file]); |                 await processDroppedFiles([file]); | ||||||
|                 break; |                 break; | ||||||
|             case 'lorebook': |             case 'lorebook': | ||||||
|                 await importWorldInfo(file); |                 await importWorldInfo(file); | ||||||
| @@ -9029,7 +9023,7 @@ jQuery(async function () { | |||||||
|         if (!files.length) { |         if (!files.length) { | ||||||
|             await importFromURL(event.originalEvent.dataTransfer.items, files); |             await importFromURL(event.originalEvent.dataTransfer.items, files); | ||||||
|         } |         } | ||||||
|         processDroppedFiles(files); |         await processDroppedFiles(files); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user