Fix protocol URL parsing - action is host, session is path

This commit is contained in:
2025-12-30 06:08:29 -07:00
parent 9f36686ea1
commit 56a9496f98

View File

@@ -352,6 +352,8 @@ pub fn parse_protocol_url(url: &str) -> Result<(String, String, Option<String>)>
// guruconnect://view/SESSION_ID
// guruconnect://view/SESSION_ID?token=API_KEY
// guruconnect://connect/SESSION_ID?server=wss://...&token=API_KEY
//
// Note: In URL parsing, "view" becomes the host, SESSION_ID is the path
let url = url::Url::parse(url)
.map_err(|e| anyhow!("Invalid URL: {}", e))?;
@@ -360,17 +362,22 @@ pub fn parse_protocol_url(url: &str) -> Result<(String, String, Option<String>)>
return Err(anyhow!("Invalid scheme: expected guruconnect://"));
}
// The "action" (view/connect) is parsed as the host
let action = url.host_str()
.ok_or_else(|| anyhow!("Missing action in URL"))?;
// The session ID is the first path segment
let path = url.path().trim_start_matches('/');
let parts: Vec<&str> = path.split('/').collect();
let session_id = if path.is_empty() {
return Err(anyhow!("Missing session ID"));
} else {
path.split('/').next().unwrap_or("").to_string()
};
if parts.is_empty() {
return Err(anyhow!("Missing action in URL"));
if session_id.is_empty() {
return Err(anyhow!("Missing session ID"));
}
let action = parts[0];
let session_id = parts.get(1).map(|s| s.to_string())
.ok_or_else(|| anyhow!("Missing session ID"))?;
// Extract query parameters
let mut server = None;
let mut token = None;