use atrium_api::types::Collection; use reqwest::Url; use serde::Deserialize; #[derive(Deserialize, Debug)] struct ConstellationCountResponse { total: i64, } pub async fn fetch_constellation_count(target: &str) -> anyhow::Result { let base = std::env::var("CONSTELLATION_BASE_URL") .unwrap_or_else(|_| "https://constellation.microcosm.blue".to_string()); let endpoint = if base.ends_with('/') { format!("{}links/count", base) } else { format!("{}/links/count", base) }; // Build URL with query params in one go to avoid non-Send lifetimes let url = Url::parse_with_params( &endpoint, &[ ("target", target.to_string()), ("collection", atproto_api::sh::tangled::feed::Star::NSID.to_string()), ("path", ".subject".to_string()), ], )?; let resp = reqwest::Client::new() .get(url) .send() .await? .error_for_status()?; let parsed: ConstellationCountResponse = resp.json().await?; Ok(parsed.total) }