diff --git a/src/activity_queue.rs b/src/activity_queue.rs index 8785971..f81518d 100644 --- a/src/activity_queue.rs +++ b/src/activity_queue.rs @@ -11,6 +11,7 @@ use crate::{ use futures_core::Future; +use crate::url::Url; use reqwest_middleware::ClientWithMiddleware; use serde::Serialize; use std::{ @@ -26,7 +27,6 @@ use tokio::{ task::{JoinHandle, JoinSet}, }; use tracing::{info, warn}; -use crate::url::Url; /// Send a new activity to the given inboxes with automatic retry on failure. Alternatively you /// can implement your own queue and then send activities using [[crate::activity_sending::SendActivityTask]]. diff --git a/src/activity_sending.rs b/src/activity_sending.rs index 7a35a34..83da26a 100644 --- a/src/activity_sending.rs +++ b/src/activity_sending.rs @@ -8,6 +8,7 @@ use crate::{ http_signatures::sign_request, reqwest_shim::ResponseExt, traits::{ActivityHandler, Actor}, + url::Url, FEDERATION_CONTENT_TYPE, }; use bytes::Bytes; @@ -27,7 +28,6 @@ use std::{ time::{Duration, SystemTime}, }; use tracing::debug; -use crate::url::Url; #[derive(Clone, Debug)] /// All info needed to sign and send one activity to one inbox. You should generally use diff --git a/src/actix_web/inbox.rs b/src/actix_web/inbox.rs index dbd1984..e4d20fc 100644 --- a/src/actix_web/inbox.rs +++ b/src/actix_web/inbox.rs @@ -54,12 +54,12 @@ mod test { fetch::object_id::ObjectId, http_signatures::sign_request, traits::tests::{DbConnection, DbUser, Follow, DB_USER_KEYPAIR}, + url::Url, }; use actix_web::test::TestRequest; use reqwest::Client; use reqwest_middleware::ClientWithMiddleware; use serde_json::json; - use crate::url::Url; #[tokio::test] async fn test_receive_activity() { diff --git a/src/config.rs b/src/config.rs index d3c3608..2e23c41 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,6 +19,7 @@ use crate::{ error::Error, protocol::verification::verify_domains_match, traits::{ActivityHandler, Actor}, + url::Url, }; use async_trait::async_trait; use derive_builder::Builder; @@ -35,7 +36,6 @@ use std::{ }, time::Duration, }; -use crate::url::Url; /// Configuration for this library, with various federation related settings #[derive(Builder, Clone)] diff --git a/src/error.rs b/src/error.rs index edaed0f..b14863e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ //! Error messages returned by this library -use crate::fetch::webfinger::WebFingerError; +use crate::{fetch::webfinger::WebFingerError, url::Url}; use http_signature_normalization_reqwest::SignError; use rsa::{ errors::Error as RsaError, @@ -8,7 +8,6 @@ use rsa::{ }; use std::string::FromUtf8Error; use tokio::task::JoinError; -use crate::url::Url; /// Error messages returned by this library #[derive(thiserror::Error, Debug)] diff --git a/src/fetch/collection_id.rs b/src/fetch/collection_id.rs index 7a58278..ea9dda2 100644 --- a/src/fetch/collection_id.rs +++ b/src/fetch/collection_id.rs @@ -1,10 +1,10 @@ -use crate::{config::Data, error::Error, fetch::fetch_object_http, traits::Collection}; +use crate::{config::Data, error::Error, fetch::fetch_object_http, traits::Collection, url::Url}; use serde::{Deserialize, Serialize}; use std::{ fmt::{Debug, Display, Formatter}, - marker::PhantomData, str::FromStr, + marker::PhantomData, + str::FromStr, }; -use crate::url::Url; /// Typed wrapper for Activitypub Collection ID which helps with dereferencing. #[derive(Serialize, Deserialize)] diff --git a/src/fetch/mod.rs b/src/fetch/mod.rs index eee5899..738384e 100644 --- a/src/fetch/mod.rs +++ b/src/fetch/mod.rs @@ -8,6 +8,7 @@ use crate::{ extract_id, http_signatures::sign_request, reqwest_shim::ResponseExt, + url::Url, FEDERATION_CONTENT_TYPE, }; use bytes::Bytes; @@ -15,7 +16,6 @@ use http::{HeaderValue, StatusCode}; use serde::de::DeserializeOwned; use std::sync::atomic::Ordering; use tracing::info; -use crate::url::Url; /// Typed wrapper for collection IDs pub mod collection_id; diff --git a/src/fetch/object_id.rs b/src/fetch/object_id.rs index b05b59d..7334b23 100644 --- a/src/fetch/object_id.rs +++ b/src/fetch/object_id.rs @@ -1,4 +1,4 @@ -use crate::{config::Data, error::Error, fetch::fetch_object_http, traits::Object}; +use crate::{config::Data, error::Error, fetch::fetch_object_http, traits::Object, url::Url}; use chrono::{DateTime, Duration as ChronoDuration, Utc}; use serde::{Deserialize, Serialize}; use std::{ @@ -6,7 +6,6 @@ use std::{ marker::PhantomData, str::FromStr, }; -use crate::url::Url; impl FromStr for ObjectId where diff --git a/src/fetch/webfinger.rs b/src/fetch/webfinger.rs index 80100bb..b61b72b 100644 --- a/src/fetch/webfinger.rs +++ b/src/fetch/webfinger.rs @@ -3,6 +3,7 @@ use crate::{ error::Error, fetch::{fetch_object_http_with_accept, object_id::ObjectId}, traits::{Actor, Object}, + url::Url, FEDERATION_CONTENT_TYPE, }; use http::HeaderValue; @@ -12,7 +13,6 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, fmt::Display, str::FromStr}; use tracing::debug; -use crate::url::Url; /// Errors relative to webfinger handling #[derive(thiserror::Error, Debug)] diff --git a/src/http_signatures.rs b/src/http_signatures.rs index 91a759f..94fbb41 100644 --- a/src/http_signatures.rs +++ b/src/http_signatures.rs @@ -11,6 +11,7 @@ use crate::{ fetch::object_id::ObjectId, protocol::public_key::main_key_id, traits::{Actor, Object}, + url::Url, }; use base64::{engine::general_purpose::STANDARD as Base64, Engine}; use bytes::Bytes; @@ -32,7 +33,6 @@ use serde::Deserialize; use sha2::{Digest, Sha256}; use std::{collections::BTreeMap, fmt::Debug, str::FromStr, time::Duration}; use tracing::debug; -use crate::url::Url; /// A private/public key pair used for HTTP signatures #[derive(Debug, Clone)] @@ -287,7 +287,8 @@ pub mod test { use rsa::{pkcs1::DecodeRsaPrivateKey, pkcs8::DecodePrivateKey}; use std::str::FromStr; - static ACTOR_ID: Lazy = Lazy::new(|| Url::from_str("https://example.com/u/alice").unwrap()); + static ACTOR_ID: Lazy = + Lazy::new(|| Url::from_str("https://example.com/u/alice").unwrap()); static INBOX_URL: Lazy = Lazy::new(|| Url::from_str("https://example.com/u/alice/inbox").unwrap()); diff --git a/src/lib.rs b/src/lib.rs index 9a2abf7..f60d85e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,8 +33,8 @@ use crate::{ }; pub use activitystreams_kinds as kinds; -use serde::{de::DeserializeOwned, Deserialize}; use crate::url::Url; +use serde::{de::DeserializeOwned, Deserialize}; /// Mime type for Activitypub data, used for `Accept` and `Content-Type` HTTP headers pub const FEDERATION_CONTENT_TYPE: &str = "application/activity+json"; diff --git a/src/protocol/context.rs b/src/protocol/context.rs index 06e429e..e3003e3 100644 --- a/src/protocol/context.rs +++ b/src/protocol/context.rs @@ -19,10 +19,9 @@ //! Ok::<(), serde_json::error::Error>(()) //! ``` -use crate::{config::Data, traits::ActivityHandler}; +use crate::{config::Data, traits::ActivityHandler, url::Url}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use crate::url::Url; /// Default context used in Activitypub const DEFAULT_CONTEXT: &str = "https://www.w3.org/ns/activitystreams"; diff --git a/src/protocol/helpers.rs b/src/protocol/helpers.rs index cb44680..4410bf6 100644 --- a/src/protocol/helpers.rs +++ b/src/protocol/helpers.rs @@ -120,8 +120,7 @@ where mod tests { #[test] fn deserialize_one_multiple_values() { - use crate::protocol::helpers::deserialize_one; - use crate::url::Url; + use crate::{protocol::helpers::deserialize_one, url::Url}; #[derive(serde::Deserialize)] struct Note { #[serde(deserialize_with = "deserialize_one")] diff --git a/src/protocol/public_key.rs b/src/protocol/public_key.rs index fc7c31c..3c4889f 100644 --- a/src/protocol/public_key.rs +++ b/src/protocol/public_key.rs @@ -1,7 +1,7 @@ //! Struct which is used to federate actor key for HTTP signatures -use serde::{Deserialize, Serialize}; use crate::url::Url; +use serde::{Deserialize, Serialize}; /// Public key of actors which is used for HTTP signatures. /// diff --git a/src/protocol/verification.rs b/src/protocol/verification.rs index a2392fd..e747ec8 100644 --- a/src/protocol/verification.rs +++ b/src/protocol/verification.rs @@ -1,7 +1,6 @@ //! Verify that received data is valid -use crate::error::Error; -use crate::url::Url; +use crate::{error::Error, url::Url}; /// Check that both urls have the same domain. If not, return UrlVerificationError. /// diff --git a/src/traits.rs b/src/traits.rs index d5613a9..c42f5ca 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,11 +1,10 @@ //! Traits which need to be implemented for federated data types -use crate::{config::Data, protocol::public_key::PublicKey}; +use crate::{config::Data, protocol::public_key::PublicKey, url::Url}; use async_trait::async_trait; use chrono::{DateTime, Utc}; use serde::Deserialize; use std::{fmt::Debug, ops::Deref}; -use crate::url::Url; /// Helper for converting between database structs and federated protocol structs. /// diff --git a/src/url.rs b/src/url.rs index ea6ea72..18c0b77 100644 --- a/src/url.rs +++ b/src/url.rs @@ -1,6 +1,10 @@ //! Wrapper for `url::Url` type. -use std::{fmt::{Display, Formatter}, ops::Deref, str::FromStr}; +use std::{ + fmt::{Display, Formatter}, + ops::Deref, + str::FromStr, +}; use serde::{Deserialize, Serialize}; @@ -43,4 +47,4 @@ impl FromStr for Url { fn from_str(s: &str) -> Result { Ok(url::Url::from_str(s).map(Url).unwrap()) } -} \ No newline at end of file +}