From bc4e52f790d3133dfd3956918ce44df5b28296f5 Mon Sep 17 00:00:00 2001 From: doombubbles Date: Mon, 21 Aug 2023 13:25:58 -0700 Subject: [PATCH] Hash consistency fixes --- comfy/api/openapi.yaml | 2 +- comfy/cmd/server.py | 6 ++++-- comfy/digest.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/comfy/api/openapi.yaml b/comfy/api/openapi.yaml index 5be3725f7..69b1bb706 100644 --- a/comfy/api/openapi.yaml +++ b/comfy/api/openapi.yaml @@ -381,7 +381,7 @@ paths: Hashing function for python: ```python def digest(data: dict | str) -> str: - json_str = data if isinstance(data, str) else json.dumps(data) + json_str = data if isinstance(data, str) else json.dumps(data, separators=(',', ':')) json_bytes = json_str.encode('utf-8') hash_object = hashlib.sha256(json_bytes) return hash_object.hexdigest() diff --git a/comfy/cmd/server.py b/comfy/cmd/server.py index 761b6bee7..a4fddbe06 100644 --- a/comfy/cmd/server.py +++ b/comfy/cmd/server.py @@ -566,11 +566,13 @@ class PromptServer(): if len(prompt_dict) == 0: return web.Response(status=400, reason="no prompt was specified") + content_digest = digest(prompt_dict) + dump = json.dumps(prompt_dict) + valid = execution.validate_prompt(prompt_dict) if not valid[0]: return web.Response(status=400, body=valid[1]) - content_digest = digest(prompt_dict) cache_path = os.path.join(user_data_dir("comfyui", "comfyanonymous", roaming=False), content_digest) cache_url = f"/api/v1/images/{content_digest}" @@ -578,7 +580,7 @@ class PromptServer(): return web.Response(status=200, headers={ "Digest": f"SHA-256={content_digest}", - "Location": f"/api/v1/images/{content_digest}", + "Location": f"/api/v1/images/{content_digest}" }, body=json.dumps({'urls': [cache_url]})) diff --git a/comfy/digest.py b/comfy/digest.py index c6f421d34..13c4344af 100644 --- a/comfy/digest.py +++ b/comfy/digest.py @@ -3,7 +3,7 @@ import json def digest(data: dict | str) -> str: - json_str = data if isinstance(data, str) else json.dumps(data) + json_str = data if isinstance(data, str) else json.dumps(data, separators=(',', ':')) hash_object = hashlib.sha256() hash_object.update(json_str.encode()) return hash_object.hexdigest()