"git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "f61798749853149c27346122805efb659441de9f"
Commit 99abc0eb authored by pythongosssss's avatar pythongosssss
Browse files

Changed to upload to input dir

Fixed jpg
Added dupe support
Changed to use existing nodes
parent 4a326a25
...@@ -833,9 +833,6 @@ class LoadImage: ...@@ -833,9 +833,6 @@ class LoadImage:
m.update(f.read()) m.update(f.read())
return m.digest().hex() return m.digest().hex()
class UploadImage(LoadImage):
input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "uploads")
class LoadImageMask: class LoadImageMask:
input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input") input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
@classmethod @classmethod
...@@ -871,9 +868,6 @@ class LoadImageMask: ...@@ -871,9 +868,6 @@ class LoadImageMask:
m.update(f.read()) m.update(f.read())
return m.digest().hex() return m.digest().hex()
class UploadImageMask(LoadImageMask):
input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "uploads")
class ImageScale: class ImageScale:
upscale_methods = ["nearest-exact", "bilinear", "area"] upscale_methods = ["nearest-exact", "bilinear", "area"]
crop_methods = ["disabled", "center"] crop_methods = ["disabled", "center"]
...@@ -925,9 +919,7 @@ NODE_CLASS_MAPPINGS = { ...@@ -925,9 +919,7 @@ NODE_CLASS_MAPPINGS = {
"LatentUpscale": LatentUpscale, "LatentUpscale": LatentUpscale,
"SaveImage": SaveImage, "SaveImage": SaveImage,
"LoadImage": LoadImage, "LoadImage": LoadImage,
"UploadImage": UploadImage,
"LoadImageMask": LoadImageMask, "LoadImageMask": LoadImageMask,
"UploadImageMask": UploadImageMask,
"ImageScale": ImageScale, "ImageScale": ImageScale,
"ImageInvert": ImageInvert, "ImageInvert": ImageInvert,
"ConditioningCombine": ConditioningCombine, "ConditioningCombine": ConditioningCombine,
......
...@@ -72,7 +72,7 @@ class PromptServer(): ...@@ -72,7 +72,7 @@ class PromptServer():
@routes.post("/upload/image") @routes.post("/upload/image")
async def upload_image(request): async def upload_image(request):
upload_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "uploads") upload_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
if not os.path.exists(upload_dir): if not os.path.exists(upload_dir):
os.makedirs(upload_dir) os.makedirs(upload_dir)
...@@ -85,7 +85,15 @@ class PromptServer(): ...@@ -85,7 +85,15 @@ class PromptServer():
if not filename: if not filename:
return web.Response(status=400) return web.Response(status=400)
with open(os.path.join(upload_dir, filename), "wb") as f: split = os.path.splitext(filename)
i = 1
while os.path.exists(os.path.join(upload_dir, filename)):
filename = f"{split[0]} ({i}){split[1]}"
i += 1
filepath = os.path.join(upload_dir, filename)
with open(filepath, "wb") as f:
f.write(image.file.read()) f.write(image.file.read())
return web.json_response({"name" : filename}) return web.json_response({"name" : filename})
...@@ -97,12 +105,12 @@ class PromptServer(): ...@@ -97,12 +105,12 @@ class PromptServer():
async def view_image(request): async def view_image(request):
if "file" in request.match_info: if "file" in request.match_info:
type = request.rel_url.query.get("type", "output") type = request.rel_url.query.get("type", "output")
if type != "output" and type != "uploads": if type != "output" and type != "input":
return web.Response(status=400) return web.Response(status=400)
output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), type) output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), type)
file = request.match_info["file"] file = request.match_info["file"]
file = os.path.splitext(os.path.basename(file))[0] + ".png" file = os.path.basename(file)
file = os.path.join(output_dir, file) file = os.path.join(output_dir, file)
if os.path.isfile(file): if os.path.isfile(file):
return web.FileResponse(file) return web.FileResponse(file)
......
import { app } from "/scripts/app.js"; import { app } from "/scripts/app.js";
// Adds an upload button to the nodes
app.registerExtension({ app.registerExtension({
name: "Comfy.UploadImage", name: "Comfy.UploadImage",
async beforeRegisterNodeDef(nodeType, nodeData, app) { async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "UploadImage" || nodeData.name === "UploadImageMask") { if (nodeData.name === "LoadImage" || nodeData.name === "LoadImageMask") {
nodeData.input.required.upload = ["IMAGEUPLOAD"]; nodeData.input.required.upload = ["IMAGEUPLOAD"];
} }
}, },
......
...@@ -141,7 +141,7 @@ export const ComfyWidgets = { ...@@ -141,7 +141,7 @@ export const ComfyWidgets = {
node.imgs = [img]; node.imgs = [img];
app.graph.setDirtyCanvas(true); app.graph.setDirtyCanvas(true);
}; };
img.src = `/view/${name}?type=uploads`; img.src = `/view/${name}?type=input`;
} }
// Add our own callback to the combo widget to render an image when it changes // Add our own callback to the combo widget to render an image when it changes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment