Commit 00dffd6a authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

Fix identity_key parsing to check raw key in Redis

parent 2eac208c
...@@ -12,8 +12,16 @@ async def get_limit_info(identity_key: str): ...@@ -12,8 +12,16 @@ async def get_limit_info(identity_key: str):
identity_key format: 'device:id' hoặc 'user:id' identity_key format: 'device:id' hoặc 'user:id'
""" """
is_authenticated = identity_key.startswith("user:") is_authenticated = identity_key.startswith("user:")
info = await message_limit_service.get_usage(identity_key, is_authenticated)
return {"status": "success", "info": info} # Bỏ prefix để lấy raw ID query xuống Redis
real_key = identity_key
if identity_key.startswith("user:"):
real_key = identity_key.split("user:", 1)[1]
elif identity_key.startswith("device:"):
real_key = identity_key.split("device:", 1)[1]
info = await message_limit_service.get_usage(real_key, is_authenticated)
return {"status": "success", "info": info, "real_key": real_key}
@router.post("/reset", summary="Reset limit (thêm limit / cho phép nhắn lại) cho 1 ID") @router.post("/reset", summary="Reset limit (thêm limit / cho phép nhắn lại) cho 1 ID")
async def reset_limit(payload: dict = Body(...)): async def reset_limit(payload: dict = Body(...)):
...@@ -21,8 +29,15 @@ async def reset_limit(payload: dict = Body(...)): ...@@ -21,8 +29,15 @@ async def reset_limit(payload: dict = Body(...)):
if not identity_key: if not identity_key:
return {"status": "error", "message": "Missing identity_key"} return {"status": "error", "message": "Missing identity_key"}
success = await message_limit_service.reset(identity_key) # Bỏ prefix để reset đúng raw ID trên Redis
real_key = identity_key
if identity_key.startswith("user:"):
real_key = identity_key.split("user:", 1)[1]
elif identity_key.startswith("device:"):
real_key = identity_key.split("device:", 1)[1]
success = await message_limit_service.reset(real_key)
if success: if success:
return {"status": "success", "message": f"Đã reset/thêm limit cho {identity_key} (về 0)"} return {"status": "success", "message": f"Đã reset/thêm limit cho {real_key} (về 0)"}
else: else:
return {"status": "error", "message": "Có lỗi khi reset limit"} return {"status": "error", "message": "Có lỗi khi reset limit trên Redis"}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment