Spaces:
Running
Running
Download publication_identity.py from ZHIWEI666/ComfyUI-Ranking-API: direct link, hf CLI and curl.
- Browser
- Download file 982 Bytes
-
https://huggingface.co/spaces/ZHIWEI666/ComfyUI-Ranking-API/resolve/main/publication_identity.py
- Command line
-
hf download hf://spaces/ZHIWEI666/ComfyUI-Ranking-API/publication_identity.py
-
curl -L -o publication_identity.py https://huggingface.co/spaces/ZHIWEI666/ComfyUI-Ranking-API/resolve/main/publication_identity.py
982 Bytes
| """可选发布请求身份;只提供现存内容记录范围内的重复创建确认。""" | |
| import hashlib | |
| import json | |
| import re | |
| def publication_identity(kind, account, key): | |
| if key is None: | |
| return None | |
| if kind not in {'post', 'prompt'} or not isinstance(account, str) or not account: | |
| raise ValueError('invalid publication owner') | |
| if not isinstance(key, str) or re.fullmatch(r'[0-9a-f]{32}', key) is None: | |
| raise ValueError('invalid publication key') | |
| data = json.dumps([kind, account, key], ensure_ascii=False, separators=(',', ':')).encode('utf-8') | |
| return f'{kind}_publish_{hashlib.sha256(data).hexdigest()}' | |
| def same_publication(existing, incoming, fields): | |
| def content(record): | |
| return json.dumps({field: record.get(field) for field in fields}, ensure_ascii=False, | |
| sort_keys=True, separators=(',', ':'), allow_nan=False) | |
| return content(existing) == content(incoming) | |