feat: implement AI model API proxy service

This commit is contained in:
2026-03-11 18:22:16 +08:00
commit 26738973bd
33 changed files with 4607 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
"""Authentication service."""
import aiosqlite
from typing import Optional
from ..database import db_connection
from ..models import ClientKey
class AuthService:
"""Service for client key authentication."""
@staticmethod
async def validate_key(api_key: str) -> Optional[ClientKey]:
"""Validate a client API key.
Args:
api_key: The API key to validate
Returns:
ClientKey if valid and active, None otherwise
"""
async with db_connection() as db:
cursor = await db.execute(
"""SELECT id, key, name, is_active, created_at
FROM client_keys WHERE key = ?""",
(api_key,)
)
row = await cursor.fetchone()
if row and row["is_active"]:
return ClientKey(
id=row["id"],
key=row["key"],
name=row["name"],
is_active=row["is_active"],
created_at=row["created_at"]
)
return None