mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-11 14:50:49 +08:00
Handle too many files in output folder
Added a 50 png files from output folder limit. If this fails it also deletes the "DeleteAll" button to prevent deleting files that aren't on the list.
This commit is contained in:
parent
a783775268
commit
65fadd0d88
@ -148,6 +148,11 @@ class PromptServer():
|
||||
return web.Response(status=404)
|
||||
|
||||
images = [f for f in os.listdir(output_dir) if f.endswith('.png')]
|
||||
# Check the length of the images list
|
||||
if len(images) > 50:
|
||||
# If there are more than 50 images, raise an exception
|
||||
return web.json_response({"error": "Too many images, load from output disabled."}, status=400)
|
||||
|
||||
return web.json_response({"images": images})
|
||||
|
||||
@routes.get("/view")
|
||||
|
||||
@ -153,17 +153,6 @@ app.registerExtension({
|
||||
}
|
||||
}
|
||||
|
||||
api.getOutput().then(data => {
|
||||
try {
|
||||
var images = data.filenames[0].map((filename) => {
|
||||
return { filename: filename, type: 'output', subfolder: '' };
|
||||
});
|
||||
var output = {images: images}
|
||||
var detail = {output: output}
|
||||
loadImages(detail);
|
||||
} catch(err){}
|
||||
});
|
||||
|
||||
// stop resize function
|
||||
function stopResize() {
|
||||
document.removeEventListener("mousemove", resize);
|
||||
@ -225,7 +214,24 @@ app.registerExtension({
|
||||
allImages = []
|
||||
imageList.replaceChildren(menu, resizeHandle);
|
||||
};
|
||||
|
||||
api.getOutput().then(data => {
|
||||
try {
|
||||
if (data.message == "Success"){
|
||||
var images = data.filenames[0].map((filename) => {
|
||||
return { filename: filename, type: 'output', subfolder: '' };
|
||||
});
|
||||
var output = {images: images}
|
||||
var detail = {output: output}
|
||||
loadImages(detail);
|
||||
}
|
||||
else {
|
||||
deleteAllButton.setAttribute("disabled", true);
|
||||
}
|
||||
} catch(err){
|
||||
deleteAllButton.setAttribute("disabled", true);
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
showButton.classList.add("comfy-settings-btn");
|
||||
showButton.style.right = "16px";
|
||||
showButton.style.cursor = "pointer";
|
||||
|
||||
@ -230,15 +230,21 @@ class ComfyApi extends EventTarget {
|
||||
* Gets the prompt execution history
|
||||
* @returns Prompt history including node outputs
|
||||
*/
|
||||
async getOutput() {
|
||||
try {
|
||||
const res = await fetch("/output/images");
|
||||
return { filenames: Object.values(await res.json()) };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { output: [] };
|
||||
}
|
||||
}
|
||||
async getOutput() {
|
||||
try {
|
||||
const res = await fetch("/output/images");
|
||||
if (res.status == 200){
|
||||
var values = await res.json();
|
||||
return { filenames: Object.values(values), message: "Success" };
|
||||
}
|
||||
else {
|
||||
return { filenames: [], message: "Failed to fetch output images" };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { filenames: [], message: "Failed to fetch output images" };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a POST request to the API
|
||||
|
||||
Loading…
Reference in New Issue
Block a user