From b5156ecfbf798ed42acb3eb537e487c607d759c2 Mon Sep 17 00:00:00 2001 From: Aleksei Voronov Date: Sun, 15 Oct 2023 20:08:56 +0200 Subject: [PATCH] Remove unnecessary parameterization of Bluesky hosts Really isn't necessary. I'm never going to use anything other than proper, real, production Bluesky for this. --- src/bin/force_profile_country.rs | 2 +- src/bin/publish_feed.rs | 2 +- src/bin/who_am_i.rs | 2 +- src/main.rs | 2 +- src/services/bluesky/client.rs | 19 +++++++++++-------- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/bin/force_profile_country.rs b/src/bin/force_profile_country.rs index e7aec15..1062901 100644 --- a/src/bin/force_profile_country.rs +++ b/src/bin/force_profile_country.rs @@ -28,7 +28,7 @@ async fn main() -> Result<()> { let database_url = env::var("DATABASE_URL").context("DATABASE_URL environment variable must be set")?; - let bluesky = Bluesky::unauthenticated("https://bsky.social"); + let bluesky = Bluesky::unauthenticated(); let database = Database::connect(&database_url).await?; for handle in &args.handle { diff --git a/src/bin/publish_feed.rs b/src/bin/publish_feed.rs index baabc06..9ecd410 100644 --- a/src/bin/publish_feed.rs +++ b/src/bin/publish_feed.rs @@ -43,7 +43,7 @@ async fn main() -> Result<()> { println!("Logging in"); - let bluesky = Bluesky::login("https://bsky.social", &handle, &password).await?; + let bluesky = Bluesky::login(&handle, &password).await?; let mut avatar = None; if let Some(path) = args.avatar_filename { diff --git a/src/bin/who_am_i.rs b/src/bin/who_am_i.rs index df37704..c612e8f 100644 --- a/src/bin/who_am_i.rs +++ b/src/bin/who_am_i.rs @@ -17,7 +17,7 @@ async fn main() -> Result<()> { let password = env::var("PUBLISHER_BLUESKY_PASSWORD") .context("PUBLISHER_BLUESKY_PASSWORD environment variable must be set")?; - let bluesky = Bluesky::login("https://bsky.social", &handle, &password).await?; + let bluesky = Bluesky::login(&handle, &password).await?; let session = bluesky .session() .ok_or_else(|| anyhow!("Could not log in"))?; diff --git a/src/main.rs b/src/main.rs index 44be1ad..31f1a4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ async fn main() -> Result<()> { info!("Initializing service clients"); let ai = Arc::new(AI::new(&config.chat_gpt_api_key, "https://api.openai.com")); - let bluesky = Arc::new(Bluesky::unauthenticated("https://bsky.social")); + let bluesky = Arc::new(Bluesky::unauthenticated()); let database = Arc::new(Database::connect(&config.database_url).await?); info!("Initializing language detector"); diff --git a/src/services/bluesky/client.rs b/src/services/bluesky/client.rs index 4907c98..6b6c778 100644 --- a/src/services/bluesky/client.rs +++ b/src/services/bluesky/client.rs @@ -23,17 +23,20 @@ pub struct Bluesky { } impl Bluesky { - pub fn unauthenticated(host: &str) -> Self { + const XRPC_HOST: &str = "https://bsky.social"; + const FIREHOSE_HOST: &str = "wss://bsky.social"; + + pub fn unauthenticated() -> Self { Self { - client: AtpServiceClient::new(AuthenticateableXrpcClient::new(host.to_owned())), + client: AtpServiceClient::new(AuthenticateableXrpcClient::new(Self::XRPC_HOST.to_owned())), session: None, } } - pub async fn login(host: &str, handle: &str, password: &str) -> Result { + pub async fn login(handle: &str, password: &str) -> Result { use atrium_api::com::atproto::server::create_session::Input; - let client = AtpServiceClient::new(AuthenticateableXrpcClient::new(host.to_owned())); + let client = AtpServiceClient::new(AuthenticateableXrpcClient::new(Self::XRPC_HOST.to_owned())); let result = client .service @@ -49,7 +52,7 @@ impl Bluesky { let session = Arc::new(Mutex::new(result.try_into()?)); let authenticated_client = AtpServiceClient::new(AuthenticateableXrpcClient::with_session( - host.to_owned(), + Self::XRPC_HOST.to_owned(), session.clone(), )); @@ -178,10 +181,10 @@ impl Bluesky { ) -> Result<()> { let url = match cursor { Some(cursor) => format!( - "wss://bsky.social/xrpc/com.atproto.sync.subscribeRepos?cursor={}", - cursor + "{}/xrpc/com.atproto.sync.subscribeRepos?cursor={}", + Self::FIREHOSE_HOST, cursor ), - None => "wss://bsky.social/xrpc/com.atproto.sync.subscribeRepos".to_owned(), + None => format!("{}/xrpc/com.atproto.sync.subscribeRepos", Self::FIREHOSE_HOST), }; let (mut stream, _) = connect_async(url).await?;