File size: 1,372 Bytes
b49d66f
050d8f8
b49d66f
050d8f8
 
b49d66f
 
050d8f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b49d66f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()

@router.get("/health")
async def health_check():
    """
    Health check endpoint.
    """
    return {"status": "healthy", "service": "url-blink-api"}


@router.get("/", response_class=HTMLResponse)
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())


@router.get("/api/key-stats")
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
    }