Show WireGuard QR, full .conf and ZIP download after 3x-ui client create

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-25 22:51:19 +03:00
co-authored by Cursor
parent 9ae64d1bd1
commit 0ef3562860
9 changed files with 465 additions and 12 deletions
+41
View File
@@ -287,6 +287,39 @@ async def list_all_site_clients(session: AsyncSession) -> list[XuiSiteClient]:
return list(result.scalars().all())
async def get_site_client(session: AsyncSession, site_client_id: int) -> XuiSiteClient | None:
from sqlalchemy.orm import selectinload
result = await session.execute(
select(XuiSiteClient)
.options(selectinload(XuiSiteClient.panel))
.where(XuiSiteClient.id == site_client_id)
)
return result.scalar_one_or_none()
async def site_client_download_payload(row: XuiSiteClient) -> tuple[str, str]:
"""Return (filename_stem, text content) for conf/link download."""
safe = "".join(ch if ch.isalnum() or ch in "-_" else "_" for ch in (row.email or "client"))
if row.protocol == "wireguard":
text = row.config_text or ""
if not text and row.private_key and row.address and row.server_public_key and row.endpoint:
from app.services.crypto import render_xui_wireguard_config
text = render_xui_wireguard_config(
private_key=row.private_key,
address=row.address,
dns=row.dns or "1.1.1.1, 1.0.0.1",
mtu=row.mtu or 1420,
server_public_key=row.server_public_key,
endpoint=row.endpoint,
remark=row.inbound_remark or row.email,
)
return safe, text
text = row.link or row.config_text or ""
return safe, text
async def add_xui_client(
session: AsyncSession,
panel: XuiPanel,
@@ -359,6 +392,14 @@ async def add_xui_client(
row.private_key = result.get("privateKey")
row.public_key = result.get("publicKey")
row.link = links[0] if links else None
row.address = result.get("address")
row.endpoint = result.get("endpoint")
row.dns = result.get("dns")
row.mtu = result.get("mtu")
row.server_public_key = result.get("server_public_key")
row.config_text = result.get("config_text")
if not row.config_text and row.link:
row.config_text = row.link
row.expiry_days = expiry_days
row.start_after_first_use = start_after_first_use
row.expiry_time = int(result.get("expiryTime") or expiry_time or 0)