mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-13 00:37:00 +08:00
gitignore huggingface + extra model paths + server.py
This commit is contained in:
parent
d5ed90dd74
commit
2fae18ed9f
3
.gitignore
vendored
3
.gitignore
vendored
@ -18,4 +18,5 @@ venv/
|
||||
/tests-ui/data/object_info.json
|
||||
/user/
|
||||
*.log
|
||||
web_custom_versions/
|
||||
/huggingface/
|
||||
web_custom_versions/
|
||||
|
||||
@ -3,16 +3,18 @@ comfyui:
|
||||
checkpoints: models/checkpoints/
|
||||
clip: models/clip/
|
||||
clip_vision: models/clip_vision/
|
||||
configs: models/configs/
|
||||
configs: models/checkpoints/
|
||||
controlnet: models/controlnet/
|
||||
embeddings: models/embeddings/
|
||||
upscale_models: models/upscale_models/
|
||||
vae: models/vae/
|
||||
loras: |
|
||||
models/lora
|
||||
models/ip_adapter_faceid/lora
|
||||
hypernetworks: embeddings
|
||||
models/lora/
|
||||
models/ip_adapter_faceid/lora/
|
||||
hypernetworks: embeddings/
|
||||
ipadapter: |
|
||||
models/ip_adapter_faceid/models
|
||||
models/ip_adapter
|
||||
models/ip_adapter_faceid/models/
|
||||
models/ip_adapter/
|
||||
insightface: models/insightface/
|
||||
|
||||
|
||||
|
||||
@ -134,6 +134,7 @@ def add_model_folder_path(folder_name, full_folder_path):
|
||||
folder_names_and_paths[folder_name] = ([full_folder_path], set())
|
||||
|
||||
def get_folder_paths(folder_name):
|
||||
print(folder_names_and_paths[folder_name][0][:])
|
||||
return folder_names_and_paths[folder_name][0][:]
|
||||
|
||||
def recursive_search(directory, excluded_dir_names=None):
|
||||
@ -191,8 +192,11 @@ def get_full_path(folder_name, filename):
|
||||
|
||||
def get_filename_list_(folder_name):
|
||||
global folder_names_and_paths
|
||||
print("global path")
|
||||
print(folder_names_and_paths)
|
||||
output_list = set()
|
||||
folders = folder_names_and_paths[folder_name]
|
||||
print(f"folders path :\n {folders}")
|
||||
output_folders = {}
|
||||
for x in folders[0]:
|
||||
files, folders_all = recursive_search(x, excluded_dir_names=[".git"])
|
||||
|
||||
105
server.py
105
server.py
@ -2,6 +2,7 @@ import os
|
||||
import sys
|
||||
import asyncio
|
||||
import traceback
|
||||
# import io
|
||||
|
||||
import nodes
|
||||
import folder_paths
|
||||
@ -175,132 +176,66 @@ class PromptServer():
|
||||
return a.hexdigest() == b.hexdigest()
|
||||
return False
|
||||
|
||||
def is_base64_string(s):
|
||||
try:
|
||||
if isinstance(s, str):
|
||||
if s.startswith('data:image'):
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
return False
|
||||
# def is_base64_string(s):
|
||||
# try:
|
||||
# if isinstance(s, str):
|
||||
# if s.startswith('data:image'):
|
||||
# return True
|
||||
# return False
|
||||
# except Exception as e:
|
||||
# return False
|
||||
|
||||
def image_upload(post, image_save_function=None):
|
||||
print("Starting image upload process")
|
||||
|
||||
image = post.get("image")
|
||||
overwrite = post.get("overwrite")
|
||||
image_is_duplicate = False
|
||||
|
||||
image_upload_type = post.get("type")
|
||||
print(f"Image upload type: {image_upload_type}")
|
||||
|
||||
# print(f"Received image data: {image}")
|
||||
|
||||
upload_dir, image_upload_type = get_dir_by_type(image_upload_type)
|
||||
print(f"Upload directory: {upload_dir}, Image type: {image_upload_type}, Overwrite: {overwrite}")
|
||||
|
||||
if image:
|
||||
if isinstance(image, web.FileField):
|
||||
filename = image.filename
|
||||
file_content = image.file.read()
|
||||
else:
|
||||
filename = image.get("filename")
|
||||
file_content = image.get("file")
|
||||
if is_base64_string(file_content):
|
||||
file_content = base64.b64decode(file_content.split(",")[1])
|
||||
|
||||
print(f"Filename: {filename}")
|
||||
print(f"File content length: {len(file_content)}")
|
||||
|
||||
if not filename or not file_content:
|
||||
print("No filename or file content provided")
|
||||
if image and image.file:
|
||||
filename = image.filename
|
||||
if not filename:
|
||||
return web.Response(status=400)
|
||||
|
||||
subfolder = post.get("subfolder", "")
|
||||
full_output_folder = os.path.join(upload_dir, os.path.normpath(subfolder))
|
||||
filepath = os.path.abspath(os.path.join(full_output_folder, filename))
|
||||
print(f"Full output folder: {full_output_folder}")
|
||||
print(f"File path: {filepath}")
|
||||
|
||||
if os.path.commonpath((upload_dir, filepath)) != upload_dir:
|
||||
print("Security check failed: filepath not within upload directory")
|
||||
return web.Response(status=400)
|
||||
|
||||
if not os.path.exists(full_output_folder):
|
||||
os.makedirs(full_output_folder)
|
||||
print(f"Created output folder: {full_output_folder}")
|
||||
|
||||
split = os.path.splitext(filename)
|
||||
print(f"File split: {split}")
|
||||
|
||||
if overwrite is not None and (overwrite == "true" or overwrite == "1"):
|
||||
print("Overwrite enabled")
|
||||
pass
|
||||
else:
|
||||
i = 1
|
||||
while os.path.exists(filepath):
|
||||
print(f"File exists: {filepath}")
|
||||
if compare_image_hash(filepath, file_content): # compare hash to prevent saving of duplicates with same name
|
||||
print(f"Duplicate image found: {filepath}")
|
||||
if compare_image_hash(filepath, image): #compare hash to prevent saving of duplicates with same name, fix for #3465
|
||||
image_is_duplicate = True
|
||||
break
|
||||
filename = f"{split[0]} ({i}){split[1]}"
|
||||
filepath = os.path.join(full_output_folder, filename)
|
||||
i += 1
|
||||
print(f"New filename: {filename}, New filepath: {filepath}")
|
||||
|
||||
if not image_is_duplicate:
|
||||
if is_base64_string(file_content):
|
||||
print("File content is a Base64 string")
|
||||
# Handle base64 string
|
||||
image_bytes = base64.b64decode(file_content.split(",")[1])
|
||||
if image_save_function is not None:
|
||||
print(f"Using custom image save function for Base64 content")
|
||||
image_save_function(image_bytes, post, filepath)
|
||||
else:
|
||||
with open(filepath, "wb") as f:
|
||||
print(f"Saving Base64 decoded image to: {filepath}")
|
||||
f.write(image_bytes)
|
||||
if image_save_function is not None:
|
||||
image_save_function(image, post, filepath)
|
||||
else:
|
||||
print("File content is a raw file-like object")
|
||||
# Handle raw file-like object
|
||||
if image_save_function is not None:
|
||||
print(f"Using custom image save function for raw file")
|
||||
image_save_function(file_content, post, filepath)
|
||||
else:
|
||||
with open(filepath, "wb") as f:
|
||||
print(f"Saving raw file to: {filepath}")
|
||||
f.write(file_content)
|
||||
return web.json_response({"name": filename, "subfolder": subfolder, "type": image_upload_type})
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(image.file.read())
|
||||
|
||||
return web.json_response({"name" : filename, "subfolder": subfolder, "type": image_upload_type})
|
||||
else:
|
||||
print("No image provided in the post data")
|
||||
return web.Response(status=400)
|
||||
|
||||
@routes.post("/upload/image")
|
||||
async def upload_image(request):
|
||||
content_type = request.headers.get('Content-Type')
|
||||
print(f"Content-Type: {content_type}")
|
||||
|
||||
post = {}
|
||||
if 'application/json' in content_type:
|
||||
try:
|
||||
post = await request.json()
|
||||
print(f"Received JSON post data: {post}")
|
||||
except Exception as e:
|
||||
print(f"Error parsing JSON: {e}")
|
||||
return web.Response(status=400, text="Invalid JSON data")
|
||||
elif 'multipart/form-data' in content_type:
|
||||
try:
|
||||
post = await request.post()
|
||||
print(f"Received form-data post data: {post}")
|
||||
post = {key: post[key] for key in post.keys()}
|
||||
except Exception as e:
|
||||
print(f"Error parsing form-data: {e}")
|
||||
return web.Response(status=400, text="Invalid form-data")
|
||||
else:
|
||||
print("Unsupported Content-Type")
|
||||
return web.Response(status=400, text="Unsupported Content-Type")
|
||||
|
||||
post = await request.post()
|
||||
return image_upload(post)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user