Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ai company
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
ai company
Commits
a6f8f399
Commit
a6f8f399
authored
Apr 04, 2026
by
Vũ Hoàng Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix identity_key parsing to check raw key in Redis
parent
665070e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
limit_route.py
backend/api/limit_route.py
+20
-5
No files found.
backend/api/limit_route.py
View file @
a6f8f399
...
@@ -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
"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment