Archived
feat(routes): 迁移查询类路由到 FastAPI + 会话互通 + 统一错误/限流
会话互通(迁移关键): - core/session.py:itsdangerous 兼容的签名 Cookie 编解码(同密钥/同 salt/同 时间戳编码),Flask 与 FastAPI 双向可读——实测 F->core 与 core->F 双向解出一致, 篡改/错密钥返回 None FastAPI 基础设施: - web/deps.py 会话→当前用户(封禁/顶号校验,口径同 auth_system.current_user) - web/errors.py AppError + 全局异常处理,404/405/400 统一为本站包体 - web/ratelimit.py 复用 core.state 同一批限流桶(跨栈共享,避免绕框架绕过限流) - core/repo.py 补 get_user_by_id(异步) 迁移路由(/api/v1/*,与 Flask 同端点逐字段对齐): - toplist / artist_songs / comments / search,走 music_api 异步方法 - search 的服务器昵称遮蔽改为 FastAPI 侧异步实现(不再依赖 main) 契约奇偶校验:扩展至 7 项(含登录会话互通 + 未登录 401),全 OK; CDN 分片主机差异归一化(上游易变值,非契约漂移)。 验证:pytest 33/33;ruff All checks passed;pyright 0 errors; uvicorn 实跑未登录 401 包体与 Flask 一致。
This commit is contained in:
1 parent
c77ef40fd5
commit
2c55b55e03
9 files changed
+559
-6
No files matched your search
@@ -54,6 +54,11 @@ async def get_user_by_name(username: str) -> dict[str, Any] | None:
|
||||
return dict(row) if row is not None else None
|
||||
|
||||
|
||||
async def get_user_by_id(uid: int) -> dict[str, Any] | None:
|
||||
row = await db.fetch_one('SELECT * FROM users WHERE id = ?', (uid,))
|
||||
return dict(row) if row is not None else None
|
||||
|
||||
|
||||
# ---------- billing ledger(只读对账) ----------
|
||||
|
||||
async def ledger_open_count() -> int:
|
||||
|
||||
Reference in new issue
Block a user