Update track_client_activity to handle missing rustdesk_id

- When rustdesk_id is not provided, update the most recent client for the API token
- This ensures user agents are updated even for clients not sending rustdesk_id
- Improves client reconnection handling
parent c2f2f165
......@@ -818,10 +818,11 @@ def track_client_activity(api_token, rustdesk_id=None):
ip_address = request.headers.get('X-Forwarded-For', request.remote_addr)
user_agent = request.headers.get('User-Agent')
# Check if client already exists
if rustdesk_id:
# If rustdesk_id is provided, use specific client
client = ClientActivity.query.filter_by(
api_token_id=api_token.id,
rustdesk_id=rustdesk_id or 'unknown'
rustdesk_id=rustdesk_id
).first()
if client:
......@@ -833,7 +834,27 @@ def track_client_activity(api_token, rustdesk_id=None):
# Create new client
client = ClientActivity(
api_token_id=api_token.id,
rustdesk_id=rustdesk_id or 'unknown',
rustdesk_id=rustdesk_id,
ip_address=ip_address,
user_agent=user_agent
)
db.session.add(client)
else:
# If no rustdesk_id provided, update the most recent client for this API token
client = ClientActivity.query.filter_by(
api_token_id=api_token.id
).order_by(ClientActivity.last_seen.desc()).first()
if client:
# Update most recent client
client.last_seen = datetime.utcnow()
client.ip_address = ip_address
client.user_agent = user_agent
else:
# Create new client with unknown rustdesk_id
client = ClientActivity(
api_token_id=api_token.id,
rustdesk_id='unknown',
ip_address=ip_address,
user_agent=user_agent
)
......
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