DevPlace CI / test (push) Failing after 36m45s
Consolidate scattered `X-Real-IP` / `request.client.host` fallback logic into the single `client_ip()` helper from `utils`, reducing duplication in the rate limiter middleware, project file zip routes, tools shared module, and audit record builder. Also refactor three admin endpoints (`/ai-usage/data`, `/analytics`, `/users/{uid}/ai-usage`) to use the existing `require_admin()` guard instead of repeating manual auth checks, and remove now-unused `get_current_user`/`is_admin` imports from those modules.
24 lines
683 B
Python
24 lines
683 B
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import logging
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import HTMLResponse, JSONResponse
|
|
from devplacepy.database import get_platform_analytics
|
|
from devplacepy.utils import require_admin
|
|
from devplacepy.responses import action_result
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_class=HTMLResponse)
|
|
async def admin_index(request: Request):
|
|
require_admin(request)
|
|
return action_result(request, "/admin/users")
|
|
|
|
|
|
@router.get("/analytics")
|
|
async def admin_analytics(request: Request, top_n: int = 10):
|
|
require_admin(request)
|
|
return JSONResponse(get_platform_analytics(top_n))
|