#!/usr/bin/env python3
"""Step6 校验：确认前端直读的 MCP 文件在 CDN 上是否为新版（cron 临时探针）"""
import hashlib, json, os, time, urllib.parse, urllib.request

BASE = "https://bier-sales-d0gatbvlx288724e9-1458438710.tcloudbaseapp.com"
DATA = os.path.expanduser("~/Desktop/Hermes输出-工作类/数据")
FILES = ["mcp_customers.json", "mcp_complaints.json", "daily_activities_mcp.json", "activities_feishu.json"]


def md5b(b):
    return hashlib.md5(b).hexdigest()


def get(url):
    req = urllib.request.Request(url, headers={"Cache-Control": "no-cache", "User-Agent": "verify"})
    return urllib.request.urlopen(req, timeout=90).read()


for f in FILES:
    lp = os.path.join(DATA, f)
    lb = open(lp, "rb").read()
    cp = urllib.parse.quote("数据/" + f)
    try:
        rb = get(f"{BASE}/{cp}?v={int(time.time())}")
        print(f"{f}: {'✅CDN一致' if md5b(lb) == md5b(rb) else '⚠️CDN为旧版/不一致'} "
              f"local={len(lb)}B remote={len(rb)}B")
    except Exception as e:
        print(f"{f}: ❌CDN不存在或拉取失败 ({e})  local={len(lb)}B")
