Skip to content

Commit

Permalink
resolve #28
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterain98 committed Feb 15, 2025
1 parent 23c3394 commit 8834b7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ def get_commit_hash_str():
def identify_user(request: Request) -> None:
# Extract headers
device_id = request.headers.get("x-hutao-device-id", "unknown-device")
reqable_id = request.headers.get("Reqable-Id", None)
user_agent = request.headers.get("User-Agent", "unknown-group")

# Assign to Apitally consumer
request.state.apitally_consumer = ApitallyConsumer(
identifier=device_id,
identifier=device_id if reqable_id is None else reqable_id,
name=device_id,
group=user_agent
group=user_agent if reqable_id is None else "Reqable",
)


Expand Down
3 changes: 3 additions & 0 deletions utils/dgp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ async def validate_client_is_updated(request: Request, user_agent: Annotated[str
if user_agent.startswith("PaimonsNotebook/"):
logger.info("Client is Paimon's Notebook, allowed.")
return True
if user_agent.startswith("Reqable/"):
logger.info("Client is Reqable, allowed.")
return True

allowed_user_agents = await redis_client.get("allowed_user_agents")
if allowed_user_agents:
Expand Down

0 comments on commit 8834b7e

Please sign in to comment.