Files
aigc-home/calliope-backend/src/calliope/comfyui/fixed_document.py
T

83 lines
3.8 KiB
Python

"""Explicit source-bound editorial documents; never a conversion or execution contract."""
from __future__ import annotations
import copy
import hashlib
import json
SOURCE_PATH = (
"example_ComfyUI_workflows/0-基础处理:图像合并-音频分离-视频截取合并-图像视频放大/"
"Minimax-H3提示词增强.json"
)
# Pins the reviewed Chinese text, saved values, pointers and complete evidence citations.
DEFINITION_SHA256 = "4da30b7b4314d6e3e37b3cefcaae710072ae0ee4e323e999789e63b386080b5e"
# Explicit path allowlist; a recomputed caller-supplied digest cannot extend trust.
DEFINITIONS = {
(
"example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_图像编辑_提示词增强.json"
): "dcbf1de5f2fb82465c6fe6c473e4c1ffa2e13d166e4becc62dc6d9acaec9a5ed",
(
"example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_文生图_提示词增强.json"
): "6dd26b64aecccd272af43f17a66f162f5bfd746807af46c5514c3eb9c00d6cb5",
SOURCE_PATH: DEFINITION_SHA256,
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/ControlNet_aux_常用样例.json"
): "b1962f8f98c002594982d536fc24384a692460e0ce9253fbddd5bfade1c01078",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/音频转MP3格式.json"
): "288ae80c9348bc85e96adc4dc9caf0fada7efedd1970b920613d1187cfb20a76",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/音频人声分离.json"
): "cced72ff103a8325c41bd3c29c6a92d5e4239146dac2374b7b95c8b74c9b66fe",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/视频-音频分离.json"
): "77acfaa5f826b48a9bcdbfa9720a5be827c9974e07cc37ecdab0ae5d4419ed3a",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/图像嵌入文字描述.json"
): "f10269bcaa0a6ab064a009f673399ab0c0d3140c50f644630f79db1035ad5019",
(
"example_ComfyUI_workflows/1-语音生成/Qwen3-ASR-语音转文字.json"
): "5b9ec6bca1b113c7b20495af9e36f5109c01e943f430de56d65e11b51f2dba63",
(
"example_ComfyUI_workflows/1-语音生成/Qwen3-ASR-Subtitle语音转字幕.json"
): "1bad3c128e8c1da689d684d5f85eef0ee3f8cabcad5f51ef148af0024f86971e",
}
def canonical(value: object) -> bytes:
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
def fixed_document_for(path: str, source: object, review: dict | None) -> dict | None:
"""Fail closed on any source, identity, dual saved value or citation mismatch.
review_for already checks the original byte SHA1 before supplying a review.
The canonical digest also protects direct build_document callers from mixing
another source object with that review. No upstream code or network is used.
"""
if path not in DEFINITIONS:
return None
pending = {
"matched": False,
"notice": "固定版本参数说明待核对:源文件、声明版本或说明依据未匹配,未采用旧定义。",
}
block = (review or {}).get("fixed_version_document")
if not isinstance(block, dict):
return pending
if hashlib.sha256(canonical(block)).hexdigest() != DEFINITIONS[path]:
return pending
if (
block["source_path"] != path
or (review or {}).get("source_sha") != block["source_sha1"]
or hashlib.sha256(canonical(source)).hexdigest() != block["canonical_sha256"]
):
return pending
return {**copy.deepcopy(block), "matched": True}