(tailscale_status: dict[str, Any], serve_status: dict[str, Any])
| 478 | |
| 479 | |
| 480 | def build_remote_status(tailscale_status: dict[str, Any], serve_status: dict[str, Any]) -> dict[str, Any]: |
| 481 | serve_data = serve_status.get("data") if serve_status.get("ok") else {} |
| 482 | web_entries = list((serve_data or {}).get("Web", {}).items()) |
| 483 | if not web_entries: |
| 484 | return { |
| 485 | "published": False, |
| 486 | "url": None, |
| 487 | "target": None, |
| 488 | "detail": "远程发布未开启", |
| 489 | "health_ok": False, |
| 490 | "health_detail": "未执行远程健康检查", |
| 491 | } |
| 492 | |
| 493 | host_and_port, config = web_entries[0] |
| 494 | host = str(host_and_port).replace(":443", "") |
| 495 | target = (((config or {}).get("Handlers") or {}).get("/") or {}).get("Proxy") |
| 496 | tailscale_data = tailscale_status.get("data") if tailscale_status.get("ok") else {} |
| 497 | fallback_dns = normalize_dns_name((((tailscale_data or {}).get("Self") or {}).get("DNSName"))) |
| 498 | url = f"https://{host or fallback_dns}" if (host or fallback_dns) else None |
| 499 | health_ok = False |
| 500 | health_detail = "未执行远程健康检查" |
| 501 | if url: |
| 502 | health_ok, health_detail = http_health(f"{url}/health", timeout=2.5) |
| 503 | return { |
| 504 | "published": True, |
| 505 | "url": url, |
| 506 | "target": target, |
| 507 | "detail": f"已发布到 {target}" if target else "远程发布已开启", |
| 508 | "health_ok": health_ok, |
| 509 | "health_detail": health_detail, |
| 510 | } |
| 511 | |
| 512 | |
| 513 | def pick_mobile_display_name(peer: dict[str, Any]) -> str: |
no test coverage detected