Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter, Depends | |
| from fastapi.responses import HTMLResponse | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| import os | |
| from core.database import get_db | |
| router = APIRouter() | |
| async def health_check(): | |
| """ | |
| Health check endpoint. | |
| """ | |
| return {"status": "healthy", "service": "url-blink-api"} | |
| async def root(): | |
| """ | |
| Serve the main HTML page. | |
| """ | |
| # Note: We need to go up one level to find templates since we are in routers/ | |
| # But actually, app.py is in root, so templates is in root. | |
| # The file path logic here needs to be robust. | |
| # os.path.dirname(__file__) is routers/ | |
| # so we need ../templates | |
| base_dir = os.path.dirname(os.path.dirname(__file__)) | |
| template_path = os.path.join(base_dir, "templates", "index.html") | |
| with open(template_path, "r") as f: | |
| return HTMLResponse(content=f.read()) | |
| async def get_api_key_stats(db: AsyncSession = Depends(get_db)): | |
| """ | |
| Get API key usage statistics. | |
| Returns usage stats by key index (not actual keys for security). | |
| """ | |
| from services.api_key_manager import get_all_usage_stats, get_key_count | |
| stats = await get_all_usage_stats(db) | |
| return { | |
| "total_keys": get_key_count(), | |
| "keys": stats | |
| } | |