new changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""YakPanel - Site service"""
|
||||
import os
|
||||
import re
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
|
||||
@@ -126,13 +127,19 @@ async def create_site(
|
||||
|
||||
|
||||
async def list_sites(db: AsyncSession) -> list[dict]:
|
||||
"""List all sites with domain count."""
|
||||
"""List all sites with domain count, primary domain, backup count, SSL summary."""
|
||||
cfg = get_runtime_config()
|
||||
backup_dir = cfg.get("backup_path") or ""
|
||||
result = await db.execute(select(Site).order_by(Site.id))
|
||||
sites = result.scalars().all()
|
||||
out = []
|
||||
for s in sites:
|
||||
domain_result = await db.execute(select(Domain).where(Domain.pid == s.id))
|
||||
domains = domain_result.scalars().all()
|
||||
domain_result = await db.execute(select(Domain).where(Domain.pid == s.id).order_by(Domain.id))
|
||||
domain_rows = domain_result.scalars().all()
|
||||
domain_list = [f"{d.name}:{d.port}" if d.port != "80" else d.name for d in domain_rows]
|
||||
hostnames = [d.name for d in domain_rows]
|
||||
primary = hostnames[0] if hostnames else ""
|
||||
php_ver = getattr(s, "php_version", None) or "74"
|
||||
out.append({
|
||||
"id": s.id,
|
||||
"name": s.name,
|
||||
@@ -140,8 +147,13 @@ async def list_sites(db: AsyncSession) -> list[dict]:
|
||||
"status": s.status,
|
||||
"ps": s.ps,
|
||||
"project_type": s.project_type,
|
||||
"domain_count": len(domains),
|
||||
"domain_count": len(domain_rows),
|
||||
"addtime": s.addtime.isoformat() if s.addtime else None,
|
||||
"php_version": php_ver,
|
||||
"primary_domain": primary,
|
||||
"domains": domain_list,
|
||||
"backup_count": _backup_count(s.name, backup_dir),
|
||||
"ssl": _best_ssl_for_hostnames(hostnames),
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
Reference in New Issue
Block a user