Files
aigc-home/docs/hel-892/watermark-document-evidence/discover_sources.py
T

84 lines
3.1 KiB
Python

"Bounded official textual discovery; no upstream execution or asset fetches."
import json
import urllib.parse
import urllib.request
from pathlib import Path
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "watermark-reference"
def get(url):
with urllib.request.urlopen(
urllib.request.Request(
urllib.parse.quote(url, safe=":/?=&"), headers={"User-Agent": "static-source-review"}
),
timeout=30,
) as r:
return r.read()
def main():
repos = {
"core": ("Comfy-Org/ComfyUI", "v0.25.0"),
"camera": ("karas17/ComfyUI-Camera-Watermark", "c461dedc6ce65e1defe7308e97e7081cedcaf2a7"),
"cr": ("Suzie1/ComfyUI_Comfyroll_CustomNodes", "d78b780ae43fcf8c6b7c6505e6ffb4584281ceca"),
"guhai": ("goohai/Goohaitools-comfyui", "0b267384faaa9201c821c68dfa3dacd784da171d"),
}
pins = {}
for key, (repo, ref) in repos.items():
commit = json.loads(get(f"https://api.github.com/repos/{repo}/commits/{ref}"))["sha"]
tree = json.loads(
get(f"https://api.github.com/repos/{repo}/git/trees/{commit}?recursive=1")
)
assert not tree["truncated"]
(REF / f"{key}-tree.json").write_text(json.dumps(tree, ensure_ascii=False, indent=2) + "\n")
pins[key] = {"repository": repo, "requested_ref": ref, "commit": commit}
print(key, commit)
for e in tree["tree"]:
p = e["path"]
if e["type"] == "blob" and (
p.endswith(".py") or "license" in p.lower() or p.endswith(".js")
):
if key == "core" and p not in ["nodes.py", "LICENSE.txt", "LICENSE"]:
continue
if key == "guhai" and not (
"水印" in p or p == "__init__.py" or "license" in p.lower()
):
continue
if key == "cr" and not (
any(
t in p
for t in [
"__init__.py",
"nodes_graphics_text",
"functions_graphics",
"categories",
"config",
]
)
or "license" in p.lower()
):
continue
local = REF / (key + "__" + p.replace("/", "__"))
raw = (
local.read_bytes()
if local.exists()
else get(f"https://raw.githubusercontent.com/{repo}/{commit}/{p}")
)
(REF / (key + "__" + p.replace("/", "__"))).write_bytes(raw)
# Registry release is authoritative for the declared package; do not substitute latest Git.
url = "https://api.comfy.org/nodes/comfyui_layerstyle_advance/versions/2.0.38"
try:
raw = get(url)
(REF / "layer-registry-2.0.38.json").write_bytes(raw)
print(raw.decode()[:1800])
except Exception as exc:
(REF / "layer-registry-error.txt").write_text(str(exc))
(REF / "pins.json").write_text(json.dumps(pins, indent=2) + "\n")
if __name__ == "__main__":
main()