按功能模块拆分API路由到不同文件

This commit is contained in:
shuohigh@gmail.com
2025-05-19 15:02:34 +08:00
parent c21e999188
commit 668a5a33d4
20 changed files with 708 additions and 629 deletions

View File

@@ -0,0 +1,23 @@
from fastapi import Depends, HTTPException
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from starlette import status
bearer_scheme = HTTPBearer()
async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(bearer_scheme)):
token = credentials.credentials
# 在这里实现你的token验证逻辑
if not is_valid_token(token):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid authentication credentials",
headers={"WWW-Authenticate": "Bearer"},
)
return token
def is_valid_token(token: str) -> bool:
# 这里实现具体的token验证逻辑
# 例如:验证JWT token,检查数据库中的token等
return token == "bowong7777"