Files
2026-06-28 00:26:18 +08:00

35 lines
992 B
Python

"""分享链接生成(Hysteria2)。"""
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()
domain = env["DOMAIN"]
name = quote(node["name"])
port = hy2_port(node, list_nodes())
hy2 = (
f"hy2://{quote(node['hy2_password'], safe='')}@{domain}:{port}"
f"?sni={domain}#{name}-Hy2"
)
return {"hy2": hy2}