- 添加认证模块 (auth.py) - 添加 CRUD 基础操作 (crud.py) - 添加异常处理 (exceptions.py) - 添加日志模块 (logging.py) - 添加响应格式 (response.py) - 添加依赖注入 (dependencies.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
21 lines
491 B
Python
21 lines
491 B
Python
"""
|
|
API Dependencies
|
|
API 依赖项
|
|
"""
|
|
from typing import Annotated
|
|
from fastapi import Depends
|
|
from app.core.auth import verify_api_key
|
|
|
|
|
|
# Type alias for API key dependency
|
|
ApiKey = Annotated[str, Depends(verify_api_key)]
|
|
|
|
|
|
# Optional API key (for endpoints that can work with or without auth)
|
|
async def get_optional_api_key(api_key: str = None) -> Optional[str]:
|
|
"""Get optional API key"""
|
|
return api_key
|
|
|
|
|
|
OptionalApiKey = Annotated[Optional[str], Depends(get_optional_api_key)]
|