feat(license): 接入授权平台客户端门禁(license-v2/lease-v2)并烧入交付版信任根

This commit is contained in:
lianjianwei2024
2026-10-10 18:05:04 +08:00
parent 6de1370ce5
commit d3a805ede0
25 changed files with 3123 additions and 25 deletions

View File

@@ -39,6 +39,7 @@ import price_html as price # 信息价 / 市场价 HTML 解析器
import price_xlsx # 信息价 / 市场价 Excel 解析器(2026-10-06 新增,与上面共用入库口径)
import session_job as sess # 会话库(工作台)
import match # 比对引擎(M4)
import license_client.gate as license_gate # 授权门禁(license-v2/lease-v2,2026-10-10)
# ⚠️ 2026-10-06 删除 `from search_demo import build`:search_demo 的 FTS/x_period 索引只为它
# 自己的演示查询服务,生产比对引擎 match.py 全程用 x_hash_exact/x_hash_semi + LIKE,
# 从不读 bills_fts/lmes_fts;每次导入重建 FTS(约 2 秒)纯属白费。索引由 schema.sql 在
@@ -3541,11 +3542,26 @@ class Handler(SimpleHTTPRequestHandler):
self.end_headers()
self.wfile.write(raw)
def _gate_send(self, r):
"""发送门禁拦截响应:授权页(自包含 HTML)或 JSON 错误。"""
if r.get("kind") == "html":
body = r["text"].encode("utf-8")
self.send_response(r.get("code", 200))
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
return
return self._json(r["obj"], r.get("code", 200))
def do_GET(self):
if not self._allowed_origin():
return self._json({"error": "forbidden"}, 403)
u = urllib.parse.urlparse(self.path)
p, q = u.path, urllib.parse.parse_qs(u.query)
_g = license_gate.intercept("GET", p) # 授权门禁:未激活/过期只放授权页与 /api/license/*
if _g is not None:
return self._gate_send(_g)
one = {k: v[0] for k, v in q.items()}
try:
if p == "/api/sessions": # 最近审核(会话台账,按源文件去重)
@@ -3702,6 +3718,9 @@ class Handler(SimpleHTTPRequestHandler):
body = {}
if not isinstance(body, dict): # JSON 是数组/字符串/数字时,下面 body.get 会 500,统一按空请求处理
body = {}
_g = license_gate.intercept("POST", u.path, body) # 授权门禁(/api/license/activate 在此放行)
if _g is not None:
return self._gate_send(_g)
try:
if u.path == "/api/admin/import":
with WRITE_LOCK: # 写库串行
@@ -3895,6 +3914,7 @@ def run():
migrate_match_keys() # 决策 27:清单哈希改编码前9位 + 字集键回填(幂等,探针跳过)
ensure_dict_schema() # 数据源字典(首次用库里已有值播种)
backfill_session_batch() # 老会话补 x_batch_id → 工作台才能看到该项目的询价附件
license_gate.init(DATA_DIR) # 授权门禁:读配置/状态,配了凭据则起心跳线程(内部吞异常)
cleanup_sessions() # 启动时清掉超过保留天数的会话(只碰 session.db)
try: # 启动自检:有批次是用旧解析器导入的 → 控制台先报一句
s = stale_batches()