|
|
@@ -1,7 +1,8 @@
|
|
|
-from fastapi import APIRouter, Depends, HTTPException, Query
|
|
|
-from typing import List, Optional
|
|
|
import db
|
|
|
import auth_utils
|
|
|
+import subprocess
|
|
|
+import os
|
|
|
+from fastapi import APIRouter, Depends, HTTPException, Query, BackgroundTasks, Request
|
|
|
from dependencies import require_admin
|
|
|
|
|
|
router = APIRouter(prefix="/admin", tags=["admin"])
|
|
|
@@ -40,9 +41,30 @@ async def get_audit_logs(
|
|
|
else:
|
|
|
total = db.execute_query(count_query)
|
|
|
|
|
|
- return {
|
|
|
- "logs": logs,
|
|
|
- "total": total[0]['total'],
|
|
|
"page": page,
|
|
|
"size": size
|
|
|
}
|
|
|
+
|
|
|
+def run_deploy():
|
|
|
+ """Фоновая задача для обновления сайта"""
|
|
|
+ try:
|
|
|
+ # Путь к корню проекта
|
|
|
+ root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
+ # Выполняем цепочку команд
|
|
|
+ cmd = f"cd {root_dir} && git pull && npm install && ./build_frontend.sh && sudo systemctl restart radionica-backend"
|
|
|
+ subprocess.run(cmd, shell=True, check=True, capture_output=True)
|
|
|
+ print("✅ Auto-deploy finished successfully")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"❌ Auto-deploy failed: {e}")
|
|
|
+
|
|
|
+@router.post("/webhook/deploy")
|
|
|
+async def deploy_webhook(
|
|
|
+ secret: str,
|
|
|
+ background_tasks: BackgroundTasks
|
|
|
+):
|
|
|
+ # Секретный ключ для защиты от спама
|
|
|
+ if secret != "NY9B9VLifDC9ehZ":
|
|
|
+ raise HTTPException(status_code=403, detail="Invalid secret")
|
|
|
+
|
|
|
+ background_tasks.add_task(run_deploy)
|
|
|
+ return {"message": "Deployment triggered"}
|