mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-11 02:15:17 +00:00
rework payload from server
This commit is contained in:
parent
5fa514fa51
commit
d1138e8ba0
15
nodes.py
15
nodes.py
@ -775,7 +775,7 @@ class KSamplerAdvanced:
|
||||
class SaveImage:
|
||||
def __init__(self):
|
||||
self.output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "output")
|
||||
self.url_suffix = ""
|
||||
self.type = "output"
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@ -822,7 +822,7 @@ class SaveImage:
|
||||
if not os.path.exists(self.output_dir):
|
||||
os.makedirs(self.output_dir)
|
||||
|
||||
paths = list()
|
||||
results = list()
|
||||
for image in images:
|
||||
i = 255. * image.cpu().numpy()
|
||||
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
||||
@ -835,14 +835,19 @@ class SaveImage:
|
||||
|
||||
file = f"{filename}_{counter:05}_.png"
|
||||
img.save(os.path.join(full_output_folder, file), pnginfo=metadata, optimize=True)
|
||||
paths.append(os.path.join(subfolder, file + self.url_suffix))
|
||||
results.append({
|
||||
"filename": file,
|
||||
"subfolder": subfolder,
|
||||
"type": self.type
|
||||
});
|
||||
counter += 1
|
||||
return { "ui": { "images": paths } }
|
||||
|
||||
return { "ui": { "images": results } }
|
||||
|
||||
class PreviewImage(SaveImage):
|
||||
def __init__(self):
|
||||
self.output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "temp")
|
||||
self.url_suffix = "&type=temp"
|
||||
self.type = "temp"
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
|
@ -111,7 +111,7 @@ class PromptServer():
|
||||
|
||||
@routes.get("/view")
|
||||
async def view_image(request):
|
||||
if "file" in request.rel_url.query:
|
||||
if "filename" in request.rel_url.query:
|
||||
type = request.rel_url.query.get("type", "output")
|
||||
if type not in ["output", "input", "temp"]:
|
||||
return web.Response(status=400)
|
||||
@ -123,7 +123,7 @@ class PromptServer():
|
||||
return web.Response(status=403)
|
||||
output_dir = full_output_dir
|
||||
|
||||
file = request.rel_url.query["file"]
|
||||
file = request.rel_url.query["filename"]
|
||||
file = os.path.basename(file)
|
||||
file = os.path.join(output_dir, file)
|
||||
|
||||
|
@ -109,11 +109,8 @@ class ComfyApp {
|
||||
return new Promise((r) => {
|
||||
const img = new Image();
|
||||
img.onload = () => r(img);
|
||||
img.onerror = () => r(null);
|
||||
|
||||
var filename = src.replace(/^.*[\\\/]/, '');
|
||||
var subfolder = src.replace(filename, '');
|
||||
img.src = "/view?file=" + filename + "&subfolder=" + subfolder;
|
||||
img.onerror = () => r(null);
|
||||
img.src = "/view?" + new URLSearchParams(src).toString();
|
||||
});
|
||||
})
|
||||
).then((imgs) => {
|
||||
|
@ -141,7 +141,7 @@ export const ComfyWidgets = {
|
||||
node.imgs = [img];
|
||||
app.graph.setDirtyCanvas(true);
|
||||
};
|
||||
img.src = `/view/${name}?type=input`;
|
||||
img.src = `/view?filename=${name}&type=input`;
|
||||
}
|
||||
|
||||
// Add our own callback to the combo widget to render an image when it changes
|
||||
|
Loading…
Reference in New Issue
Block a user