Added in export of world info folders

This commit is contained in:
ebolam
2022-08-29 09:25:01 -04:00
parent b64fa67b4b
commit 6a117ba84c
3 changed files with 45 additions and 7 deletions

View File

@@ -7310,6 +7310,24 @@ def UI_2_create_world_info_folder(data):
def UI_2_delete_world_info(uid):
koboldai_vars.worldinfo_v2.delete(int(uid))
#==================================================================#
# Event triggered when user exports world info folder
#==================================================================#
@app.route('/export_world_info_folder')
def UI_2_export_world_info_folder():
if 'folder' in request.args:
data = koboldai_vars.worldinfo_v2.to_json(folder=request.args['folder'])
folder = request.args['folder']
else:
data = koboldai_vars.worldinfo_v2.to_json()
folder = koboldai_vars.story_name
return Response(
data,
mimetype="application/json",
headers={"Content-disposition":
"attachment; filename={}_world_info.json".format(folder)})
#==================================================================#
# Event triggered when user edits phrase biases
#==================================================================#

View File

@@ -1355,11 +1355,17 @@ class KoboldWorldInfo(object):
for uid in self.world_info:
self.socketio.emit("world_info_entry", self.world_info[uid], broadcast=True, room="UI_2")
def to_json(self):
return {
"folders": {x: self.world_info_folder[x] for x in self.world_info_folder},
"entries": self.world_info
}
def to_json(self, folder=None):
if folder is None:
return {
"folders": {x: self.world_info_folder[x] for x in self.world_info_folder},
"entries": self.world_info
}
else:
return {
"folders": {x: self.world_info_folder[x] for x in self.world_info_folder if x == folder},
"entries": {x: self.world_info[x] for x in self.world_info if self.world_info[x]['folder'] == folder}
}
def load_json(self, data):
self.world_info = {int(x): data['entries'][x] for x in data['entries']}

View File

@@ -1506,7 +1506,18 @@ function world_info_folder(data) {
}
}
title.append(title_text);
//create download button
download = document.createElement("span");
download.classList.add("material-icons-outlined");
download.setAttribute("folder", folder_name);
download.textContent = "file_download";
download.onclick = function () {
console.log('export_world_info_folder?folder='+this.getAttribute("folder"));
document.getElementById('download_iframe').src = 'export_world_info_folder?folder='+this.getAttribute("folder");
};
title.append(download);
folder.append(title);
//create add button
new_icon = document.createElement("span");
new_icon.classList.add("wi_add_button");
@@ -2049,7 +2060,7 @@ function update_context(data) {
$(".context-block").remove();
for (const entry of data) {
console.log(entry);
//console.log(entry);
let contextClass = "context-" + ({
soft_prompt: "sp",
prompt: "prompt",
@@ -2310,6 +2321,8 @@ function find_wi_container(e) {
while (true) {
if (e.parentElement == document) {
return e;
} else if (e.classList.contains('WI_Folder')) {
return e;
} else if (e.tagName == 'H2') {
return e.parentElement;
} else if (typeof e.id == 'undefined') {
@@ -2330,6 +2343,7 @@ function dragEnter(e) {
function dragOver(e) {
e.preventDefault();
//console.log(e.target);
element = find_wi_container(e.target);
element.classList.add('drag-over');
}
@@ -2354,7 +2368,7 @@ function drop(e) {
//check if we're droping on a folder, and then append it to the folder
if (element.children[0].tagName == "H2") {
if (element.classList.contains('WI_Folder')) {
//element.append(draggable);
socket.emit("wi_set_folder", {'dragged_id': dragged_id, 'folder': drop_id});
} else {