"""分享链接生成。""" from __future__ import annotations import os from pathlib import Path from urllib.parse import quote def load_env() -> dict[str, str]: root = Path(os.environ.get("JIEDIAN_ROOT", Path(__file__).resolve().parents[1])) env: dict[str, str] = {} for line in (root / ".env").read_text(encoding="utf-8").splitlines(): line = line.strip() if not line or line.startswith("#") or "=" not in line: continue key, _, value = line.partition("=") env[key.strip()] = value.strip() return env def build_links(node: dict, env: dict | None = None) -> dict[str, str]: env = env or load_env() vps_ip = env["VPS_IP"] domain = env["DOMAIN"] reality_sni = env.get("REALITY_SERVER_NAME", "www.microsoft.com") public_key = env["REALITY_PUBLIC_KEY"] short_id = env["REALITY_SHORT_ID"] name = quote(node["name"]) vless = ( f"vless://{node['uuid']}@{vps_ip}:443" f"?encryption=none&flow=xtls-rprx-vision&security=reality" f"&sni={reality_sni}&fp=chrome&pbk={public_key}&sid={short_id}" f"&type=tcp#{name}" ) hy2 = f"hy2://{node['hy2_password']}@{domain}:8443?sni={domain}#{name}-Hy2" return {"vless": vless, "hy2": hy2}