1、增加消息推送的前台横幅显示
2、增加apikey的整体配额增加和修改记录显示
This commit is contained in:
@@ -17,6 +17,7 @@ from app.schemas.admin_api.api_key import (
|
||||
ApiKeyCreateResponse,
|
||||
ApiKeyListItem,
|
||||
ApiKeyListOut,
|
||||
ApiKeyQuotaAdjustRequest,
|
||||
ApiKeyRevealResponse,
|
||||
ApiKeyResponse,
|
||||
ApiKeyUpdateRequest,
|
||||
@@ -388,3 +389,47 @@ async def list_all_usage(
|
||||
"total": total,
|
||||
"items": items,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/{key_id}/quota-adjust", response_model=ApiKeyListItem, summary="调整 API Key 配额")
|
||||
async def quota_adjust(
|
||||
req: ApiKeyQuotaAdjustRequest,
|
||||
key_id: str = Path(..., description="API Key ID"),
|
||||
admin: User = Depends(get_admin_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> ApiKeyListItem:
|
||||
"""调整 API Key 配额(增加总额/重置已用/设置限额/修改周期)。"""
|
||||
key = await key_service.get_api_key(db, key_id)
|
||||
if not key:
|
||||
raise HTTPException(status_code=404, detail="API Key 不存在")
|
||||
|
||||
key, changes = await key_service.adjust_quota(
|
||||
db,
|
||||
key,
|
||||
action=req.action,
|
||||
quota_limit_delta=req.quota_limit_delta,
|
||||
quota_limit=req.quota_limit,
|
||||
quota_cycle=req.quota_cycle,
|
||||
)
|
||||
|
||||
# 审计日志
|
||||
try:
|
||||
from app.services.operation_log import log_operation
|
||||
await log_operation(
|
||||
db=db,
|
||||
user_id=str(admin.id),
|
||||
username=str(admin.username),
|
||||
action=f"quota_adjust:{req.action}",
|
||||
method="POST",
|
||||
path=f"/admin/api-keys/{key_id}/quota-adjust",
|
||||
detail=json.dumps(
|
||||
{**changes, "reason": req.reason},
|
||||
ensure_ascii=False,
|
||||
default=str,
|
||||
),
|
||||
)
|
||||
except Exception as log_exc:
|
||||
logger.warning("配额调整审计日志记录失败: %s", log_exc)
|
||||
|
||||
await db.commit()
|
||||
return _key_to_list_item(key)
|
||||
|
||||
Reference in New Issue
Block a user