mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-10 06:10:50 +08:00
Hash consistency fixes
This commit is contained in:
parent
9897c9c9bd
commit
bc4e52f790
@ -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()
|
||||
|
||||
@ -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]}))
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user