mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Add time or something i forgot what this was
This commit is contained in:
53
aiserver.py
53
aiserver.py
@@ -7290,34 +7290,47 @@ def UI_2_load_model(data):
|
|||||||
def UI_2_load_story_list(data):
|
def UI_2_load_story_list(data):
|
||||||
file_popup("Select Story to Load", "./stories", "load_story", upload=True, jailed=True, folder_only=False, renameable=True,
|
file_popup("Select Story to Load", "./stories", "load_story", upload=True, jailed=True, folder_only=False, renameable=True,
|
||||||
deleteable=True, show_breadcrumbs=True, item_check=valid_story,
|
deleteable=True, show_breadcrumbs=True, item_check=valid_story,
|
||||||
valid_only=True, hide_extention=True, extra_parameter_function=get_story_length,
|
valid_only=True, hide_extention=True, extra_parameter_function=get_story_listing_data,
|
||||||
column_names=['Story Name', 'Action Count'], show_filename=False,
|
column_names=['Story Name', 'Action Count', 'Last Loaded'], show_filename=False,
|
||||||
column_widths=['auto', '100px'], advanced_sort=story_sort,
|
column_widths=['auto', '100px', '150px'], advanced_sort=story_sort,
|
||||||
sort="Modified", desc=True)
|
sort="Modified", desc=True)
|
||||||
|
|
||||||
def get_story_length(item_full_path, item, valid_selection):
|
def get_story_listing_data(item_full_path, item, valid_selection):
|
||||||
|
title = ""
|
||||||
|
action_count = -1
|
||||||
|
last_loaded = ""
|
||||||
|
|
||||||
if not valid_selection:
|
if not valid_selection:
|
||||||
return ["", ""]
|
return [title, action_count, last_loaded]
|
||||||
|
|
||||||
with open(item_full_path, "r") as f:
|
with open(item_full_path, "r") as f:
|
||||||
js = json.load(f)
|
js = json.load(f)
|
||||||
title = js['story_name'] if 'story_name' in js else ".".join(item.split(".")[:-1])
|
|
||||||
if 'file_version' not in js:
|
title = js['story_name'] if 'story_name' in js else ".".join(item.split(".")[:-1])
|
||||||
return [title, len(js['actions'])]
|
action_count = len(js["actions"])
|
||||||
if js['file_version'] == 1:
|
|
||||||
return [title, len(js['actions'])]
|
if title in koboldai_vars._system_settings.story_loads:
|
||||||
return [title, 0 if js['actions']['action_count'] == -1 else js['actions']['action_count'] ]
|
timestamp = int(time.mktime(time.strptime(koboldai_vars._system_settings.story_loads[title], "%m/%d/%Y, %H:%M:%S")))
|
||||||
|
last_loaded = f"DATE:{timestamp}"
|
||||||
|
|
||||||
|
if js.get("file_version", 1) == 1:
|
||||||
|
return [title, action_count, last_loaded]
|
||||||
|
|
||||||
|
action_count = 0 if js['actions']['action_count'] == -1 else js['actions']['action_count']
|
||||||
|
|
||||||
|
return [title, action_count, last_loaded]
|
||||||
|
|
||||||
|
|
||||||
def valid_story(file):
|
def valid_story(file):
|
||||||
if file.endswith(".json"):
|
if file.endswith(".json"):
|
||||||
with open(file, "r") as f:
|
with open(file, "r") as f:
|
||||||
try:
|
try:
|
||||||
js = json.load(f)
|
js = json.load(f)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return 'actions' in js
|
return 'actions' in js
|
||||||
|
|
||||||
def story_sort(base_path, desc=False):
|
def story_sort(base_path, desc=False):
|
||||||
files = {}
|
files = {}
|
||||||
|
@@ -821,14 +821,30 @@ function popup_items(data) {
|
|||||||
tr.append(popup_item);
|
tr.append(popup_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let dataIndex = -1;
|
||||||
for (extra_data of item[4]) {
|
for (extra_data of item[4]) {
|
||||||
td = document.createElement("span");
|
td = document.createElement("span");
|
||||||
td.style = "grid-area: p"+i+";";
|
td.style = "grid-area: p"+i+";";
|
||||||
i+=1;
|
i+=1;
|
||||||
|
dataIndex++;
|
||||||
td.id = item[1];
|
td.id = item[1];
|
||||||
td.setAttribute("folder", item[0]);
|
td.setAttribute("folder", item[0]);
|
||||||
td.setAttribute("valid", item[3]);
|
td.setAttribute("valid", item[3]);
|
||||||
td.textContent = extra_data;
|
|
||||||
|
// HACK: We should probably not use an index-based approach to check this...
|
||||||
|
if (dataIndex === 2 && extra_data.startsWith("DATE:")) {
|
||||||
|
let timestamp = parseInt(extra_data.replace("DATE:", ""));
|
||||||
|
|
||||||
|
// When sorting by date, we don't want to sort alphabetically!
|
||||||
|
td.setAttribute("sort-value", timestamp);
|
||||||
|
|
||||||
|
// Date expects unix timestamps to be in milligilliaseconds or something
|
||||||
|
const date = new Date(timestamp * 1000)
|
||||||
|
td.textContent = date.toLocaleString();
|
||||||
|
} else {
|
||||||
|
td.textContent = extra_data;
|
||||||
|
}
|
||||||
|
|
||||||
td.onclick = function () {
|
td.onclick = function () {
|
||||||
var accept = document.getElementById("popup_accept");
|
var accept = document.getElementById("popup_accept");
|
||||||
if (this.getAttribute("valid") == "true") {
|
if (this.getAttribute("valid") == "true") {
|
||||||
|
Reference in New Issue
Block a user