Export chats as .txt files

This commit is contained in:
RossAscends
2023-05-28 16:42:59 +09:00
parent 79979009f2
commit 6ab9e0f182
5 changed files with 100 additions and 3 deletions

View File

@@ -2363,6 +2363,7 @@
</div>
<div class="flex-container height100pSpaceEvenly">
<div class="renameChatButton fa-solid fa-pen"></div>
<div class="exportChatButton fa-solid fa-file-export"></div>
<div file_name="" class="PastChat_cross fa-solid fa-circle-xmark"></div>
</div>
</div>
@@ -2713,4 +2714,4 @@
</script>
</body>
</html>
</html>

View File

@@ -5795,6 +5795,43 @@ $(document).ready(function () {
}
});
$(document).on("click", ".exportChatButton", async function () {
const filenamefull = $(this).closest('.select_chat_block_wrapper').find('.select_chat_block_filename').text();
const filename = filenamefull.replace('.jsonl', '');
const body = {
is_group: !!selected_group,
avatar_url: characters[this_chid]?.avatar,
file: `${filename}.jsonl`,
exportfilename: `${filename}.txt`,
}
console.log(body);
try {
const response = await fetch('/exportchat', {
method: 'POST',
body: JSON.stringify(body),
headers: getRequestHeaders(),
});
const data = await response.json();
if (!response.ok) {
// display error message
console.log(data.message);
await delay(250);
toastr.error(`Error: ${data.message}`);
return;
} else {
// success, handle response data
console.log(data);
await delay(250);
toastr.success(data.message);
}
} catch (error) {
// display error message
console.log(`An error has occurred: ${error.message}`);
await delay(250);
toastr.error(`Error: ${error.message}`);
}
});
$("#talkativeness_slider").on("input", function () {
if (menu_type == "create") {
create_save_talkativeness = $("#talkativeness_slider").val();

View File

@@ -2618,7 +2618,8 @@ h5 {
flex: 1
}
.renameChatButton {
.renameChatButton,
.exportChatButton {
cursor: pointer;
}
@@ -4467,4 +4468,4 @@ body.waifuMode #avatar_zoom_popup {
overflow-y: auto;
overflow-x: hidden;
}
}
}