new changes

This commit is contained in:
Niranjan
2026-04-07 10:03:25 +05:30
parent 5e86cc7e40
commit 8965233e8c
42 changed files with 465 additions and 120 deletions

View File

@@ -72,6 +72,38 @@ async def site_create(
return result
class SiteBatchRequest(BaseModel):
action: str
ids: list[int]
@router.post("/batch")
async def site_batch(
body: SiteBatchRequest,
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
"""Bulk enable, disable, or delete sites by id."""
if body.action not in ("enable", "disable", "delete"):
raise HTTPException(status_code=400, detail="action must be enable, disable, or delete")
if not body.ids:
raise HTTPException(status_code=400, detail="ids required")
results: list[dict] = []
for sid in body.ids:
if body.action == "delete":
r = await delete_site(db, sid)
elif body.action == "enable":
r = await set_site_status(db, sid, 1)
else:
r = await set_site_status(db, sid, 0)
results.append({
"id": sid,
"ok": bool(r.get("status")),
"msg": r.get("msg", ""),
})
return {"results": results}
@router.get("/{site_id}")
async def site_get(
site_id: int,

View File

@@ -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