From 6945ded96322187d6e5c8a90ce3afe295b2ca8c4 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 12 Feb 2023 23:07:19 +0000 Subject: [PATCH] Group imports --- src/activitypub/actors/types.rs | 18 +++--- src/activitypub/authentication.rs | 6 +- src/activitypub/builders/accept_follow.rs | 6 +- src/activitypub/builders/announce.rs | 8 ++- src/activitypub/builders/delete_note.rs | 8 ++- src/activitypub/builders/delete_person.rs | 6 +- src/activitypub/builders/follow.rs | 6 +- src/activitypub/builders/like.rs | 8 ++- src/activitypub/builders/undo_announce.rs | 8 ++- src/activitypub/builders/undo_follow.rs | 6 +- src/activitypub/builders/undo_like.rs | 8 ++- src/activitypub/builders/update_person.rs | 6 +- src/activitypub/fetcher/fetchers.rs | 6 +- src/activitypub/fetcher/helpers.rs | 16 ++--- src/activitypub/views.rs | 8 ++- src/atom/feeds.rs | 6 +- src/atom/views.rs | 6 +- src/config/loader.rs | 12 ++-- src/errors.rs | 5 +- src/ethereum/identity.rs | 10 +-- src/ethereum/subscriptions.rs | 56 +++++++++-------- src/job_queue/periodic_tasks.rs | 12 ++-- src/json_signatures/verify.rs | 6 +- src/mastodon_api/accounts/views.rs | 76 ++++++++++++----------- src/mastodon_api/directory/views.rs | 6 +- src/mastodon_api/markers/views.rs | 10 +-- src/mastodon_api/media/views.rs | 6 +- src/mastodon_api/notifications/types.rs | 8 ++- src/mastodon_api/notifications/views.rs | 6 +- src/mastodon_api/oauth/auth.rs | 6 +- src/mastodon_api/oauth/views.rs | 24 +++---- src/mastodon_api/search/helpers.rs | 30 ++++----- src/mastodon_api/search/types.rs | 8 ++- src/mastodon_api/statuses/views.rs | 50 ++++++++------- src/mastodon_api/subscriptions/types.rs | 6 +- src/mastodon_api/subscriptions/views.rs | 16 +++-- src/mastodon_api/timelines/views.rs | 6 +- src/models/attachments/queries.rs | 6 +- src/models/notifications/queries.rs | 16 ++--- src/models/oauth/queries.rs | 6 +- src/models/posts/emojis.rs | 6 +- src/models/posts/helpers.rs | 22 ++++--- src/models/posts/mentions.rs | 6 +- src/models/posts/queries.rs | 50 ++++++++------- src/models/profiles/queries.rs | 14 +++-- src/models/profiles/types.rs | 6 +- src/models/reactions/queries.rs | 10 +-- src/models/relationships/queries.rs | 14 +++-- src/models/subscriptions/queries.rs | 8 ++- src/models/users/queries.rs | 6 +- src/nodeinfo/helpers.rs | 6 +- src/webfinger/views.rs | 12 ++-- 52 files changed, 403 insertions(+), 280 deletions(-) diff --git a/src/activitypub/actors/types.rs b/src/activitypub/actors/types.rs index e20eb3e..4a61e8f 100644 --- a/src/activitypub/actors/types.rs +++ b/src/activitypub/actors/types.rs @@ -23,14 +23,18 @@ use crate::activitypub::{ use crate::config::Instance; use crate::errors::ValidationError; use crate::media::get_file_url; -use crate::models::profiles::types::{ - ExtraField, - IdentityProof, - PaymentOption, +use crate::models::{ + profiles::types::{ + ExtraField, + IdentityProof, + PaymentOption, + }, + users::types::User, +}; +use crate::utils::{ + crypto_rsa::{deserialize_private_key, get_public_key_pem}, + urls::get_hostname, }; -use crate::models::users::types::User; -use crate::utils::crypto_rsa::{deserialize_private_key, get_public_key_pem}; -use crate::utils::urls::get_hostname; use crate::webfinger::types::ActorAddress; use super::attachments::{ attach_extra_field, diff --git a/src/activitypub/authentication.rs b/src/activitypub/authentication.rs index 5aec0c3..8e2061d 100644 --- a/src/activitypub/authentication.rs +++ b/src/activitypub/authentication.rs @@ -17,8 +17,10 @@ use crate::json_signatures::verify::{ JsonSignatureVerificationError as JsonSignatureError, JsonSigner, }; -use crate::models::profiles::queries::get_profile_by_remote_actor_id; -use crate::models::profiles::types::DbActorProfile; +use crate::models::{ + profiles::queries::get_profile_by_remote_actor_id, + profiles::types::DbActorProfile, +}; use crate::utils::crypto_rsa::deserialize_public_key; use super::fetcher::helpers::get_or_import_profile_by_actor_id; use super::receiver::HandlerError; diff --git a/src/activitypub/builders/accept_follow.rs b/src/activitypub/builders/accept_follow.rs index 8651709..fd5b28b 100644 --- a/src/activitypub/builders/accept_follow.rs +++ b/src/activitypub/builders/accept_follow.rs @@ -8,8 +8,10 @@ use crate::activitypub::{ vocabulary::ACCEPT, }; use crate::config::Instance; -use crate::models::profiles::types::DbActorProfile; -use crate::models::users::types::User; +use crate::models::{ + profiles::types::DbActorProfile, + users::types::User, +}; use crate::utils::id::generate_ulid; #[derive(Serialize)] diff --git a/src/activitypub/builders/announce.rs b/src/activitypub/builders/announce.rs index 823cadf..f71c4bb 100644 --- a/src/activitypub/builders/announce.rs +++ b/src/activitypub/builders/announce.rs @@ -11,9 +11,11 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::types::Post; -use crate::models::relationships::queries::get_followers; -use crate::models::users::types::User; +use crate::models::{ + posts::types::Post, + relationships::queries::get_followers, + users::types::User, +}; #[derive(Serialize)] struct Announce { diff --git a/src/activitypub/builders/delete_note.rs b/src/activitypub/builders/delete_note.rs index 8f11ecb..37901f6 100644 --- a/src/activitypub/builders/delete_note.rs +++ b/src/activitypub/builders/delete_note.rs @@ -8,9 +8,11 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::helpers::add_related_posts; -use crate::models::posts::types::Post; -use crate::models::users::types::User; +use crate::models::{ + posts::helpers::add_related_posts, + posts::types::Post, + users::types::User, +}; use super::create_note::{ build_note, get_note_recipients, diff --git a/src/activitypub/builders/delete_person.rs b/src/activitypub/builders/delete_person.rs index ef85d98..f0bc91f 100644 --- a/src/activitypub/builders/delete_person.rs +++ b/src/activitypub/builders/delete_person.rs @@ -10,8 +10,10 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::relationships::queries::{get_followers, get_following}; -use crate::models::users::types::User; +use crate::models::{ + relationships::queries::{get_followers, get_following}, + users::types::User, +}; #[derive(Serialize)] struct DeletePerson { diff --git a/src/activitypub/builders/follow.rs b/src/activitypub/builders/follow.rs index b8b123f..832e3c2 100644 --- a/src/activitypub/builders/follow.rs +++ b/src/activitypub/builders/follow.rs @@ -9,8 +9,10 @@ use crate::activitypub::{ vocabulary::FOLLOW, }; use crate::config::Instance; -use crate::models::profiles::types::DbActorProfile; -use crate::models::users::types::User; +use crate::models::{ + profiles::types::DbActorProfile, + users::types::User, +}; #[derive(Serialize)] pub(super) struct Follow { diff --git a/src/activitypub/builders/like.rs b/src/activitypub/builders/like.rs index 361dd7c..701ff1a 100644 --- a/src/activitypub/builders/like.rs +++ b/src/activitypub/builders/like.rs @@ -11,9 +11,11 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::types::{Post, Visibility}; -use crate::models::profiles::types::DbActorProfile; -use crate::models::users::types::User; +use crate::models::{ + posts::types::{Post, Visibility}, + profiles::types::DbActorProfile, + users::types::User, +}; #[derive(Serialize)] struct Like { diff --git a/src/activitypub/builders/undo_announce.rs b/src/activitypub/builders/undo_announce.rs index 1ed678d..6b64a3d 100644 --- a/src/activitypub/builders/undo_announce.rs +++ b/src/activitypub/builders/undo_announce.rs @@ -10,9 +10,11 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::types::Post; -use crate::models::profiles::types::DbActorProfile; -use crate::models::users::types::User; +use crate::models::{ + posts::types::Post, + profiles::types::DbActorProfile, + users::types::User, +}; use super::announce::get_announce_recipients; #[derive(Serialize)] diff --git a/src/activitypub/builders/undo_follow.rs b/src/activitypub/builders/undo_follow.rs index 0706ae7..0fc1261 100644 --- a/src/activitypub/builders/undo_follow.rs +++ b/src/activitypub/builders/undo_follow.rs @@ -9,8 +9,10 @@ use crate::activitypub::{ vocabulary::{FOLLOW, UNDO}, }; use crate::config::Instance; -use crate::models::profiles::types::DbActorProfile; -use crate::models::users::types::User; +use crate::models::{ + profiles::types::DbActorProfile, + users::types::User, +}; use super::follow::Follow; #[derive(Serialize)] diff --git a/src/activitypub/builders/undo_like.rs b/src/activitypub/builders/undo_like.rs index 1181cb8..d0e6ba5 100644 --- a/src/activitypub/builders/undo_like.rs +++ b/src/activitypub/builders/undo_like.rs @@ -9,9 +9,11 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::types::{Post, Visibility}; -use crate::models::profiles::types::DbActorProfile; -use crate::models::users::types::User; +use crate::models::{ + posts::types::{Post, Visibility}, + profiles::types::DbActorProfile, + users::types::User, +}; use super::like::{ get_like_audience, get_like_recipients, diff --git a/src/activitypub/builders/update_person.rs b/src/activitypub/builders/update_person.rs index 88d2657..dacba4a 100644 --- a/src/activitypub/builders/update_person.rs +++ b/src/activitypub/builders/update_person.rs @@ -11,8 +11,10 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError, DatabaseTypeError}; -use crate::models::relationships::queries::get_followers; -use crate::models::users::types::User; +use crate::models::{ + relationships::queries::get_followers, + users::types::User, +}; use crate::utils::id::generate_ulid; #[derive(Serialize)] diff --git a/src/activitypub/fetcher/fetchers.rs b/src/activitypub/fetcher/fetchers.rs index 6b43780..65ff303 100644 --- a/src/activitypub/fetcher/fetchers.rs +++ b/src/activitypub/fetcher/fetchers.rs @@ -16,8 +16,10 @@ use crate::http_signatures::create::{ HttpSignatureError, }; use crate::media::{save_file, SUPPORTED_MEDIA_TYPES}; -use crate::utils::files::sniff_media_type; -use crate::utils::urls::guess_protocol; +use crate::utils::{ + files::sniff_media_type, + urls::guess_protocol, +}; use crate::webfinger::types::{ActorAddress, JsonResourceDescriptor}; const FETCHER_CONNECTION_TIMEOUT: u64 = 30; diff --git a/src/activitypub/fetcher/helpers.rs b/src/activitypub/fetcher/helpers.rs index 7ed941d..1a5e80e 100644 --- a/src/activitypub/fetcher/helpers.rs +++ b/src/activitypub/fetcher/helpers.rs @@ -11,14 +11,16 @@ use crate::activitypub::{ use crate::config::{Config, Instance}; use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; -use crate::models::posts::helpers::get_local_post_by_id; -use crate::models::posts::queries::get_post_by_remote_object_id; -use crate::models::posts::types::Post; -use crate::models::profiles::queries::{ - get_profile_by_acct, - get_profile_by_remote_actor_id, +use crate::models::{ + posts::helpers::get_local_post_by_id, + posts::queries::get_post_by_remote_object_id, + posts::types::Post, + profiles::queries::{ + get_profile_by_acct, + get_profile_by_remote_actor_id, + }, + profiles::types::DbActorProfile, }; -use crate::models::profiles::types::DbActorProfile; use crate::webfinger::types::ActorAddress; use super::fetchers::{ fetch_actor, diff --git a/src/activitypub/views.rs b/src/activitypub/views.rs index 78466ed..98d419f 100644 --- a/src/activitypub/views.rs +++ b/src/activitypub/views.rs @@ -1,10 +1,14 @@ use std::time::Instant; use actix_web::{ - get, post, web, - HttpRequest, HttpResponse, Scope, + get, + post, + web, http::header as http_header, http::header::HeaderMap, + HttpRequest, + HttpResponse, + Scope, }; use serde::Deserialize; use tokio::sync::Mutex; diff --git a/src/atom/feeds.rs b/src/atom/feeds.rs index 65d00b2..1626b7a 100644 --- a/src/atom/feeds.rs +++ b/src/atom/feeds.rs @@ -1,7 +1,9 @@ use crate::activitypub::identifiers::{local_actor_id, local_object_id}; use crate::config::Instance; -use crate::models::posts::types::Post; -use crate::models::profiles::types::DbActorProfile; +use crate::models::{ + posts::types::Post, + profiles::types::DbActorProfile, +}; use crate::utils::{ datetime::get_min_datetime, html::{clean_html_all, escape_html}, diff --git a/src/atom/views.rs b/src/atom/views.rs index 64e1ef5..0fd41a3 100644 --- a/src/atom/views.rs +++ b/src/atom/views.rs @@ -3,8 +3,10 @@ use actix_web::{get, web, HttpResponse}; use crate::config::Config; use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; -use crate::models::posts::queries::get_posts_by_author; -use crate::models::users::queries::get_user_by_name; +use crate::models::{ + posts::queries::get_posts_by_author, + users::queries::get_user_by_name, +}; use super::feeds::make_feed; const FEED_SIZE: u16 = 10; diff --git a/src/config/loader.rs b/src/config/loader.rs index 535c7b6..2dd6b10 100644 --- a/src/config/loader.rs +++ b/src/config/loader.rs @@ -4,12 +4,14 @@ use std::str::FromStr; use rsa::RsaPrivateKey; -use crate::utils::crypto_rsa::{ - deserialize_private_key, - generate_rsa_key, - serialize_private_key, +use crate::utils::{ + crypto_rsa::{ + deserialize_private_key, + generate_rsa_key, + serialize_private_key, + }, + files::{set_file_permissions, write_file}, }; -use crate::utils::files::{set_file_permissions, write_file}; use super::environment::Environment; use super::main::{Config, RegistrationType}; diff --git a/src/errors.rs b/src/errors.rs index 8f73fe9..c9e233b 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,7 +1,8 @@ use actix_web::{ - http::StatusCode, - HttpResponse, HttpResponseBuilder, error::ResponseError, + http::StatusCode, + HttpResponse, + HttpResponseBuilder, }; use serde::Serialize; diff --git a/src/ethereum/identity.rs b/src/ethereum/identity.rs index e549246..c190949 100644 --- a/src/ethereum/identity.rs +++ b/src/ethereum/identity.rs @@ -36,11 +36,13 @@ pub fn verify_eip191_identity_proof( #[cfg(test)] mod tests { use web3::signing::{Key, SecretKeyRef}; - use crate::ethereum::signatures::{ - generate_ecdsa_key, - sign_message, + use crate::ethereum::{ + signatures::{ + generate_ecdsa_key, + sign_message, + }, + utils::address_to_string, }; - use crate::ethereum::utils::address_to_string; use crate::utils::currencies::Currency; use super::*; diff --git a/src/ethereum/subscriptions.rs b/src/ethereum/subscriptions.rs index cbf9183..9b2b744 100644 --- a/src/ethereum/subscriptions.rs +++ b/src/ethereum/subscriptions.rs @@ -10,11 +10,13 @@ use web3::{ types::{BlockId, BlockNumber, FilterBuilder, U256}, }; -use crate::activitypub::builders::{ - add_person::prepare_add_person, - remove_person::prepare_remove_person, +use crate::activitypub::{ + builders::{ + add_person::prepare_add_person, + remove_person::prepare_remove_person, + }, + identifiers::LocalActorCollection, }; -use crate::activitypub::identifiers::LocalActorCollection; use crate::config::{EthereumConfig, Instance}; use crate::database::{ get_database_client, @@ -23,29 +25,33 @@ use crate::database::{ DbPool, }; use crate::errors::ConversionError; -use crate::models::notifications::queries::{ - create_subscription_notification, - create_subscription_expiration_notification, +use crate::models::{ + notifications::queries::{ + create_subscription_notification, + create_subscription_expiration_notification, + }, + profiles::queries::{ + get_profile_by_id, + search_profiles_by_wallet_address, + }, + profiles::types::DbActorProfile, + relationships::queries::unsubscribe, + subscriptions::queries::{ + create_subscription, + update_subscription, + get_expired_subscriptions, + get_subscription_by_participants, + }, + users::queries::{ + get_user_by_id, + get_user_by_public_wallet_address, + }, + users::types::User, }; -use crate::models::profiles::queries::{ - get_profile_by_id, - search_profiles_by_wallet_address, +use crate::utils::{ + caip2::ChainId, + currencies::Currency, }; -use crate::models::profiles::types::DbActorProfile; -use crate::models::relationships::queries::unsubscribe; -use crate::models::subscriptions::queries::{ - create_subscription, - update_subscription, - get_expired_subscriptions, - get_subscription_by_participants, -}; -use crate::models::users::queries::{ - get_user_by_id, - get_user_by_public_wallet_address, -}; -use crate::models::users::types::User; -use crate::utils::caip2::ChainId; -use crate::utils::currencies::Currency; use super::contracts::ContractSet; use super::errors::EthereumError; use super::signatures::{ diff --git a/src/job_queue/periodic_tasks.rs b/src/job_queue/periodic_tasks.rs index bd7be1e..4535e41 100644 --- a/src/job_queue/periodic_tasks.rs +++ b/src/job_queue/periodic_tasks.rs @@ -11,11 +11,13 @@ use crate::activitypub::queues::{ }; use crate::config::Config; use crate::database::{get_database_client, DbPool}; -use crate::ethereum::contracts::Blockchain; -use crate::ethereum::nft::process_nft_events; -use crate::ethereum::subscriptions::{ - check_ethereum_subscriptions, - update_expired_subscriptions, +use crate::ethereum::{ + contracts::Blockchain, + nft::process_nft_events, + subscriptions::{ + check_ethereum_subscriptions, + update_expired_subscriptions, + }, }; use crate::monero::subscriptions::check_monero_subscriptions; use crate::models::{ diff --git a/src/json_signatures/verify.rs b/src/json_signatures/verify.rs index f707a64..3e3dc34 100644 --- a/src/json_signatures/verify.rs +++ b/src/json_signatures/verify.rs @@ -133,8 +133,10 @@ pub fn verify_ed25519_json_signature( mod tests { use serde_json::json; use crate::json_signatures::create::sign_object; - use crate::utils::crypto_rsa::generate_weak_rsa_key; - use crate::utils::currencies::Currency; + use crate::utils::{ + crypto_rsa::generate_weak_rsa_key, + currencies::Currency, + }; use super::*; #[test] diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index fe52e56..08617f8 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -15,10 +15,12 @@ use crate::activitypub::builders::{ use crate::config::{Config, RegistrationType}; use crate::database::{get_database_client, DatabaseError, DbPool}; use crate::errors::{HttpError, ValidationError}; -use crate::ethereum::contracts::ContractSet; -use crate::ethereum::eip4361::verify_eip4361_signature; -use crate::ethereum::gate::is_allowed_user; -use crate::ethereum::identity::verify_eip191_identity_proof; +use crate::ethereum::{ + contracts::ContractSet, + eip4361::verify_eip4361_signature, + gate::is_allowed_user, + identity::verify_eip191_identity_proof, +}; use crate::identity::{ claims::create_identity_claim, did::Did, @@ -36,39 +38,43 @@ use crate::json_signatures::{ verify_eip191_json_signature, }, }; -use crate::mastodon_api::oauth::auth::get_current_user; -use crate::mastodon_api::pagination::get_paginated_response; -use crate::mastodon_api::search::helpers::search_profiles_only; -use crate::mastodon_api::statuses::helpers::build_status_list; -use crate::mastodon_api::statuses::types::Status; -use crate::models::posts::queries::get_posts_by_author; -use crate::models::profiles::queries::{ - get_profile_by_acct, - get_profile_by_id, - search_profiles_by_did, - update_profile, +use crate::mastodon_api::{ + oauth::auth::get_current_user, + pagination::get_paginated_response, + search::helpers::search_profiles_only, + statuses::helpers::build_status_list, + statuses::types::Status, }; -use crate::models::profiles::types::{ - IdentityProof, - ProfileUpdateData, - ProofType, +use crate::models::{ + posts::queries::get_posts_by_author, + profiles::queries::{ + get_profile_by_acct, + get_profile_by_id, + search_profiles_by_did, + update_profile, + }, + profiles::types::{ + IdentityProof, + ProfileUpdateData, + ProofType, + }, + relationships::queries::{ + get_followers_paginated, + get_following_paginated, + hide_replies, + hide_reposts, + show_replies, + show_reposts, + unfollow, + }, + subscriptions::queries::get_incoming_subscriptions, + users::queries::{ + create_user, + get_user_by_did, + is_valid_invite_code, + }, + users::types::{Role, UserCreateData}, }; -use crate::models::relationships::queries::{ - get_followers_paginated, - get_following_paginated, - hide_replies, - hide_reposts, - show_replies, - show_reposts, - unfollow, -}; -use crate::models::subscriptions::queries::get_incoming_subscriptions; -use crate::models::users::queries::{ - create_user, - get_user_by_did, - is_valid_invite_code, -}; -use crate::models::users::types::{Role, UserCreateData}; use crate::utils::{ caip2::ChainId, canonicalization::canonicalize_object, diff --git a/src/mastodon_api/directory/views.rs b/src/mastodon_api/directory/views.rs index 858111c..3560af1 100644 --- a/src/mastodon_api/directory/views.rs +++ b/src/mastodon_api/directory/views.rs @@ -5,8 +5,10 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use crate::config::Config; use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; -use crate::mastodon_api::accounts::types::Account; -use crate::mastodon_api::oauth::auth::get_current_user; +use crate::mastodon_api::{ + accounts::types::Account, + oauth::auth::get_current_user, +}; use crate::models::profiles::queries::get_profiles; use super::types::DirectoryQueryParams; diff --git a/src/mastodon_api/markers/views.rs b/src/mastodon_api/markers/views.rs index a429bc9..cb7558a 100644 --- a/src/mastodon_api/markers/views.rs +++ b/src/mastodon_api/markers/views.rs @@ -4,11 +4,13 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; use crate::mastodon_api::oauth::auth::get_current_user; -use crate::models::markers::queries::{ - create_or_update_marker, - get_marker_opt, +use crate::models::{ + markers::queries::{ + create_or_update_marker, + get_marker_opt, + }, + markers::types::Timeline, }; -use crate::models::markers::types::Timeline; use super::types::{MarkerQueryParams, MarkerCreateData, Markers}; /// https://docs.joinmastodon.org/methods/timelines/markers/ diff --git a/src/mastodon_api/media/views.rs b/src/mastodon_api/media/views.rs index 98554a0..93884d4 100644 --- a/src/mastodon_api/media/views.rs +++ b/src/mastodon_api/media/views.rs @@ -5,8 +5,10 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use crate::config::Config; use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; -use crate::mastodon_api::oauth::auth::get_current_user; -use crate::mastodon_api::uploads::save_b64_file; +use crate::mastodon_api::{ + oauth::auth::get_current_user, + uploads::save_b64_file, +}; use crate::models::attachments::queries::create_attachment; use super::types::{AttachmentCreateData, Attachment}; diff --git a/src/mastodon_api/notifications/types.rs b/src/mastodon_api/notifications/types.rs index 4b7435a..c3e5bb0 100644 --- a/src/mastodon_api/notifications/types.rs +++ b/src/mastodon_api/notifications/types.rs @@ -1,9 +1,11 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -use crate::mastodon_api::accounts::types::Account; -use crate::mastodon_api::pagination::PageSize; -use crate::mastodon_api::statuses::types::Status; +use crate::mastodon_api::{ + accounts::types::Account, + pagination::PageSize, + statuses::types::Status, +}; use crate::models::notifications::types::{EventType, Notification}; fn default_page_size() -> PageSize { PageSize::new(20) } diff --git a/src/mastodon_api/notifications/views.rs b/src/mastodon_api/notifications/views.rs index 69b0b03..7989a0e 100644 --- a/src/mastodon_api/notifications/views.rs +++ b/src/mastodon_api/notifications/views.rs @@ -9,8 +9,10 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use crate::config::Config; use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; -use crate::mastodon_api::oauth::auth::get_current_user; -use crate::mastodon_api::pagination::get_paginated_response; +use crate::mastodon_api::{ + oauth::auth::get_current_user, + pagination::get_paginated_response, +}; use crate::models::notifications::queries::get_notifications; use super::types::{ApiNotification, NotificationQueryParams}; diff --git a/src/mastodon_api/oauth/auth.rs b/src/mastodon_api/oauth/auth.rs index be2611f..781cffe 100644 --- a/src/mastodon_api/oauth/auth.rs +++ b/src/mastodon_api/oauth/auth.rs @@ -8,8 +8,10 @@ use serde_json::json; use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::HttpError; -use crate::models::oauth::queries::get_user_by_oauth_token; -use crate::models::users::types::User; +use crate::models::{ + oauth::queries::get_user_by_oauth_token, + users::types::User, +}; pub async fn get_current_user( db_client: &impl DatabaseClient, diff --git a/src/mastodon_api/oauth/views.rs b/src/mastodon_api/oauth/views.rs index 4f0a34d..23e1d1e 100644 --- a/src/mastodon_api/oauth/views.rs +++ b/src/mastodon_api/oauth/views.rs @@ -1,11 +1,11 @@ use actix_web::{ get, + http::header as http_header, post, web, Either, HttpResponse, Scope as ActixScope, - http::header as http_header, }; use actix_web_httpauth::extractors::bearer::BearerAuth; use chrono::{Duration, Utc}; @@ -17,16 +17,18 @@ use crate::ethereum::{ eip4361::verify_eip4361_signature, utils::validate_ethereum_address, }; -use crate::models::oauth::queries::{ - create_oauth_authorization, - delete_oauth_token, - get_oauth_app_by_client_id, - get_user_by_authorization_code, - save_oauth_token, -}; -use crate::models::users::queries::{ - get_user_by_name, - get_user_by_login_address, +use crate::models::{ + oauth::queries::{ + create_oauth_authorization, + delete_oauth_token, + get_oauth_app_by_client_id, + get_user_by_authorization_code, + save_oauth_token, + }, + users::queries::{ + get_user_by_name, + get_user_by_login_address, + }, }; use crate::utils::passwords::verify_password; use super::auth::get_current_user; diff --git a/src/mastodon_api/search/helpers.rs b/src/mastodon_api/search/helpers.rs index 6fe783e..5199284 100644 --- a/src/mastodon_api/search/helpers.rs +++ b/src/mastodon_api/search/helpers.rs @@ -17,20 +17,22 @@ use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::ethereum::utils::validate_ethereum_address; use crate::identity::did::Did; -use crate::models::posts::{ - helpers::{can_view_post, get_local_post_by_id}, - types::Post, -}; -use crate::models::profiles::queries::{ - search_profiles, - search_profiles_by_did_only, - search_profiles_by_wallet_address, -}; -use crate::models::profiles::types::DbActorProfile; -use crate::models::tags::queries::search_tags; -use crate::models::users::{ - queries::get_user_by_name, - types::User, +use crate::models::{ + posts::{ + helpers::{can_view_post, get_local_post_by_id}, + types::Post, + }, + profiles::queries::{ + search_profiles, + search_profiles_by_did_only, + search_profiles_by_wallet_address, + }, + profiles::types::DbActorProfile, + tags::queries::search_tags, + users::{ + queries::get_user_by_name, + types::User, + }, }; use crate::utils::currencies::Currency; use crate::webfinger::types::ActorAddress; diff --git a/src/mastodon_api/search/types.rs b/src/mastodon_api/search/types.rs index b3fc89d..6f5d378 100644 --- a/src/mastodon_api/search/types.rs +++ b/src/mastodon_api/search/types.rs @@ -1,9 +1,11 @@ /// https://docs.joinmastodon.org/methods/search/ use serde::{Deserialize, Serialize}; -use crate::mastodon_api::accounts::types::Account; -use crate::mastodon_api::pagination::PageSize; -use crate::mastodon_api::statuses::types::{Status, Tag}; +use crate::mastodon_api::{ + accounts::types::Account, + pagination::PageSize, + statuses::types::{Status, Tag}, +}; fn default_page_size() -> PageSize { PageSize::new(20) } diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index 4f07825..d8c8c3d 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -16,31 +16,35 @@ use crate::config::Config; use crate::database::{get_database_client, DatabaseError, DbPool}; use crate::errors::{HttpError, ValidationError}; use crate::ethereum::nft::create_mint_signature; -use crate::ipfs::store as ipfs_store; -use crate::ipfs::posts::PostMetadata; -use crate::ipfs::utils::get_ipfs_url; +use crate::ipfs::{ + store as ipfs_store, + posts::PostMetadata, + utils::get_ipfs_url, +}; use crate::mastodon_api::oauth::auth::get_current_user; -use crate::models::posts::helpers::{can_create_post, can_view_post}; -use crate::models::posts::queries::{ - create_post, - get_post_by_id, - get_thread, - find_reposts_by_user, - set_post_ipfs_cid, - set_post_token_tx_id, - delete_post, +use crate::models::{ + posts::helpers::{can_create_post, can_view_post}, + posts::queries::{ + create_post, + get_post_by_id, + get_thread, + find_reposts_by_user, + set_post_ipfs_cid, + set_post_token_tx_id, + delete_post, + }, + posts::types::{PostCreateData, Visibility}, + posts::validators::{ + clean_content, + ATTACHMENTS_MAX_NUM, + EMOJIS_MAX_NUM, + }, + reactions::queries::{ + create_reaction, + delete_reaction, + }, + relationships::queries::get_subscribers, }; -use crate::models::posts::types::{PostCreateData, Visibility}; -use crate::models::posts::validators::{ - clean_content, - ATTACHMENTS_MAX_NUM, - EMOJIS_MAX_NUM, -}; -use crate::models::reactions::queries::{ - create_reaction, - delete_reaction, -}; -use crate::models::relationships::queries::get_subscribers; use crate::utils::{ currencies::Currency, markdown::markdown_lite_to_html, diff --git a/src/mastodon_api/subscriptions/types.rs b/src/mastodon_api/subscriptions/types.rs index 3230490..872f511 100644 --- a/src/mastodon_api/subscriptions/types.rs +++ b/src/mastodon_api/subscriptions/types.rs @@ -2,8 +2,10 @@ use chrono::{DateTime, Duration, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::models::invoices::types::{DbInvoice, InvoiceStatus}; -use crate::models::profiles::types::PaymentOption; +use crate::models::{ + invoices::types::{DbInvoice, InvoiceStatus}, + profiles::types::PaymentOption, +}; use crate::monero::subscriptions::MONERO_INVOICE_TIMEOUT; #[derive(Deserialize)] diff --git a/src/mastodon_api/subscriptions/views.rs b/src/mastodon_api/subscriptions/views.rs index 72ed833..a5c26dc 100644 --- a/src/mastodon_api/subscriptions/views.rs +++ b/src/mastodon_api/subscriptions/views.rs @@ -6,13 +6,17 @@ use crate::activitypub::builders::update_person::prepare_update_person; use crate::config::Config; use crate::database::{get_database_client, DbPool}; use crate::errors::{HttpError, ValidationError}; -use crate::ethereum::contracts::ContractSet; -use crate::ethereum::subscriptions::{ - create_subscription_signature, - is_registered_recipient, +use crate::ethereum::{ + contracts::ContractSet, + subscriptions::{ + create_subscription_signature, + is_registered_recipient, + }, +}; +use crate::mastodon_api::{ + accounts::types::Account, + oauth::auth::get_current_user, }; -use crate::mastodon_api::accounts::types::Account; -use crate::mastodon_api::oauth::auth::get_current_user; use crate::models::{ invoices::queries::{create_invoice, get_invoice_by_id}, profiles::queries::{ diff --git a/src/mastodon_api/timelines/views.rs b/src/mastodon_api/timelines/views.rs index 19df97c..c1759f1 100644 --- a/src/mastodon_api/timelines/views.rs +++ b/src/mastodon_api/timelines/views.rs @@ -5,8 +5,10 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use crate::config::Config; use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; -use crate::mastodon_api::oauth::auth::get_current_user; -use crate::mastodon_api::statuses::helpers::build_status_list; +use crate::mastodon_api::{ + oauth::auth::get_current_user, + statuses::helpers::build_status_list, +}; use crate::models::posts::queries::{ get_home_timeline, get_local_timeline, diff --git a/src/models/attachments/queries.rs b/src/models/attachments/queries.rs index f7e61ce..3ec7a98 100644 --- a/src/models/attachments/queries.rs +++ b/src/models/attachments/queries.rs @@ -96,8 +96,10 @@ pub async fn delete_unused_attachments( mod tests { use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::profiles::types::ProfileCreateData; - use crate::models::profiles::queries::create_profile; + use crate::models::{ + profiles::types::ProfileCreateData, + profiles::queries::create_profile, + }; use super::*; #[tokio::test] diff --git a/src/models/notifications/queries.rs b/src/models/notifications/queries.rs index beb085a..103b0b5 100644 --- a/src/models/notifications/queries.rs +++ b/src/models/notifications/queries.rs @@ -1,13 +1,15 @@ use uuid::Uuid; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::helpers::{add_related_posts, add_user_actions}; -use crate::models::posts::queries::{ - RELATED_ATTACHMENTS, - RELATED_EMOJIS, - RELATED_LINKS, - RELATED_MENTIONS, - RELATED_TAGS, +use crate::models::{ + posts::helpers::{add_related_posts, add_user_actions}, + posts::queries::{ + RELATED_ATTACHMENTS, + RELATED_EMOJIS, + RELATED_LINKS, + RELATED_MENTIONS, + RELATED_TAGS, + }, }; use super::types::{EventType, Notification}; diff --git a/src/models/oauth/queries.rs b/src/models/oauth/queries.rs index 578c2c7..b50ceb5 100644 --- a/src/models/oauth/queries.rs +++ b/src/models/oauth/queries.rs @@ -6,8 +6,10 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::profiles::types::DbActorProfile; -use crate::models::users::types::{DbUser, User}; +use crate::models::{ + profiles::types::DbActorProfile, + users::types::{DbUser, User}, +}; use super::types::{DbOauthApp, DbOauthAppData}; pub async fn create_oauth_app( diff --git a/src/models/posts/emojis.rs b/src/models/posts/emojis.rs index a6aaa21..7faf825 100644 --- a/src/models/posts/emojis.rs +++ b/src/models/posts/emojis.rs @@ -3,8 +3,10 @@ use std::collections::HashMap; use regex::Regex; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::emojis::queries::get_local_emojis_by_names; -use crate::models::emojis::types::DbEmoji; +use crate::models::{ + emojis::queries::get_local_emojis_by_names, + emojis::types::DbEmoji, +}; use super::links::is_inside_code_block; // See also: EMOJI_NAME_RE in models::emojis::validators diff --git a/src/models/posts/helpers.rs b/src/models/posts/helpers.rs index 8fe936f..73bee0a 100644 --- a/src/models/posts/helpers.rs +++ b/src/models/posts/helpers.rs @@ -2,10 +2,12 @@ use uuid::Uuid; use crate::activitypub::identifiers::parse_local_object_id; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::reactions::queries::find_favourited_by_user; -use crate::models::relationships::queries::has_relationship; -use crate::models::relationships::types::RelationshipType; -use crate::models::users::types::{Permission, User}; +use crate::models::{ + reactions::queries::find_favourited_by_user, + relationships::queries::has_relationship, + relationships::types::RelationshipType, + users::types::{Permission, User}, +}; use super::queries::{ get_post_by_id, get_post_by_remote_object_id, @@ -164,11 +166,13 @@ mod tests { use serial_test::serial; use tokio_postgres::Client; use crate::database::test_utils::create_test_database; - use crate::models::posts::queries::create_post; - use crate::models::posts::types::PostCreateData; - use crate::models::relationships::queries::{follow, subscribe}; - use crate::models::users::queries::create_user; - use crate::models::users::types::{Role, User, UserCreateData}; + use crate::models::{ + posts::queries::create_post, + posts::types::PostCreateData, + relationships::queries::{follow, subscribe}, + users::queries::create_user, + users::types::{Role, User, UserCreateData}, + }; use super::*; #[tokio::test] diff --git a/src/models/posts/mentions.rs b/src/models/posts/mentions.rs index 30b39d8..544d7bf 100644 --- a/src/models/posts/mentions.rs +++ b/src/models/posts/mentions.rs @@ -4,8 +4,10 @@ use regex::{Captures, Regex}; use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; -use crate::models::profiles::queries::get_profiles_by_accts; -use crate::models::profiles::types::DbActorProfile; +use crate::models::{ + profiles::queries::get_profiles_by_accts, + profiles::types::DbActorProfile, +}; use crate::webfinger::types::ActorAddress; use super::links::is_inside_code_block; diff --git a/src/models/posts/queries.rs b/src/models/posts/queries.rs index 68aa572..167693a 100644 --- a/src/models/posts/queries.rs +++ b/src/models/posts/queries.rs @@ -7,22 +7,24 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::attachments::queries::set_attachment_ipfs_cid; -use crate::models::attachments::types::DbMediaAttachment; -use crate::models::cleanup::{ - find_orphaned_files, - find_orphaned_ipfs_objects, - DeletionQueue, +use crate::models::{ + attachments::queries::set_attachment_ipfs_cid, + attachments::types::DbMediaAttachment, + cleanup::{ + find_orphaned_files, + find_orphaned_ipfs_objects, + DeletionQueue, + }, + emojis::types::DbEmoji, + notifications::queries::{ + create_mention_notification, + create_reply_notification, + create_repost_notification, + }, + profiles::queries::update_post_count, + profiles::types::DbActorProfile, + relationships::types::RelationshipType, }; -use crate::models::emojis::types::DbEmoji; -use crate::models::notifications::queries::{ - create_mention_notification, - create_reply_notification, - create_repost_notification, -}; -use crate::models::profiles::queries::update_post_count; -use crate::models::profiles::types::DbActorProfile; -use crate::models::relationships::types::RelationshipType; use crate::utils::id::generate_ulid; use super::types::{ DbPost, @@ -1304,15 +1306,17 @@ mod tests { use chrono::Duration; use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::profiles::queries::create_profile; - use crate::models::profiles::types::ProfileCreateData; - use crate::models::relationships::queries::{ - follow, - hide_reposts, - subscribe, + use crate::models::{ + profiles::queries::create_profile, + profiles::types::ProfileCreateData, + relationships::queries::{ + follow, + hide_reposts, + subscribe, + }, + users::queries::create_user, + users::types::UserCreateData, }; - use crate::models::users::queries::create_user; - use crate::models::users::types::UserCreateData; use super::*; #[tokio::test] diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index 71835be..4ce843d 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -8,13 +8,15 @@ use crate::database::{ DatabaseError, }; use crate::identity::{did::Did, did_pkh::DidPkh}; -use crate::models::cleanup::{ - find_orphaned_files, - find_orphaned_ipfs_objects, - DeletionQueue, +use crate::models::{ + cleanup::{ + find_orphaned_files, + find_orphaned_ipfs_objects, + DeletionQueue, + }, + instances::queries::create_instance, + relationships::types::RelationshipType, }; -use crate::models::instances::queries::create_instance; -use crate::models::relationships::types::RelationshipType; use crate::utils::{ currencies::Currency, id::generate_ulid, diff --git a/src/models/profiles/types.rs b/src/models/profiles/types.rs index 68db255..0242ae3 100644 --- a/src/models/profiles/types.rs +++ b/src/models/profiles/types.rs @@ -11,8 +11,10 @@ use serde::{ }; use uuid::Uuid; -use crate::activitypub::actors::types::Actor; -use crate::activitypub::identifiers::local_actor_id; +use crate::activitypub::{ + actors::types::Actor, + identifiers::local_actor_id, +}; use crate::database::{ json_macro::{json_from_sql, json_to_sql}, DatabaseTypeError, diff --git a/src/models/reactions/queries.rs b/src/models/reactions/queries.rs index 2c062d7..0edd5ea 100644 --- a/src/models/reactions/queries.rs +++ b/src/models/reactions/queries.rs @@ -5,10 +5,12 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::notifications::queries::create_reaction_notification; -use crate::models::posts::queries::{ - update_reaction_count, - get_post_author, +use crate::models::{ + notifications::queries::create_reaction_notification, + posts::queries::{ + update_reaction_count, + get_post_author, + }, }; use crate::utils::id::generate_ulid; use super::types::DbReaction; diff --git a/src/models/relationships/queries.rs b/src/models/relationships/queries.rs index 61fd716..dbd9194 100644 --- a/src/models/relationships/queries.rs +++ b/src/models/relationships/queries.rs @@ -5,13 +5,15 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::notifications::queries::create_follow_notification; -use crate::models::profiles::queries::{ - update_follower_count, - update_following_count, - update_subscriber_count, +use crate::models::{ + notifications::queries::create_follow_notification, + profiles::queries::{ + update_follower_count, + update_following_count, + update_subscriber_count, + }, + profiles::types::DbActorProfile, }; -use crate::models::profiles::types::DbActorProfile; use crate::utils::id::generate_ulid; use super::types::{ DbFollowRequest, diff --git a/src/models/subscriptions/queries.rs b/src/models/subscriptions/queries.rs index 6ab3d52..f02ec9a 100644 --- a/src/models/subscriptions/queries.rs +++ b/src/models/subscriptions/queries.rs @@ -6,9 +6,11 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::profiles::types::PaymentType; -use crate::models::relationships::queries::{subscribe, subscribe_opt}; -use crate::models::relationships::types::RelationshipType; +use crate::models::{ + profiles::types::PaymentType, + relationships::queries::{subscribe, subscribe_opt}, + relationships::types::RelationshipType, +}; use crate::utils::caip2::ChainId; use super::types::{DbSubscription, Subscription}; diff --git a/src/models/users/queries.rs b/src/models/users/queries.rs index 5d7323d..caca1e0 100644 --- a/src/models/users/queries.rs +++ b/src/models/users/queries.rs @@ -6,8 +6,10 @@ use crate::database::{ DatabaseError, }; use crate::identity::{did::Did, did_pkh::DidPkh}; -use crate::models::profiles::queries::create_profile; -use crate::models::profiles::types::{DbActorProfile, ProfileCreateData}; +use crate::models::{ + profiles::queries::create_profile, + profiles::types::{DbActorProfile, ProfileCreateData}, +}; use crate::utils::currencies::Currency; use super::types::{DbUser, Role, User, UserCreateData}; use super::utils::generate_invite_code; diff --git a/src/nodeinfo/helpers.rs b/src/nodeinfo/helpers.rs index c207429..074eceb 100644 --- a/src/nodeinfo/helpers.rs +++ b/src/nodeinfo/helpers.rs @@ -1,6 +1,8 @@ use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::queries::get_local_post_count; -use crate::models::users::queries::get_user_count; +use crate::models::{ + posts::queries::get_local_post_count, + users::queries::get_user_count, +}; use super::types::{Usage, Users}; pub async fn get_usage(db_client: &impl DatabaseClient) diff --git a/src/webfinger/views.rs b/src/webfinger/views.rs index 31b420f..20fe89c 100644 --- a/src/webfinger/views.rs +++ b/src/webfinger/views.rs @@ -1,10 +1,12 @@ use actix_web::{get, web, HttpResponse}; -use crate::activitypub::constants::AP_MEDIA_TYPE; -use crate::activitypub::identifiers::{ - local_actor_id, - local_instance_actor_id, - parse_local_actor_id, +use crate::activitypub::{ + constants::AP_MEDIA_TYPE, + identifiers::{ + local_actor_id, + local_instance_actor_id, + parse_local_actor_id, + }, }; use crate::config::{Config, Instance}; use crate::database::{get_database_client, DatabaseClient, DbPool};