2 Commits

Author SHA1 Message Date
3a1daf3857 zero-dep requirements.txt 2026-07-24 13:48:28 +08:00
52dd9f050e zero-dep main.py 2026-07-24 13:48:26 +08:00
2 changed files with 14 additions and 8 deletions

19
main.py
View File

@@ -66,12 +66,15 @@ def _aes_cbc_b64(pt, key, iv):
def _sign(model, cfg, t_ms):
a = _sha_hex("computility:model-verify:browser-submit" + "|v1|" + str(t_ms) + "|" + model)
ii = _sha_hex(cfg)
kf = _sha_bytes("key|" + a + "|" + ii)[:16]
ivf = _sha_bytes("iv|" + model + "|" + str(t_ms) + "|" + str(len(cfg)))[:16]
o = str(t_ms) + "\n" + model + "\n" + cfg
return _sha_hex("v1." + a + "." + _aes_cbc_b64(o, kf, ivf) + "." + ii)
try:
a = _sha_hex("computility:model-verify:browser-submit" + "|v1|" + str(t_ms) + "|" + model)
ii = _sha_hex(cfg)
kf = _sha_bytes("key|" + a + "|" + ii)[:16]
ivf = _sha_bytes("iv|" + model + "|" + str(t_ms) + "|" + str(len(cfg)))[:16]
o = str(t_ms) + "\n" + model + "\n" + cfg
return _sha_hex("v1." + a + "." + _aes_cbc_b64(o, kf, ivf) + "." + ii)
except Exception:
return None # cryptography 不可用(零依赖构建)→ 提交走 token-only
def build_config(gpu):
@@ -109,7 +112,9 @@ def _post(model, gpu, cfg, signed):
t_ms = int(time.time() * 1000)
h = {"Authorization": TOKEN, "Content-Type": "application/json"}
if signed:
h.update({"X-Request-Time": str(t_ms), "X-Model-Address": model, "X-Request-Sign": _sign(model, cfg, t_ms)})
sig = _sign(model, cfg, t_ms)
if sig:
h.update({"X-Request-Time": str(t_ms), "X-Model-Address": model, "X-Request-Sign": sig})
body = json.dumps({"modelAddress": model, "taskType": TASK_TYPE, "targetGpu": gpu,
"framework": FRAMEWORK, "configParams": cfg})
st, txt = _http("POST", MAIN + "/api/adapt/task/add", h, body)

View File

@@ -1 +1,2 @@
cryptography>=42.0.0
# 零依赖:纯 stdlib。签名需 AES,构建环境 pip 装 cryptography 会卡(疑 PyPI 不通),
# 故设为可选——签名不可用时提交走 token-only。确认需签名后再解决 crypto。