Hash consistency fixes

This commit is contained in:
doombubbles 2023-08-21 13:25:58 -07:00
parent 9897c9c9bd
commit bc4e52f790
3 changed files with 6 additions and 4 deletions

View File

@ -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()

View File

@ -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]}))

View File

@ -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()