Added folder browser for softprompts and userscripts
This commit is contained in:
parent
97e0df45d7
commit
813540fe9b
35
aiserver.py
35
aiserver.py
|
@ -6070,36 +6070,57 @@ def send_debug():
|
|||
|
||||
emit('from_server', {'cmd': 'debug_info', 'data': debug_info}, broadcast=True)
|
||||
|
||||
#==================================================================#
|
||||
# Load file browser for soft prompts
|
||||
#==================================================================#
|
||||
@socketio.on('show_folder_soft_prompt')
|
||||
def show_folder_soft_prompt(data):
|
||||
file_popup("Load Softprompt", "./softprompts", "", renameable=True, folder_only=False, editable=False, deleteable=True, jailed=True, item_check=None)
|
||||
|
||||
#==================================================================#
|
||||
# Load file browser for user scripts
|
||||
#==================================================================#
|
||||
@socketio.on('show_folder_usersripts')
|
||||
def show_folder_usersripts(data):
|
||||
file_popup("Load Softprompt", "./userscripts", "", renameable=True, folder_only=False, editable=False, deleteable=True, jailed=True, item_check=None)
|
||||
|
||||
|
||||
|
||||
#==================================================================#
|
||||
# File Popup options
|
||||
#==================================================================#
|
||||
@app.route("/popup_test")
|
||||
def popup_test():
|
||||
file_popup("Test Popup", "./", "return_event_name", renameable=True, folder_only=False, editable=True, deleteable=True, jailed=False, item_check=check_if_dir_is_model)
|
||||
return "ok"
|
||||
|
||||
@socketio.on('upload_file')
|
||||
def upload_file(data):
|
||||
print("upload_file {}".format(data['filename']))
|
||||
print('current_folder' in session)
|
||||
print('popup_jailed_dir' not in session)
|
||||
print(session['popup_jailed_dir'])
|
||||
print(session['current_folder'])
|
||||
if 'current_folder' in session:
|
||||
path = os.path.join(session['current_folder'], data['filename'])
|
||||
print("Want to save to {}".format(path))
|
||||
path = os.path.abspath(os.path.join(session['current_folder'], data['filename']).replace("\\", "/")).replace("\\", "/")
|
||||
print(path)
|
||||
print(os.path.exists(path))
|
||||
if 'popup_jailed_dir' not in session:
|
||||
print("Someone is trying to upload a file to your server. Blocked.")
|
||||
elif session['popup_jailed_dir'] is None:
|
||||
if os.path.exists(path):
|
||||
print("popup error")
|
||||
emit("error_popup", "The file already exists. Please delete it or rename the file before uploading", room="UI_2");
|
||||
else:
|
||||
with open(path, "wb") as f:
|
||||
f.write(data['data'])
|
||||
get_files_folders(session['current_folder'])
|
||||
print("saved")
|
||||
elif session['popup_jailed_dir'] in session['current_folder']:
|
||||
if os.path.exists(path):
|
||||
print("popup error")
|
||||
emit("error_popup", "The file already exists. Please delete it or rename the file before uploading", room="UI_2");
|
||||
else:
|
||||
with open(path, "wb") as f:
|
||||
f.write(data['data'])
|
||||
get_files_folders(session['current_folder'])
|
||||
print("saved")
|
||||
|
||||
@socketio.on('popup_change_folder')
|
||||
def popup_change_folder(data):
|
||||
|
@ -6231,7 +6252,7 @@ def file_popup(popup_title, starting_folder, return_event, upload=True, jailed=T
|
|||
|
||||
def get_files_folders(starting_folder):
|
||||
import stat
|
||||
session['current_folder'] = starting_folder
|
||||
session['current_folder'] = os.path.abspath(starting_folder).replace("\\", "/")
|
||||
item_check = session['popup_item_check']
|
||||
show_breadcrumbs = session['popup_show_breadcrumbs']
|
||||
show_hidden = session['popup_show_hidden']
|
||||
|
|
|
@ -3152,6 +3152,8 @@ var popup_editable = false;
|
|||
var popup_renameable = false;
|
||||
|
||||
function load_popup(data) {
|
||||
document.getElementById('spcontainer').classList.add('hidden');
|
||||
document.getElementById('uscontainer').classList.add('hidden');
|
||||
popup_deleteable = data.deleteable;
|
||||
popup_editable = data.editable;
|
||||
popup_renameable = data.renameable;
|
||||
|
@ -3197,9 +3199,9 @@ function load_popup(data) {
|
|||
|
||||
//adjust accept button
|
||||
if (data.call_back == "") {
|
||||
document.getElementById("popup_load_cancel").classList.add("hidden");
|
||||
document.getElementById("popup_accept").classList.add("hidden");
|
||||
} else {
|
||||
document.getElementById("popup_load_cancel").classList.remove("hidden");
|
||||
document.getElementById("popup_accept").classList.remove("hidden");
|
||||
var accept = document.getElementById("popup_accept");
|
||||
accept.classList.add("disabled");
|
||||
accept.setAttribute("emit", data.call_back);
|
||||
|
|
|
@ -339,7 +339,7 @@
|
|||
<div class="popupcontainer hidden" id="spcontainer">
|
||||
<div id="sppopup">
|
||||
<div class="popuptitlebar">
|
||||
<div class="popuptitletext">Select A Soft Prompt To Use</div>
|
||||
<div class="popuptitletext">Select A Soft Prompt To Use</div><span class="oi" style="color: white;" data-glyph="folder" onclick="socket.emit('show_folder_soft_prompt', {});"></span>
|
||||
</div>
|
||||
<div id="splistcontent">
|
||||
</div>
|
||||
|
@ -352,7 +352,7 @@
|
|||
<div class="popupcontainer hidden" id="uscontainer">
|
||||
<div id="uspopup">
|
||||
<div class="popuptitlebar">
|
||||
<div class="popuptitletext">Select userscripts to load; drag-and-drop to reorder</div>
|
||||
<div class="popuptitletext">Select userscripts to load; drag-and-drop to reorder</div><span class="oi" style="color: white;" data-glyph="folder" onclick="socket.emit('show_folder_usersripts', {});"></span>
|
||||
</div>
|
||||
<div class="usheadergrid">
|
||||
<div>[AVAILABLE]</div>
|
||||
|
|
Loading…
Reference in New Issue