1、增加消息推送的前台横幅显示

2、增加apikey的整体配额增加和修改记录显示
This commit is contained in:
2026-08-07 11:35:41 +08:00
parent f5d7cfadb4
commit 9538f6157d
16 changed files with 929 additions and 93 deletions
@@ -114,6 +114,50 @@ async def update_api_key(db: AsyncSession, key: ApiKey, **kwargs) -> ApiKey:
return key
async def adjust_quota(
db: AsyncSession,
key: ApiKey,
action: str,
quota_limit_delta: float | None = None,
quota_limit: float | None = None,
quota_cycle: str | None = None,
) -> tuple[ApiKey, dict]:
"""调整 API Key 配额。
返回 (更新后的 key, 变更详情 dict)。
action:
- adjust: 增加总额,quota_limit_delta 累加到当前 quota_limit
- reset_usage: 重置 quota_used 为 0
- set_limit: 直接设置 quota_limit
- change_cycle: 修改 quota_cycle
"""
old_limit = key.quota_limit
old_used = key.quota_used
old_cycle = key.quota_cycle
if action == "adjust":
delta = quota_limit_delta or 0
key.quota_limit = round((key.quota_limit or 0) + delta, 2)
elif action == "reset_usage":
key.quota_used = 0.0
elif action == "set_limit":
key.quota_limit = quota_limit # 允许设为 None(无限)
elif action == "change_cycle":
key.quota_cycle = quota_cycle # 允许设为 None(无限)
else:
raise ValueError(f"未知的调整操作: {action}")
await db.flush()
changes = {
"old_limit": old_limit, "new_limit": key.quota_limit,
"old_used": old_used, "new_used": key.quota_used,
"old_cycle": old_cycle, "new_cycle": key.quota_cycle,
}
return key, changes
async def delete_api_key(db: AsyncSession, key: ApiKey) -> None:
"""软删除 API Key。"""
key.deleted_at = datetime.now(timezone.utc)