Prevent on server side deletion of folders other than in models in the executing directory

Removed delete icon for model folders outside the models directory
This commit is contained in:
ebolam 2022-06-14 19:39:11 -04:00
parent f444ad851f
commit 095cd2a19d
2 changed files with 9 additions and 5 deletions

View File

@ -369,9 +369,13 @@ def sendModelSelection(menu="mainmenu", folder="./models"):
breadcrumbs = [] breadcrumbs = []
menu_list = [[folder, menu, "", False] for folder in paths] menu_list = [[folder, menu, "", False] for folder in paths]
menu_list.append(["Return to Main Menu", "mainmenu", "", True]) menu_list.append(["Return to Main Menu", "mainmenu", "", True])
emit('from_server', {'cmd': 'show_model_menu', 'data': menu_list, 'menu': menu, 'breadcrumbs': breadcrumbs}, broadcast=True) if os.path.abspath("{}/models".format(os.getcwd())) == os.path.abspath(folder):
showdelete=True
else:
showdelete=False
emit('from_server', {'cmd': 'show_model_menu', 'data': menu_list, 'menu': menu, 'breadcrumbs': breadcrumbs, "showdelete": showdelete}, broadcast=True)
else: else:
emit('from_server', {'cmd': 'show_model_menu', 'data': model_menu[menu], 'menu': menu, 'breadcrumbs': []}, broadcast=True) emit('from_server', {'cmd': 'show_model_menu', 'data': model_menu[menu], 'menu': menu, 'breadcrumbs': [], "showdelete": False}, broadcast=True)
def get_folder_path_info(base): def get_folder_path_info(base):
if base == 'This PC': if base == 'This PC':

View File

@ -998,7 +998,7 @@ function hideUSPopup() {
} }
function buildLoadModelList(ar, menu, breadcrumbs) { function buildLoadModelList(ar, menu, breadcrumbs, showdelete) {
disableButtons([load_model_accept]); disableButtons([load_model_accept]);
loadmodelcontent.html(""); loadmodelcontent.html("");
$("#loadmodellistbreadcrumbs").html(""); $("#loadmodellistbreadcrumbs").html("");
@ -1037,7 +1037,7 @@ function buildLoadModelList(ar, menu, breadcrumbs) {
} }
//now let's do the delete icon if applicable //now let's do the delete icon if applicable
if (['NeoCustom', 'GPT2Custom'].includes(menu) && !ar[i][3]) { if (['NeoCustom', 'GPT2Custom'].includes(menu) && !ar[i][3] && showdelete) {
html = html + "<span class=\"loadlisticon loadmodellisticon-folder oi oi-x allowed\" aria-hidden=\"true\" onclick='if(confirm(\"This will delete the selected folder with all contents. Are you sure?\")) { socket.send({\"cmd\": \"delete_model\", \"data\": \""+full_path.replaceAll("\\", "\\\\")+"\", \"menu\": \""+menu+"\"});}'></span>" html = html + "<span class=\"loadlisticon loadmodellisticon-folder oi oi-x allowed\" aria-hidden=\"true\" onclick='if(confirm(\"This will delete the selected folder with all contents. Are you sure?\")) { socket.send({\"cmd\": \"delete_model\", \"data\": \""+full_path.replaceAll("\\", "\\\\")+"\", \"menu\": \""+menu+"\"});}'></span>"
} else { } else {
html = html + "<div class=\"loadlistpadding\"></div>" html = html + "<div class=\"loadlistpadding\"></div>"
@ -2526,7 +2526,7 @@ $(document).ready(function(){
$("#modelkey").addClass("hidden"); $("#modelkey").addClass("hidden");
$("#modellayers").addClass("hidden"); $("#modellayers").addClass("hidden");
$("#oaimodel").addClass("hidden") $("#oaimodel").addClass("hidden")
buildLoadModelList(msg.data, msg.menu, msg.breadcrumbs); buildLoadModelList(msg.data, msg.menu, msg.breadcrumbs, msg.showdelete);
} else if(msg.cmd == 'selected_model_info') { } else if(msg.cmd == 'selected_model_info') {
enableButtons([load_model_accept]); enableButtons([load_model_accept]);
$("#oaimodel").addClass("hidden") $("#oaimodel").addClass("hidden")