diff --git a/Cargo.lock b/Cargo.lock index e72d50f..8146820 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -302,7 +302,6 @@ checksum = "7637375b7309977caed8af4f877a7e8ccd6177695fe3b2dc587536904115ef29" dependencies = [ "anyhow", "atrium-api", - "atrium-xrpc-client", "chrono", "psl", "regex", @@ -764,21 +763,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1099,22 +1083,6 @@ dependencies = [ "webpki-roots 0.26.7", ] -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper 1.5.1", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - [[package]] name = "hyper-util" version = "0.1.10" @@ -1687,23 +1655,6 @@ dependencies = [ "jobserver", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework 2.11.1", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -1817,50 +1768,12 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -2256,14 +2169,12 @@ dependencies = [ "http-body-util", "hyper 1.5.1", "hyper-rustls 0.27.3", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", "mime_guess", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -2276,7 +2187,6 @@ dependencies = [ "serde_urlencoded", "sync_wrapper 1.0.2", "tokio", - "tokio-native-tls", "tokio-rustls 0.26.1", "tokio-util", "tower-service", @@ -2373,7 +2283,7 @@ dependencies = [ "openssl-probe", "rustls-pki-types", "schannel", - "security-framework 3.0.1", + "security-framework", ] [[package]] @@ -2455,19 +2365,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags 2.6.0", - "core-foundation 0.9.4", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - [[package]] name = "security-framework" version = "3.0.1" @@ -2950,16 +2847,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.24.1" @@ -3222,12 +3109,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version-compare" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index a05531d..4f87e84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,13 @@ description = "Synchronizes posts from Mastodon to Bluesky and back." edition = "2021" [dependencies] +bsky-sdk = { version = ">=0.1", default-features = false, features = [ + "rich-text", +] } anyhow = ">=1" -atrium-xrpc-client = ">=0.1" -bsky-sdk = ">=0.1" +atrium-xrpc-client = { version = ">=0.1", default-features = false, features = [ + "reqwest", +] } # Switching off default features removes a dependency to the "time" crate that # contains a potential security issue. # See https://github.com/time-rs/time/issues/293 diff --git a/Dockerfile b/Dockerfile index 2244a22..c3caa7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN cargo vendor >> /code/.cargo/config.toml FROM rust:1-alpine AS builder -RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static +RUN apk add --no-cache musl-dev ENV USER=root WORKDIR /code diff --git a/src/bluesky_video.rs b/src/bluesky_video.rs index 0e11ca2..29e2169 100644 --- a/src/bluesky_video.rs +++ b/src/bluesky_video.rs @@ -1,16 +1,14 @@ +use crate::BskyAgent; use anyhow::{bail, Result}; use atrium_xrpc_client::reqwest::ReqwestClient; -use bsky_sdk::{ - api::{ - client::AtpServiceClient, - types::{string::Did, BlobRef}, - xrpc::{ - http::{uri::Builder, Request, Response}, - types::AuthorizationToken, - HttpClient, XrpcClient, - }, +use bsky_sdk::api::{ + client::AtpServiceClient, + types::{string::Did, BlobRef}, + xrpc::{ + http::{uri::Builder, Request, Response}, + types::AuthorizationToken, + HttpClient, XrpcClient, }, - BskyAgent, }; use serde::Serialize; use std::result::Result::Ok; diff --git a/src/delete_favs.rs b/src/delete_favs.rs index 02398bb..69d29bf 100644 --- a/src/delete_favs.rs +++ b/src/delete_favs.rs @@ -6,7 +6,6 @@ use bsky_sdk::api::types::string::Nsid; use bsky_sdk::api::types::string::RecordKey; use bsky_sdk::api::types::LimitedNonZeroU8; use bsky_sdk::api::types::TryFromUnknown; -use bsky_sdk::BskyAgent; use chrono::prelude::*; use chrono::Duration; use megalodon::error::Kind; @@ -17,6 +16,7 @@ use tokio::fs; use crate::cache_file; use crate::config::*; +use crate::BskyAgent; // Delete old favourites of this account that are older than 90 days. pub async fn mastodon_delete_older_favs( diff --git a/src/delete_posts.rs b/src/delete_posts.rs index 357f0a2..33e9b28 100644 --- a/src/delete_posts.rs +++ b/src/delete_posts.rs @@ -1,7 +1,6 @@ use anyhow::Result; use bsky_sdk::api::types::LimitedNonZeroU8; use bsky_sdk::api::types::TryFromUnknown; -use bsky_sdk::BskyAgent; use chrono::prelude::*; use chrono::Duration; use std::collections::BTreeMap; @@ -10,6 +9,7 @@ use crate::cache_file; use crate::load_dates_from_cache; use crate::remove_date_from_cache; use crate::save_dates_to_cache; +use crate::BskyAgent; use crate::DatePostList; // Delete old posts of this account that are older than 90 days. diff --git a/src/lib.rs b/src/lib.rs index 9089694..dbb47d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,9 @@ use anyhow::Context; use anyhow::Result; +use atrium_xrpc_client::reqwest::ReqwestClient; use bsky_sdk::agent::config::FileStore; +use bsky_sdk::agent::BskyAgentBuilder; use bsky_sdk::api::types::LimitedNonZeroU8; -use bsky_sdk::BskyAgent; use delete_posts::bluesky_delete_older_posts; use log::debug; use megalodon::generator; @@ -29,6 +30,8 @@ mod post; mod registration; mod sync; +type BskyAgent = bsky_sdk::BskyAgent; + pub async fn run(args: Args) -> Result<()> { debug!("running with args {:?}", args); @@ -97,21 +100,27 @@ pub async fn run(args: Args) -> Result<()> { match bsky_sdk::agent::config::Config::load(&FileStore::new("bluesky-auth-cache.json")) .await { - Ok(bsky_config) => match BskyAgent::builder().config(bsky_config).build().await { - Ok(agent) => { - // Save the session in case it was refreshed. - agent - .to_config() - .await - .save(&FileStore::new("bluesky-auth-cache.json")) - .await?; - agent - } - Err(_) => { - get_new_bluesky_agent(&config.bluesky.email, &config.bluesky.app_password) - .await? + Ok(bsky_config) => { + match BskyAgentBuilder::new(ReqwestClient::new("https://bsky.social")) + .config(bsky_config) + .build() + .await + { + Ok(agent) => { + // Save the session in case it was refreshed. + agent + .to_config() + .await + .save(&FileStore::new("bluesky-auth-cache.json")) + .await?; + agent + } + Err(_) => { + get_new_bluesky_agent(&config.bluesky.email, &config.bluesky.app_password) + .await? + } } - }, + } Err(_) => { get_new_bluesky_agent(&config.bluesky.email, &config.bluesky.app_password).await? } @@ -230,7 +239,9 @@ fn cache_file(name: &str) -> String { } async fn get_new_bluesky_agent(email: &str, app_password: &str) -> Result { - let agent = BskyAgent::builder().build().await?; + let agent = BskyAgentBuilder::new(ReqwestClient::new("https://bsky.social")) + .build() + .await?; let _session = agent.login(email, app_password).await?; agent .to_config() diff --git a/src/post.rs b/src/post.rs index a648c1e..a303d26 100644 --- a/src/post.rs +++ b/src/post.rs @@ -1,10 +1,10 @@ use crate::bluesky_richtext::get_rich_text; use crate::bluesky_video::bluesky_upload_video; use crate::sync::NewStatus; +use crate::BskyAgent; use anyhow::bail; use anyhow::Context; use anyhow::Result; -use bsky_sdk::BskyAgent; use image_compressor::compressor::Compressor; use image_compressor::Factor; use megalodon::megalodon::PostStatusOutput;