Add a delete images button on main floating menu

This commit is contained in:
Silversith 2023-03-21 22:36:27 +02:00
parent 1474c0f420
commit 4e5c0f4fa0
4 changed files with 21 additions and 2 deletions

View File

@ -40,9 +40,7 @@ class Note:
class SaveImageList:
def __init__(self):
current_dir = os.path.abspath(os.getcwd())
print(current_dir)
self.output_dir = os.path.join(current_dir, "output")
print(self.output_dir)
self.type = "output"
@classmethod

View File

@ -138,6 +138,22 @@ class PromptServer():
return web.Response(status=404)
@routes.post("/delete")
async def delete(request):
current_dir = os.path.abspath(os.getcwd())
output_dir = os.path.join(current_dir, "output")
if not os.path.exists(output_dir):
return web.json_response({"message": "Output directory does not exist."}, status=404)
try:
for file_name in os.listdir(output_dir):
file_path = os.path.join(output_dir, file_name)
if os.path.isfile(file_path):
os.remove(file_path)
return web.json_response({"message": "All content deleted from Output folder."}, status=200)
except Exception as e:
return web.json_response({"message": f"An error occurred: {str(e)}"}, status=500)
@routes.get("/prompt")
async def get_prompt(request):
return web.json_response(self.get_queue_info())

View File

@ -106,6 +106,10 @@ class ComfyApi extends EventTarget {
return await resp.json();
}
async deleteAllImages() {
await this.#postItem("delete", { delete: "all" })
}
/**
* Gets a list of embedding names
* @returns An array of script urls to import

View File

@ -329,6 +329,7 @@ export class ComfyUI {
$el("button", { textContent: "Load", onclick: () => fileInput.click() }),
$el("button", { textContent: "Clear", onclick: () => app.graph.clear() }),
$el("button", { textContent: "Load Default", onclick: () => app.loadGraphData() }),
$el("button", { textContent: "Delete Images", onclick: () => api.deleteAllImages() }),
]);
this.setStatus({ exec_info: { queue_remaining: "X" } });