mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Multi-character import
This commit is contained in:
@ -1499,7 +1499,7 @@
|
|||||||
|
|
||||||
<div id="rm_character_import" class="right_menu" style="display: none;">
|
<div id="rm_character_import" class="right_menu" style="display: none;">
|
||||||
<form id="form_import" action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
<form id="form_import" action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
||||||
<input type="file" id="character_import_file" accept=".json, image/png, image/webp" name="avatar">
|
<input multiple type="file" id="character_import_file" accept=".json, image/png, image/webp" name="avatar">
|
||||||
<input id="character_import_file_type" name="file_type" class="text_pole" maxlength="999" size="2" value="" autocomplete="off">
|
<input id="character_import_file_type" name="file_type" class="text_pole" maxlength="999" size="2" value="" autocomplete="off">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3060,8 +3060,8 @@ function select_selected_character(chid) {
|
|||||||
//console.log('select_selected_character() -- starting with input of -- '+chid+' (name:'+characters[chid].name+')');
|
//console.log('select_selected_character() -- starting with input of -- '+chid+' (name:'+characters[chid].name+')');
|
||||||
select_rm_create();
|
select_rm_create();
|
||||||
menu_type = "character_edit";
|
menu_type = "character_edit";
|
||||||
$("#delete_button").css("display", "block");
|
$("#delete_button").css("display", "flex");
|
||||||
$("#export_button").css("display", "block");
|
$("#export_button").css("display", "flex");
|
||||||
setRightTabSelectedClass('rm_button_selected_ch');
|
setRightTabSelectedClass('rm_button_selected_ch');
|
||||||
var display_name = characters[chid].name;
|
var display_name = characters[chid].name;
|
||||||
|
|
||||||
@ -3128,7 +3128,7 @@ function select_rm_create() {
|
|||||||
|
|
||||||
//create text poles
|
//create text poles
|
||||||
$("#rm_button_back").css("display", "inline-block");
|
$("#rm_button_back").css("display", "inline-block");
|
||||||
$("#character_import_button").css("display", "inline-block");
|
$("#character_import_button").css("display", "flex");
|
||||||
$("#character_popup_text_h3").text("Create character");
|
$("#character_popup_text_h3").text("Create character");
|
||||||
$("#character_name_pole").val(create_save_name);
|
$("#character_name_pole").val(create_save_name);
|
||||||
$("#description_textarea").val(create_save_description);
|
$("#description_textarea").val(create_save_description);
|
||||||
@ -4804,31 +4804,33 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
$("#character_import_file").on("change", function (e) {
|
$("#character_import_file").on("change", function (e) {
|
||||||
$("#rm_info_avatar").html("");
|
$("#rm_info_avatar").html("");
|
||||||
var file = e.target.files[0];
|
if (!e.target.files.length) {
|
||||||
//console.log(1);
|
|
||||||
if (!file) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let names = [];
|
||||||
|
|
||||||
|
for (const file of e.target.files) {
|
||||||
var ext = file.name.match(/\.(\w+)$/);
|
var ext = file.name.match(/\.(\w+)$/);
|
||||||
if (
|
if (
|
||||||
!ext ||
|
!ext ||
|
||||||
(ext[1].toLowerCase() != "json" && ext[1].toLowerCase() != "png" && ext[1] != "webp")
|
(ext[1].toLowerCase() != "json" && ext[1].toLowerCase() != "png" && ext[1] != "webp")
|
||||||
) {
|
) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var format = ext[1].toLowerCase();
|
var format = ext[1].toLowerCase();
|
||||||
$("#character_import_file_type").val(format);
|
$("#character_import_file_type").val(format);
|
||||||
//console.log(format);
|
var formData = new FormData();
|
||||||
var formData = new FormData($("#form_import").get(0));
|
formData.append('avatar', file);
|
||||||
|
formData.append('file_type', format);
|
||||||
|
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/importcharacter",
|
url: "/importcharacter",
|
||||||
data: formData,
|
data: formData,
|
||||||
|
async: false,
|
||||||
beforeSend: function () {
|
beforeSend: function () {
|
||||||
//$('#create_button').attr('disabled',true);
|
|
||||||
//$('#create_button').attr('value','Creating...');
|
|
||||||
},
|
},
|
||||||
cache: false,
|
cache: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
@ -4847,8 +4849,10 @@ $(document).ready(function () {
|
|||||||
oldSelectedChar = characters[this_chid].name;
|
oldSelectedChar = characters[this_chid].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
names.push(data.file_name);
|
||||||
|
let nameString = DOMPurify.sanitize(names.join(', '));
|
||||||
await getCharacters();
|
await getCharacters();
|
||||||
select_rm_info(`Character imported<br><h4>${DOMPurify.sanitize(data.file_name)}</h4>`, oldSelectedChar);
|
select_rm_info(`Character imported<br><h4>${nameString}</h4>`, oldSelectedChar);
|
||||||
$("#rm_info_block").transition({ opacity: 1, duration: 1000 });
|
$("#rm_info_block").transition({ opacity: 1, duration: 1000 });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -4856,6 +4860,7 @@ $(document).ready(function () {
|
|||||||
$("#create_button").removeAttr("disabled");
|
$("#create_button").removeAttr("disabled");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$("#export_button").click(function (e) {
|
$("#export_button").click(function (e) {
|
||||||
$('#export_format_popup').toggle();
|
$('#export_format_popup').toggle();
|
||||||
|
@ -1117,6 +1117,13 @@ input[type=search]:focus::-webkit-search-cancel-button {
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form_create_bottom_buttons_block .menu_button
|
||||||
|
{
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
#rm_info_block {
|
#rm_info_block {
|
||||||
display: none;
|
display: none;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -1138,6 +1145,8 @@ input[type=search]:focus::-webkit-search-cancel-button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#rm_info_avatar {
|
#rm_info_avatar {
|
||||||
|
display: flex;
|
||||||
|
column-gap: 10px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
@ -2199,11 +2208,6 @@ h5 {
|
|||||||
column-gap: 15px;
|
column-gap: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#rm_button_group_chats {
|
|
||||||
cursor: pointer;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
#rm_button_group_chats h2 {
|
#rm_button_group_chats h2 {
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
margin-bottom: auto;
|
margin-bottom: auto;
|
||||||
|
Reference in New Issue
Block a user