Files
jiedian/panel/links.py
T
dekun 5685b869dc fix: improve Reality compatibility for v2rayN/Xray clients
Add empty short_id, SpiderX in share links, and post-keygen render reminder so server config stays in sync with .env.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 11:49:53 +08:00

42 lines
1.3 KiB
Python

"""分享链接生成。"""
from __future__ import annotations
import os
from pathlib import Path
from urllib.parse import quote
from db import list_nodes
from nodes_util import hy2_port
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"])
port = hy2_port(node, list_nodes())
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"&spx=%2F&type=tcp#{name}"
)
hy2 = f"hy2://{node['hy2_password']}@{domain}:{port}?sni={domain}#{name}-Hy2"
return {"vless": vless, "hy2": hy2}