# -*- coding: utf-8 -*- """Upload 貂蝉.png / 董卓.png to SORB for public URL + vision analysis.""" import json, ssl, pathlib, urllib.request, hashlib, time BASE = "https://192.168.31.88:8042" CFG = pathlib.Path(r"C:\Users\admin\.zcode\cli\config.json") pat = json.loads(CFG.read_text(encoding="utf-8-sig"))["mcp"]["servers"]["sorb"]["env"]["SORB_PAT"] ctx = ssl._create_unverified_context() JOBS = [ (r"D:\腾讯\吕布\美女.png", "句6_美人参考_美女", "upload_j6_beauty_20261029_v1"), (r"D:\腾讯\吕布\坏人.png", "句6_坏人参考_坏人", "upload_j6_villain_20261029_v1"), ] for path, name, key in JOBS: p = pathlib.Path(path) data = p.read_bytes() sha = hashlib.sha256(data).hexdigest() intent = { "client_namespace": "lubu_pv_board", "idempotency_key": key, "project_id": 30, "name": name, "asset_type": "image", "mime_type": "image/png", "file_size": len(data), "sha256": sha, } req = urllib.request.Request(BASE + "/api/external/v1/resources/upload", data=data, method="POST", headers={"Authorization": "Bearer " + pat, "Content-Type": "image/png", "X-Sorb-Upload-Intent": json.dumps(intent)}) try: with urllib.request.urlopen(req, context=ctx, timeout=120) as r: o = json.loads(r.read().decode("utf-8")) res = o.get("resource") or {} print(name, "-> media_id:", res.get("id"), "| url:", res.get("file_url")) except urllib.error.HTTPError as e: print(name, "HTTP", e.code, e.read().decode("utf-8")[:400])