From 9e61c3be94c623b43b2e87ed060bfebc041d1eaa Mon Sep 17 00:00:00 2001 From: Felix Date: Sat, 16 May 2020 16:04:08 +0200 Subject: [PATCH] Rework imports --- server/.rustfmt.toml | 5 +- server/Cargo.lock | 26 ++++++- server/Cargo.toml | 6 +- server/src/api/comment.rs | 39 +++++++++- server/src/api/community.rs | 39 +++++++++- server/src/api/mod.rs | 45 +---------- server/src/api/post.rs | 37 ++++++++- server/src/api/site.rs | 33 +++++++- server/src/api/user.rs | 54 ++++++++++++- server/src/apub/activities.rs | 8 +- server/src/apub/comment.rs | 34 ++++++++- server/src/apub/community.rs | 40 +++++++++- server/src/apub/community_inbox.rs | 21 +++++- .../src/apub/extensions/group_extensions.rs | 6 +- server/src/apub/extensions/page_extension.rs | 3 +- server/src/apub/extensions/signatures.rs | 9 ++- server/src/apub/fetcher.rs | 41 +++++++++- server/src/apub/mod.rs | 75 +++++-------------- server/src/apub/post.rs | 36 ++++++++- server/src/apub/private_message.rs | 26 ++++++- server/src/apub/shared_inbox.rs | 38 +++++++++- server/src/apub/user.rs | 31 +++++++- server/src/apub/user_inbox.rs | 30 +++++++- server/src/db/activity.rs | 9 ++- server/src/db/category.rs | 11 ++- server/src/db/code_migrations.rs | 22 +++--- server/src/db/comment.rs | 19 ++--- server/src/db/comment_view.rs | 16 ++-- server/src/db/community.rs | 14 +++- server/src/db/community_view.rs | 5 +- server/src/db/mod.rs | 4 +- server/src/db/moderator.rs | 30 +++++--- server/src/db/moderator_views.rs | 4 +- server/src/db/password_reset_request.rs | 12 +-- server/src/db/post.rs | 21 ++++-- server/src/db/post_view.rs | 15 ++-- server/src/db/private_message.rs | 15 ++-- server/src/db/private_message_view.rs | 5 +- server/src/db/site.rs | 5 +- server/src/db/site_view.rs | 3 +- server/src/db/user.rs | 17 +++-- server/src/db/user_mention.rs | 16 ++-- server/src/db/user_mention_view.rs | 5 +- server/src/db/user_view.rs | 5 +- server/src/lib.rs | 17 +++-- server/src/main.rs | 6 +- server/src/rate_limit/mod.rs | 25 +++---- server/src/rate_limit/rate_limiter.rs | 7 +- server/src/routes/api.rs | 15 ++-- server/src/routes/federation.rs | 23 +++--- server/src/routes/feeds.rs | 37 ++++++--- server/src/routes/index.rs | 4 +- server/src/routes/mod.rs | 43 ++++------- server/src/routes/nodeinfo.rs | 11 ++- server/src/routes/webfinger.rs | 7 +- server/src/routes/websocket.rs | 11 ++- server/src/settings.rs | 5 +- server/src/websocket/mod.rs | 12 ++- server/src/websocket/server.rs | 21 +++--- 59 files changed, 853 insertions(+), 326 deletions(-) diff --git a/server/.rustfmt.toml b/server/.rustfmt.toml index 684a7f8a2..f3efdc308 100644 --- a/server/.rustfmt.toml +++ b/server/.rustfmt.toml @@ -1,2 +1,5 @@ tab_spaces = 2 -edition="2018" \ No newline at end of file +edition="2018" +imports_layout="HorizontalVertical" +merge_imports=true +reorder_imports=true diff --git a/server/Cargo.lock b/server/Cargo.lock index 714422b64..cc43028b5 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -2,9 +2,9 @@ # It is not intended for manual editing. [[package]] name = "activitystreams" -version = "0.6.0" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd5b29a0f2c64cc56f2b79ec29cab68a9dab3b714d811a55668d072f18a8638e" +checksum = "464cb473bfb402b857cc15b1153974c203a43f1485da4dda15cd17a738548958" dependencies = [ "activitystreams-derive", "chrono", @@ -26,6 +26,17 @@ dependencies = [ "syn", ] +[[package]] +name = "activitystreams-new" +version = "0.1.0" +source = "git+https://git.asonix.dog/asonix/activitystreams-sketch#3f75e56190bd2e942621e8265435c74132639a47" +dependencies = [ + "activitystreams", + "serde 1.0.106", + "serde_json 1.0.51", + "typed-builder", +] + [[package]] name = "actix" version = "0.9.0" @@ -1544,6 +1555,7 @@ name = "lemmy_server" version = "0.0.1" dependencies = [ "activitystreams", + "activitystreams-new", "actix", "actix-files", "actix-rt", @@ -2992,6 +3004,16 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d" +[[package]] +name = "typed-builder" +version = "0.5.1" +source = "git+https://git.asonix.dog/asonix/typed-builder#3dadcaaa6184ef720093c8f0632a7d423d2537b0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "typenum" version = "1.12.0" diff --git a/server/Cargo.toml b/server/Cargo.toml index ab76d06fa..2c11c1914 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -4,11 +4,15 @@ version = "0.0.1" authors = ["Dessalines "] edition = "2018" +[patch.crates-io] +typed-builder = { git = "https://git.asonix.dog/asonix/typed-builder" } + [dependencies] diesel = { version = "1.4.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] } diesel_migrations = "1.4.0" dotenv = "0.15.0" -activitystreams = "0.6.0" +activitystreams = "0.6.2" +activitystreams-new = { version = "0.1.0", git = "https://git.asonix.dog/asonix/activitystreams-sketch" } bcrypt = "0.6.2" chrono = { version = "0.4.7", features = ["serde"] } failure = "0.1.5" diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index 0660a52c8..40f87ac9c 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -1,4 +1,41 @@ -use super::*; +use crate::{ + api::{APIError, Oper, Perform}, + apub::{ApubLikeableType, ApubObjectType}, + db::{ + comment::*, + comment_view::*, + community_view::*, + moderator::*, + post::*, + site_view::*, + user::*, + user_mention::*, + user_view::*, + Crud, + Likeable, + ListingType, + Saveable, + SortType, + }, + extract_usernames, + naive_now, + remove_slurs, + send_email, + settings::Settings, + websocket::{ + server::{JoinCommunityRoom, SendComment}, + UserOperation, + WebsocketInfo, + }, +}; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; +use failure::Error; +use log::error; +use serde::{Deserialize, Serialize}; +use std::str::FromStr; #[derive(Serialize, Deserialize)] pub struct CreateComment { diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 55c55ee12..cb412fcca 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -1,4 +1,41 @@ -use super::*; +use crate::{ + api::{APIError, Oper, Perform}, + apub::{ + extensions::signatures::generate_actor_keypair, + make_apub_endpoint, + ActorType, + EndpointType, + }, + db::{ + community::*, + community_view::*, + moderator::*, + site::*, + user::*, + user_view::*, + Bannable, + Crud, + Followable, + Joinable, + SortType, + }, + naive_from_unix, + naive_now, + slur_check, + slurs_vec_to_str, + websocket::{ + server::{JoinCommunityRoom, SendCommunityRoomMessage}, + UserOperation, + WebsocketInfo, + }, +}; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; +use failure::Error; +use serde::{Deserialize, Serialize}; +use std::str::FromStr; #[derive(Serialize, Deserialize)] pub struct GetCommunity { diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index 9112a3be3..5120e9bc9 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -1,46 +1,9 @@ -use crate::db::category::*; -use crate::db::comment::*; -use crate::db::comment_view::*; -use crate::db::community::*; -use crate::db::community_view::*; -use crate::db::moderator::*; -use crate::db::moderator_views::*; -use crate::db::password_reset_request::*; -use crate::db::post::*; -use crate::db::post_view::*; -use crate::db::private_message::*; -use crate::db::private_message_view::*; -use crate::db::site::*; -use crate::db::site_view::*; -use crate::db::user::*; -use crate::db::user_mention::*; -use crate::db::user_mention_view::*; -use crate::db::user_view::*; -use crate::db::*; -use crate::{ - extract_usernames, fetch_iframely_and_pictshare_data, generate_random_string, naive_from_unix, - naive_now, remove_slurs, send_email, slur_check, slurs_vec_to_str, +use crate::websocket::WebsocketInfo; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, }; - -use crate::apub::{ - extensions::signatures::generate_actor_keypair, - fetcher::search_by_apub_id, - {make_apub_endpoint, ActorType, ApubLikeableType, ApubObjectType, EndpointType}, -}; -use crate::settings::Settings; -use crate::websocket::{ - server::{ - JoinCommunityRoom, JoinPostRoom, JoinUserRoom, SendAllMessage, SendComment, - SendCommunityRoomMessage, SendPost, SendUserRoomMessage, - }, - UserOperation, WebsocketInfo, -}; -use diesel::r2d2::{ConnectionManager, Pool}; -use diesel::PgConnection; use failure::Error; -use log::{debug, error, info}; -use serde::{Deserialize, Serialize}; -use std::str::FromStr; pub mod comment; pub mod community; diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 42c350741..9bbde7919 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -1,4 +1,39 @@ -use super::*; +use crate::{ + api::{APIError, Oper, Perform}, + apub::{ApubLikeableType, ApubObjectType}, + db::{ + comment_view::*, + community_view::*, + moderator::*, + post::*, + post_view::*, + site::*, + site_view::*, + user::*, + user_view::*, + Crud, + Likeable, + ListingType, + Saveable, + SortType, + }, + fetch_iframely_and_pictshare_data, + naive_now, + slur_check, + slurs_vec_to_str, + websocket::{ + server::{JoinCommunityRoom, JoinPostRoom, SendPost}, + UserOperation, + WebsocketInfo, + }, +}; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; +use failure::Error; +use serde::{Deserialize, Serialize}; +use std::str::FromStr; #[derive(Serialize, Deserialize, Debug)] pub struct CreatePost { diff --git a/server/src/api/site.rs b/server/src/api/site.rs index 1a4ed0be5..faee30cbb 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -1,5 +1,36 @@ use super::user::Register; -use super::*; +use crate::{ + api::{APIError, Oper, Perform}, + apub::fetcher::search_by_apub_id, + db::{ + category::*, + comment_view::*, + community_view::*, + moderator::*, + moderator_views::*, + post_view::*, + site::*, + site_view::*, + user::*, + user_view::*, + Crud, + SearchType, + SortType, + }, + naive_now, + settings::Settings, + slur_check, + slurs_vec_to_str, + websocket::{server::SendAllMessage, UserOperation, WebsocketInfo}, +}; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; +use failure::Error; +use log::{debug, info}; +use serde::{Deserialize, Serialize}; +use std::str::FromStr; #[derive(Serialize, Deserialize)] pub struct ListCategories {} diff --git a/server/src/api/user.rs b/server/src/api/user.rs index b5336609a..18d309850 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -1,5 +1,57 @@ -use super::*; +use crate::{ + api::{APIError, Oper, Perform}, + apub::{ + extensions::signatures::generate_actor_keypair, + make_apub_endpoint, + ApubObjectType, + EndpointType, + }, + db::{ + comment::*, + comment_view::*, + community::*, + community_view::*, + moderator::*, + password_reset_request::*, + post::*, + post_view::*, + private_message::*, + private_message_view::*, + site::*, + site_view::*, + user::*, + user_mention::*, + user_mention_view::*, + user_view::*, + Crud, + Followable, + Joinable, + ListingType, + SortType, + }, + generate_random_string, + naive_from_unix, + naive_now, + remove_slurs, + send_email, + settings::Settings, + slur_check, + slurs_vec_to_str, + websocket::{ + server::{JoinUserRoom, SendAllMessage, SendUserRoomMessage}, + UserOperation, + WebsocketInfo, + }, +}; use bcrypt::verify; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; +use failure::Error; +use log::error; +use serde::{Deserialize, Serialize}; +use std::str::FromStr; #[derive(Serialize, Deserialize, Debug)] pub struct Login { diff --git a/server/src/apub/activities.rs b/server/src/apub/activities.rs index 23ae96987..655e4a7a5 100644 --- a/server/src/apub/activities.rs +++ b/server/src/apub/activities.rs @@ -1,4 +1,10 @@ -use super::*; +use crate::apub::{extensions::signatures::sign, is_apub_id_valid, ActorType}; +use activitystreams::{context, object::properties::ObjectProperties, public}; +use failure::{Error, _core::fmt::Debug}; +use isahc::prelude::*; +use log::debug; +use serde::Serialize; +use url::Url; pub fn populate_object_props( props: &mut ObjectProperties, diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index df41f67be..97f9c2724 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -1,4 +1,36 @@ -use super::*; +use crate::{ + apub::{ + activities::{populate_object_props, send_activity}, + create_apub_response, + create_apub_tombstone_response, + create_tombstone, + fetcher::get_or_fetch_and_upsert_remote_user, + ActorType, + ApubLikeableType, + ApubObjectType, + FromApub, + ToApub, + }, + convert_datetime, + db::{ + activity::insert_activity, + comment::{Comment, CommentForm}, + community::Community, + post::Post, + user::User_, + Crud, + }, + routes::DbPoolParam, +}; +use activitystreams::{ + activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, + context, + object::{kind::NoteType, properties::ObjectProperties, Note, Tombstone}, +}; +use actix_web::{body::Body, web::Path, HttpResponse, Result}; +use diesel::PgConnection; +use failure::Error; +use serde::Deserialize; #[derive(Deserialize)] pub struct CommentQuery { diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index f4e8848f2..12ce2800a 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -1,4 +1,42 @@ -use super::*; +use crate::{ + apub::{ + activities::{populate_object_props, send_activity}, + create_apub_response, + create_apub_tombstone_response, + create_tombstone, + extensions::{group_extensions::GroupExtension, signatures::PublicKey}, + fetcher::get_or_fetch_and_upsert_remote_user, + get_shared_inbox, + ActorType, + FromApub, + GroupExt, + ToApub, + }, + convert_datetime, + db::{ + activity::insert_activity, + community::{Community, CommunityForm}, + community_view::{CommunityFollowerView, CommunityModeratorView}, + user::User_, + }, + naive_now, + routes::DbPoolParam, +}; +use activitystreams::{ + activity::{Accept, Delete, Follow, Remove, Undo}, + actor::{kind::GroupType, properties::ApActorProperties, Group}, + collection::UnorderedCollection, + context, + endpoint::EndpointProperties, + ext::Extensible, + object::{properties::ObjectProperties, Tombstone}, + BaseBox, +}; +use actix_web::{body::Body, web::Path, HttpResponse, Result}; +use diesel::PgConnection; +use failure::Error; +use itertools::Itertools; +use serde::Deserialize; #[derive(Deserialize)] pub struct CommunityQuery { diff --git a/server/src/apub/community_inbox.rs b/server/src/apub/community_inbox.rs index 6c35ce0aa..2ae2e0ebc 100644 --- a/server/src/apub/community_inbox.rs +++ b/server/src/apub/community_inbox.rs @@ -1,4 +1,23 @@ -use super::*; +use crate::{ + apub::{ + extensions::signatures::verify, + fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, + ActorType, + }, + db::{ + activity::insert_activity, + community::{Community, CommunityFollower, CommunityFollowerForm}, + user::User_, + Followable, + }, + routes::{ChatServerParam, DbPoolParam}, +}; +use activitystreams::activity::{Follow, Undo}; +use actix_web::{web, HttpRequest, HttpResponse, Result}; +use diesel::PgConnection; +use failure::{Error, _core::fmt::Debug}; +use log::debug; +use serde::Deserialize; #[serde(untagged)] #[derive(Deserialize, Debug)] diff --git a/server/src/apub/extensions/group_extensions.rs b/server/src/apub/extensions/group_extensions.rs index 10cee5c72..ece97706c 100644 --- a/server/src/apub/extensions/group_extensions.rs +++ b/server/src/apub/extensions/group_extensions.rs @@ -1,7 +1,5 @@ -use crate::db::category::Category; -use crate::db::Crud; -use activitystreams::ext::Extension; -use activitystreams::Actor; +use crate::db::{category::Category, Crud}; +use activitystreams::{ext::Extension, Actor}; use diesel::PgConnection; use failure::Error; use serde::{Deserialize, Serialize}; diff --git a/server/src/apub/extensions/page_extension.rs b/server/src/apub/extensions/page_extension.rs index 435a869a9..484807e3e 100644 --- a/server/src/apub/extensions/page_extension.rs +++ b/server/src/apub/extensions/page_extension.rs @@ -1,5 +1,4 @@ -use activitystreams::ext::Extension; -use activitystreams::Base; +use activitystreams::{ext::Extension, Base}; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Deserialize, Serialize)] diff --git a/server/src/apub/extensions/signatures.rs b/server/src/apub/extensions/signatures.rs index e8630f214..a78488276 100644 --- a/server/src/apub/extensions/signatures.rs +++ b/server/src/apub/extensions/signatures.rs @@ -5,9 +5,12 @@ use failure::Error; use http::request::Builder; use http_signature_normalization::Config; use log::debug; -use openssl::hash::MessageDigest; -use openssl::sign::{Signer, Verifier}; -use openssl::{pkey::PKey, rsa::Rsa}; +use openssl::{ + hash::MessageDigest, + pkey::PKey, + rsa::Rsa, + sign::{Signer, Verifier}, +}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index 994e75f2b..9379dd96b 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -1,4 +1,43 @@ -use super::*; +use activitystreams::object::Note; +use actix_web::Result; +use diesel::{result::Error::NotFound, PgConnection}; +use failure::{Error, _core::fmt::Debug}; +use isahc::prelude::*; +use log::debug; +use serde::Deserialize; +use std::time::Duration; +use url::Url; + +use crate::{ + api::site::SearchResponse, + db::{ + comment::{Comment, CommentForm}, + comment_view::CommentView, + community::{Community, CommunityForm, CommunityModerator, CommunityModeratorForm}, + community_view::CommunityView, + post::{Post, PostForm}, + post_view::PostView, + user::{UserForm, User_}, + Crud, + Joinable, + SearchType, + }, + naive_now, + routes::nodeinfo::{NodeInfo, NodeInfoWellKnown}, +}; + +use crate::{ + apub::{ + get_apub_protocol_string, + is_apub_id_valid, + FromApub, + GroupExt, + PageExt, + PersonExt, + APUB_JSON_CONTENT_TYPE, + }, + db::user_view::UserView, +}; // Fetch nodeinfo metadata from a remote instance. fn _fetch_node_info(domain: &str) -> Result { diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 6ff6a0f8f..fdd781094 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -10,68 +10,29 @@ pub mod shared_inbox; pub mod user; pub mod user_inbox; -use crate::api::community::CommunityResponse; -use crate::db::activity::insert_activity; -use crate::websocket::server::SendCommunityRoomMessage; -use activitystreams::object::kind::{NoteType, PageType}; -use activitystreams::{ - activity::{Accept, Create, Delete, Dislike, Follow, Like, Remove, Undo, Update}, - actor::{kind::GroupType, properties::ApActorProperties, Group, Person}, - collection::UnorderedCollection, - context, - endpoint::EndpointProperties, - ext::{Ext, Extensible}, - object::{properties::ObjectProperties, Note, Page, Tombstone}, - public, BaseBox, +use crate::{ + apub::extensions::{ + group_extensions::GroupExtension, + page_extension::PageExtension, + signatures::{PublicKey, PublicKeyExtension}, + }, + convert_datetime, + db::user::User_, + Settings, }; -use actix_web::body::Body; -use actix_web::web::Path; -use actix_web::{web, HttpRequest, HttpResponse, Result}; -use diesel::result::Error::NotFound; +use activitystreams::{ + activity::Follow, + actor::{properties::ApActorProperties, Group, Person}, + ext::Ext, + object::{Page, Tombstone}, +}; +use actix_web::{body::Body, HttpResponse, Result}; +use chrono::NaiveDateTime; use diesel::PgConnection; use failure::Error; -use failure::_core::fmt::Debug; -use isahc::prelude::*; -use itertools::Itertools; -use log::debug; -use serde::{Deserialize, Serialize}; -use std::time::Duration; +use serde::Serialize; use url::Url; -use crate::api::comment::CommentResponse; -use crate::api::post::PostResponse; -use crate::api::site::SearchResponse; -use crate::api::user::PrivateMessageResponse; -use crate::db::comment::{Comment, CommentForm, CommentLike, CommentLikeForm}; -use crate::db::comment_view::CommentView; -use crate::db::community::{ - Community, CommunityFollower, CommunityFollowerForm, CommunityForm, CommunityModerator, - CommunityModeratorForm, -}; -use crate::db::community_view::{CommunityFollowerView, CommunityModeratorView, CommunityView}; -use crate::db::post::{Post, PostForm, PostLike, PostLikeForm}; -use crate::db::post_view::PostView; -use crate::db::private_message::{PrivateMessage, PrivateMessageForm}; -use crate::db::private_message_view::PrivateMessageView; -use crate::db::user::{UserForm, User_}; -use crate::db::user_view::UserView; -use crate::db::{Crud, Followable, Joinable, Likeable, SearchType}; -use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown}; -use crate::routes::{ChatServerParam, DbPoolParam}; -use crate::websocket::{ - server::{SendComment, SendPost, SendUserRoomMessage}, - UserOperation, -}; -use crate::{convert_datetime, naive_now, Settings}; - -use crate::apub::extensions::group_extensions::GroupExtension; -use crate::apub::extensions::page_extension::PageExtension; -use activities::{populate_object_props, send_activity}; -use chrono::NaiveDateTime; -use extensions::signatures::verify; -use extensions::signatures::{sign, PublicKey, PublicKeyExtension}; -use fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}; - type GroupExt = Ext, ApActorProperties>, PublicKeyExtension>; type PersonExt = Ext, PublicKeyExtension>; type PageExt = Ext; diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index b2374ffd7..2e567ab04 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -1,4 +1,38 @@ -use super::*; +use crate::{ + apub::{ + activities::{populate_object_props, send_activity}, + create_apub_response, + create_apub_tombstone_response, + create_tombstone, + extensions::page_extension::PageExtension, + fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, + ActorType, + ApubLikeableType, + ApubObjectType, + FromApub, + PageExt, + ToApub, + }, + convert_datetime, + db::{ + activity::insert_activity, + community::Community, + post::{Post, PostForm}, + user::User_, + Crud, + }, + routes::DbPoolParam, +}; +use activitystreams::{ + activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, + context, + ext::Extensible, + object::{kind::PageType, properties::ObjectProperties, Page, Tombstone}, +}; +use actix_web::{body::Body, web::Path, HttpResponse, Result}; +use diesel::PgConnection; +use failure::Error; +use serde::Deserialize; #[derive(Deserialize)] pub struct PostQuery { diff --git a/server/src/apub/private_message.rs b/server/src/apub/private_message.rs index 3fff75dc2..a222b1fef 100644 --- a/server/src/apub/private_message.rs +++ b/server/src/apub/private_message.rs @@ -1,4 +1,28 @@ -use super::*; +use crate::{ + apub::{ + activities::send_activity, + create_tombstone, + fetcher::get_or_fetch_and_upsert_remote_user, + ApubObjectType, + FromApub, + ToApub, + }, + convert_datetime, + db::{ + activity::insert_activity, + private_message::{PrivateMessage, PrivateMessageForm}, + user::User_, + Crud, + }, +}; +use activitystreams::{ + activity::{Create, Delete, Undo, Update}, + context, + object::{kind::NoteType, properties::ObjectProperties, Note, Tombstone}, +}; +use actix_web::Result; +use diesel::PgConnection; +use failure::Error; impl ToApub for PrivateMessage { type Response = Note; diff --git a/server/src/apub/shared_inbox.rs b/server/src/apub/shared_inbox.rs index 6bbe97251..51b7826df 100644 --- a/server/src/apub/shared_inbox.rs +++ b/server/src/apub/shared_inbox.rs @@ -1,4 +1,40 @@ -use super::*; +use crate::{ + api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse}, + apub::{ + extensions::signatures::verify, + fetcher::get_or_fetch_and_upsert_remote_user, + FromApub, + GroupExt, + PageExt, + }, + db::{ + activity::insert_activity, + comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, + comment_view::CommentView, + community::{Community, CommunityForm}, + community_view::CommunityView, + post::{Post, PostForm, PostLike, PostLikeForm}, + post_view::PostView, + Crud, + Likeable, + }, + naive_now, + routes::{ChatServerParam, DbPoolParam}, + websocket::{ + server::{SendComment, SendCommunityRoomMessage, SendPost}, + UserOperation, + }, +}; +use activitystreams::{ + activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, + object::Note, + BaseBox, +}; +use actix_web::{web, HttpRequest, HttpResponse, Result}; +use diesel::PgConnection; +use failure::{Error, _core::fmt::Debug}; +use log::debug; +use serde::{Deserialize, Serialize}; #[serde(untagged)] #[derive(Serialize, Deserialize, Debug)] diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs index 61661de47..dac6bc313 100644 --- a/server/src/apub/user.rs +++ b/server/src/apub/user.rs @@ -1,4 +1,33 @@ -use super::*; +use crate::{ + apub::{ + activities::send_activity, + create_apub_response, + extensions::signatures::PublicKey, + ActorType, + FromApub, + PersonExt, + ToApub, + }, + convert_datetime, + db::{ + activity::insert_activity, + user::{UserForm, User_}, + }, + naive_now, + routes::DbPoolParam, +}; +use activitystreams::{ + activity::{Follow, Undo}, + actor::{properties::ApActorProperties, Person}, + context, + endpoint::EndpointProperties, + ext::Extensible, + object::{properties::ObjectProperties, Tombstone}, +}; +use actix_web::{body::Body, web::Path, HttpResponse, Result}; +use diesel::PgConnection; +use failure::Error; +use serde::Deserialize; #[derive(Deserialize)] pub struct UserQuery { diff --git a/server/src/apub/user_inbox.rs b/server/src/apub/user_inbox.rs index 3035deba8..f60a2ba9b 100644 --- a/server/src/apub/user_inbox.rs +++ b/server/src/apub/user_inbox.rs @@ -1,4 +1,32 @@ -use super::*; +use crate::{ + api::user::PrivateMessageResponse, + apub::{ + extensions::signatures::verify, + fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, + FromApub, + }, + db::{ + activity::insert_activity, + community::{CommunityFollower, CommunityFollowerForm}, + private_message::{PrivateMessage, PrivateMessageForm}, + private_message_view::PrivateMessageView, + user::User_, + Crud, + Followable, + }, + naive_now, + routes::{ChatServerParam, DbPoolParam}, + websocket::{server::SendUserRoomMessage, UserOperation}, +}; +use activitystreams::{ + activity::{Accept, Create, Delete, Undo, Update}, + object::Note, +}; +use actix_web::{web, HttpRequest, HttpResponse, Result}; +use diesel::PgConnection; +use failure::{Error, _core::fmt::Debug}; +use log::debug; +use serde::Deserialize; #[serde(untagged)] #[derive(Deserialize, Debug)] diff --git a/server/src/db/activity.rs b/server/src/db/activity.rs index 70f9d6b64..bb8a74d47 100644 --- a/server/src/db/activity.rs +++ b/server/src/db/activity.rs @@ -1,5 +1,6 @@ -use super::*; -use crate::schema::activity; +use crate::{db::Crud, schema::activity}; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; use serde_json::Value; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] @@ -72,8 +73,8 @@ where #[cfg(test)] mod tests { - use super::super::user::*; - use super::*; + use super::{super::user::*, *}; + use crate::db::{establish_unpooled_connection, Crud, ListingType, SortType}; #[test] fn test_crud() { diff --git a/server/src/db/category.rs b/server/src/db/category.rs index 408c8231b..ff49bbbee 100644 --- a/server/src/db/category.rs +++ b/server/src/db/category.rs @@ -1,6 +1,9 @@ -use super::*; -use crate::schema::category; -use crate::schema::category::dsl::*; +use crate::{ + db::Crud, + schema::{category, category::dsl::*}, +}; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "category"] @@ -50,6 +53,8 @@ impl Category { #[cfg(test)] mod tests { use super::*; + use crate::db::establish_unpooled_connection; + #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/code_migrations.rs b/server/src/db/code_migrations.rs index b51996db2..204bfe791 100644 --- a/server/src/db/code_migrations.rs +++ b/server/src/db/code_migrations.rs @@ -1,13 +1,17 @@ // This is for db migrations that require code -use super::comment::Comment; -use super::community::{Community, CommunityForm}; -use super::post::Post; -use super::private_message::PrivateMessage; -use super::user::{UserForm, User_}; -use super::*; -use crate::apub::extensions::signatures::generate_actor_keypair; -use crate::apub::{make_apub_endpoint, EndpointType}; -use crate::naive_now; +use super::{ + comment::Comment, + community::{Community, CommunityForm}, + post::Post, + private_message::PrivateMessage, + user::{UserForm, User_}, +}; +use crate::{ + apub::{extensions::signatures::generate_actor_keypair, make_apub_endpoint, EndpointType}, + db::Crud, + naive_now, +}; +use diesel::*; use failure::Error; use log::info; diff --git a/server/src/db/comment.rs b/server/src/db/comment.rs index 2e8b54c3b..ddf1feef8 100644 --- a/server/src/db/comment.rs +++ b/server/src/db/comment.rs @@ -1,8 +1,9 @@ -use super::post::Post; -use super::*; -use crate::apub::{make_apub_endpoint, EndpointType}; -use crate::naive_now; -use crate::schema::{comment, comment_like, comment_saved}; +use super::{post::Post, *}; +use crate::{ + apub::{make_apub_endpoint, EndpointType}, + naive_now, + schema::{comment, comment_like, comment_saved}, +}; // WITH RECURSIVE MyTree AS ( // SELECT * FROM comment WHERE parent_id IS NULL @@ -203,10 +204,10 @@ impl Saveable for CommentSaved { #[cfg(test)] mod tests { - use super::super::community::*; - use super::super::post::*; - use super::super::user::*; - use super::*; + use super::{ + super::{community::*, post::*, user::*}, + *, + }; #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/comment_view.rs b/server/src/db/comment_view.rs index a94aa1579..52f7d9490 100644 --- a/server/src/db/comment_view.rs +++ b/server/src/db/comment_view.rs @@ -1,5 +1,6 @@ -use super::*; -use diesel::pg::Pg; +use crate::db::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType}; +use diesel::{dsl::*, pg::Pg, result::Error, *}; +use serde::{Deserialize, Serialize}; // The faked schema since diesel doesn't do views table! { @@ -453,11 +454,12 @@ impl<'a> ReplyQueryBuilder<'a> { #[cfg(test)] mod tests { - use super::super::comment::*; - use super::super::community::*; - use super::super::post::*; - use super::super::user::*; - use super::*; + use super::{ + super::{comment::*, community::*, post::*, user::*}, + *, + }; + use crate::db::{establish_unpooled_connection, Crud, Likeable}; + #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/community.rs b/server/src/db/community.rs index 9b858fde3..e7d923181 100644 --- a/server/src/db/community.rs +++ b/server/src/db/community.rs @@ -1,5 +1,10 @@ -use super::*; -use crate::schema::{community, community_follower, community_moderator, community_user_ban}; +use crate::{ + db::{Bannable, Crud, Followable, Joinable}, + schema::{community, community_follower, community_moderator, community_user_ban}, + settings::Settings, +}; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "community"] @@ -232,8 +237,9 @@ impl Followable for CommunityFollower { #[cfg(test)] mod tests { - use super::super::user::*; - use super::*; + use super::{super::user::*, *}; + use crate::db::{establish_unpooled_connection, ListingType, SortType}; + #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/community_view.rs b/server/src/db/community_view.rs index 3e946f472..ea7b2a7ca 100644 --- a/server/src/db/community_view.rs +++ b/server/src/db/community_view.rs @@ -1,6 +1,7 @@ use super::community_view::community_mview::BoxedQuery; -use super::*; -use diesel::pg::Pg; +use crate::db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType}; +use diesel::{pg::Pg, result::Error, *}; +use serde::{Deserialize, Serialize}; table! { community_view (id) { diff --git a/server/src/db/mod.rs b/server/src/db/mod.rs index ed334b8c7..da69f8dcd 100644 --- a/server/src/db/mod.rs +++ b/server/src/db/mod.rs @@ -1,7 +1,5 @@ use crate::settings::Settings; -use diesel::dsl::*; -use diesel::result::Error; -use diesel::*; +use diesel::{dsl::*, result::Error, *}; use serde::{Deserialize, Serialize}; pub mod activity; diff --git a/server/src/db/moderator.rs b/server/src/db/moderator.rs index a040c0ca8..d0f589e30 100644 --- a/server/src/db/moderator.rs +++ b/server/src/db/moderator.rs @@ -1,8 +1,19 @@ -use super::*; -use crate::schema::{ - mod_add, mod_add_community, mod_ban, mod_ban_from_community, mod_lock_post, mod_remove_comment, - mod_remove_community, mod_remove_post, mod_sticky_post, +use crate::{ + db::Crud, + schema::{ + mod_add, + mod_add_community, + mod_ban, + mod_ban_from_community, + mod_lock_post, + mod_remove_comment, + mod_remove_community, + mod_remove_post, + mod_sticky_post, + }, }; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "mod_remove_post"] @@ -426,11 +437,12 @@ impl Crud for ModAdd { #[cfg(test)] mod tests { - use super::super::comment::*; - use super::super::community::*; - use super::super::post::*; - use super::super::user::*; - use super::*; + use super::{ + super::{comment::*, community::*, post::*, user::*}, + *, + }; + use crate::db::{establish_unpooled_connection, ListingType, SortType}; + // use Crud; #[test] fn test_crud() { diff --git a/server/src/db/moderator_views.rs b/server/src/db/moderator_views.rs index 0413e0b10..f5b109fe6 100644 --- a/server/src/db/moderator_views.rs +++ b/server/src/db/moderator_views.rs @@ -1,4 +1,6 @@ -use super::*; +use crate::db::limit_and_offset; +use diesel::{result::Error, *}; +use serde::{Deserialize, Serialize}; table! { mod_remove_post_view (id) { diff --git a/server/src/db/password_reset_request.rs b/server/src/db/password_reset_request.rs index ea8b2964a..32d7f187d 100644 --- a/server/src/db/password_reset_request.rs +++ b/server/src/db/password_reset_request.rs @@ -1,6 +1,8 @@ -use super::*; -use crate::schema::password_reset_request; -use crate::schema::password_reset_request::dsl::*; +use crate::{ + db::Crud, + schema::{password_reset_request, password_reset_request::dsl::*}, +}; +use diesel::{dsl::*, result::Error, *}; use sha2::{Digest, Sha256}; #[derive(Queryable, Identifiable, PartialEq, Debug)] @@ -79,8 +81,8 @@ impl PasswordResetRequest { #[cfg(test)] mod tests { - use super::super::user::*; - use super::*; + use super::{super::user::*, *}; + use crate::db::{establish_unpooled_connection, ListingType, SortType}; #[test] fn test_crud() { diff --git a/server/src/db/post.rs b/server/src/db/post.rs index bdd330611..d12f98d81 100644 --- a/server/src/db/post.rs +++ b/server/src/db/post.rs @@ -1,7 +1,11 @@ -use super::*; -use crate::apub::{make_apub_endpoint, EndpointType}; -use crate::naive_now; -use crate::schema::{post, post_like, post_read, post_saved}; +use crate::{ + apub::{make_apub_endpoint, EndpointType}, + db::{Crud, Likeable, Readable, Saveable}, + naive_now, + schema::{post, post_like, post_read, post_saved}, +}; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "post"] @@ -237,9 +241,12 @@ impl Readable for PostRead { #[cfg(test)] mod tests { - use super::super::community::*; - use super::super::user::*; - use super::*; + use super::{ + super::{community::*, user::*}, + *, + }; + use crate::db::{establish_unpooled_connection, ListingType, SortType}; + #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/post_view.rs b/server/src/db/post_view.rs index a7ac58c03..094889422 100644 --- a/server/src/db/post_view.rs +++ b/server/src/db/post_view.rs @@ -1,6 +1,7 @@ use super::post_view::post_mview::BoxedQuery; -use super::*; -use diesel::pg::Pg; +use crate::db::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType}; +use diesel::{dsl::*, pg::Pg, result::Error, *}; +use serde::{Deserialize, Serialize}; // The faked schema since diesel doesn't do views table! { @@ -363,10 +364,12 @@ impl PostView { #[cfg(test)] mod tests { - use super::super::community::*; - use super::super::post::*; - use super::super::user::*; - use super::*; + use super::{ + super::{community::*, post::*, user::*}, + *, + }; + use crate::db::{establish_unpooled_connection, Crud, Likeable}; + #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/private_message.rs b/server/src/db/private_message.rs index b765bef49..e8b28485e 100644 --- a/server/src/db/private_message.rs +++ b/server/src/db/private_message.rs @@ -1,6 +1,10 @@ -use super::*; -use crate::apub::{make_apub_endpoint, EndpointType}; -use crate::schema::private_message; +use crate::{ + apub::{make_apub_endpoint, EndpointType}, + db::Crud, + schema::private_message, +}; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "private_message"] @@ -85,8 +89,9 @@ impl PrivateMessage { #[cfg(test)] mod tests { - use super::super::user::*; - use super::*; + use super::{super::user::*, *}; + use crate::db::{establish_unpooled_connection, ListingType, SortType}; + #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/private_message_view.rs b/server/src/db/private_message_view.rs index 436178e1e..9a1df4397 100644 --- a/server/src/db/private_message_view.rs +++ b/server/src/db/private_message_view.rs @@ -1,5 +1,6 @@ -use super::*; -use diesel::pg::Pg; +use crate::db::{limit_and_offset, MaybeOptional}; +use diesel::{pg::Pg, result::Error, *}; +use serde::{Deserialize, Serialize}; // The faked schema since diesel doesn't do views table! { diff --git a/server/src/db/site.rs b/server/src/db/site.rs index 3b8366d81..c752bfe79 100644 --- a/server/src/db/site.rs +++ b/server/src/db/site.rs @@ -1,5 +1,6 @@ -use super::*; -use crate::schema::site; +use crate::{db::Crud, schema::site}; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "site"] diff --git a/server/src/db/site_view.rs b/server/src/db/site_view.rs index 674a7a6e7..bb9b54aa6 100644 --- a/server/src/db/site_view.rs +++ b/server/src/db/site_view.rs @@ -1,4 +1,5 @@ -use super::*; +use diesel::{result::Error, *}; +use serde::{Deserialize, Serialize}; table! { site_view (id) { diff --git a/server/src/db/user.rs b/server/src/db/user.rs index 065b2c578..8b2ff62aa 100644 --- a/server/src/db/user.rs +++ b/server/src/db/user.rs @@ -1,9 +1,14 @@ -use super::*; -use crate::schema::user_; -use crate::schema::user_::dsl::*; -use crate::{is_email_regex, naive_now, Settings}; +use crate::{ + db::Crud, + is_email_regex, + naive_now, + schema::{user_, user_::dsl::*}, + settings::Settings, +}; use bcrypt::{hash, DEFAULT_COST}; +use diesel::{dsl::*, result::Error, *}; use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "user_"] @@ -208,8 +213,8 @@ impl User_ { #[cfg(test)] mod tests { - use super::User_; - use super::*; + use super::{User_, *}; + use crate::db::{establish_unpooled_connection, ListingType, SortType}; #[test] fn test_crud() { diff --git a/server/src/db/user_mention.rs b/server/src/db/user_mention.rs index d8305d395..b9129b01f 100644 --- a/server/src/db/user_mention.rs +++ b/server/src/db/user_mention.rs @@ -1,6 +1,7 @@ use super::comment::Comment; -use super::*; -use crate::schema::user_mention; +use crate::{db::Crud, schema::user_mention}; +use diesel::{dsl::*, result::Error, *}; +use serde::{Deserialize, Serialize}; #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[belongs_to(Comment)] @@ -53,11 +54,12 @@ impl Crud for UserMention { #[cfg(test)] mod tests { - use super::super::comment::*; - use super::super::community::*; - use super::super::post::*; - use super::super::user::*; - use super::*; + use super::{ + super::{comment::*, community::*, post::*, user::*}, + *, + }; + use crate::db::{establish_unpooled_connection, ListingType, SortType}; + #[test] fn test_crud() { let conn = establish_unpooled_connection(); diff --git a/server/src/db/user_mention_view.rs b/server/src/db/user_mention_view.rs index 85fd760fc..100445b99 100644 --- a/server/src/db/user_mention_view.rs +++ b/server/src/db/user_mention_view.rs @@ -1,5 +1,6 @@ -use super::*; -use diesel::pg::Pg; +use crate::db::{limit_and_offset, MaybeOptional, SortType}; +use diesel::{dsl::*, pg::Pg, result::Error, *}; +use serde::{Deserialize, Serialize}; // The faked schema since diesel doesn't do views table! { diff --git a/server/src/db/user_view.rs b/server/src/db/user_view.rs index 88cbb7fb6..57e2a4c9c 100644 --- a/server/src/db/user_view.rs +++ b/server/src/db/user_view.rs @@ -1,6 +1,7 @@ use super::user_view::user_mview::BoxedQuery; -use super::*; -use diesel::pg::Pg; +use crate::db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType}; +use diesel::{dsl::*, pg::Pg, result::Error, *}; +use serde::{Deserialize, Serialize}; table! { user_view (id) { diff --git a/server/src/lib.rs b/server/src/lib.rs index ce886754e..4630012bf 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -40,15 +40,20 @@ use crate::settings::Settings; use actix_web::dev::ConnectionInfo; use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, Utc}; use isahc::prelude::*; -use lettre::smtp::authentication::{Credentials, Mechanism}; -use lettre::smtp::extension::ClientId; -use lettre::smtp::ConnectionReuseParameters; -use lettre::{ClientSecurity, SmtpClient, Transport}; +use lettre::{ + smtp::{ + authentication::{Credentials, Mechanism}, + extension::ClientId, + ConnectionReuseParameters, + }, + ClientSecurity, + SmtpClient, + Transport, +}; use lettre_email::Email; use log::error; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; -use rand::distributions::Alphanumeric; -use rand::{thread_rng, Rng}; +use rand::{distributions::Alphanumeric, thread_rng, Rng}; use regex::{Regex, RegexBuilder}; use serde::Deserialize; diff --git a/server/src/main.rs b/server/src/main.rs index 205d3426e..4339e5f06 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -4,8 +4,10 @@ extern crate diesel_migrations; use actix::prelude::*; use actix_web::*; -use diesel::r2d2::{ConnectionManager, Pool}; -use diesel::PgConnection; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; use failure::Error; use lemmy_server::{ db::code_migrations::run_advanced_migrations, diff --git a/server/src/rate_limit/mod.rs b/server/src/rate_limit/mod.rs index fec8a5692..b4c2dc5db 100644 --- a/server/src/rate_limit/mod.rs +++ b/server/src/rate_limit/mod.rs @@ -1,23 +1,18 @@ -pub mod rate_limiter; - use super::{IPAddr, Settings}; -use crate::api::APIError; -use crate::get_ip; -use crate::settings::RateLimitConfig; +use crate::{api::APIError, get_ip, settings::RateLimitConfig}; use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; -use failure::Error; use futures::future::{ok, Ready}; -use log::debug; use rate_limiter::{RateLimitType, RateLimiter}; -use std::collections::HashMap; -use std::future::Future; -use std::pin::Pin; -use std::sync::Arc; -use std::task::{Context, Poll}; -use std::time::SystemTime; -use strum::IntoEnumIterator; +use std::{ + future::Future, + pin::Pin, + sync::Arc, + task::{Context, Poll}, +}; use tokio::sync::Mutex; +pub mod rate_limiter; + #[derive(Debug, Clone)] pub struct RateLimit { pub rate_limiter: Arc>, @@ -92,7 +87,7 @@ impl RateLimited { } RateLimitType::Post => { limiter.check_rate_limit_full( - self.type_.clone(), + self.type_, &ip_addr, rate_limit.post, rate_limit.post_per_second, diff --git a/server/src/rate_limit/rate_limiter.rs b/server/src/rate_limit/rate_limiter.rs index a30efa094..b3ac7093c 100644 --- a/server/src/rate_limit/rate_limiter.rs +++ b/server/src/rate_limit/rate_limiter.rs @@ -1,4 +1,9 @@ -use super::*; +use super::IPAddr; +use crate::api::APIError; +use failure::Error; +use log::debug; +use std::{collections::HashMap, time::SystemTime}; +use strum::IntoEnumIterator; #[derive(Debug, Clone)] pub struct RateLimitBucket { diff --git a/server/src/routes/api.rs b/server/src/routes/api.rs index ec9f61e8c..6ee94691d 100644 --- a/server/src/routes/api.rs +++ b/server/src/routes/api.rs @@ -1,10 +1,11 @@ -use super::*; -use crate::api::comment::*; -use crate::api::community::*; -use crate::api::post::*; -use crate::api::site::*; -use crate::api::user::*; -use crate::rate_limit::RateLimit; +use crate::{ + api::{comment::*, community::*, post::*, site::*, user::*, Oper, Perform}, + rate_limit::RateLimit, + routes::{ChatServerParam, DbPoolParam}, + websocket::WebsocketInfo, +}; +use actix_web::{error::ErrorBadRequest, *}; +use serde::Serialize; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { cfg.service( diff --git a/server/src/routes/federation.rs b/server/src/routes/federation.rs index ed5c25965..fe6e33657 100644 --- a/server/src/routes/federation.rs +++ b/server/src/routes/federation.rs @@ -1,12 +1,17 @@ -use super::*; -use crate::apub::comment::get_apub_comment; -use crate::apub::community::*; -use crate::apub::community_inbox::community_inbox; -use crate::apub::post::get_apub_post; -use crate::apub::shared_inbox::shared_inbox; -use crate::apub::user::*; -use crate::apub::user_inbox::user_inbox; -use crate::apub::APUB_JSON_CONTENT_TYPE; +use crate::{ + apub::{ + comment::get_apub_comment, + community::*, + community_inbox::community_inbox, + post::get_apub_post, + shared_inbox::shared_inbox, + user::*, + user_inbox::user_inbox, + APUB_JSON_CONTENT_TYPE, + }, + settings::Settings, +}; +use actix_web::*; pub fn config(cfg: &mut web::ServiceConfig) { if Settings::get().federation.enabled { diff --git a/server/src/routes/feeds.rs b/server/src/routes/feeds.rs index 6bb70b931..e582c2f3f 100644 --- a/server/src/routes/feeds.rs +++ b/server/src/routes/feeds.rs @@ -1,11 +1,28 @@ -use super::*; -use crate::db::comment_view::{ReplyQueryBuilder, ReplyView}; -use crate::db::community::Community; -use crate::db::post_view::{PostQueryBuilder, PostView}; -use crate::db::site_view::SiteView; -use crate::db::user::{Claims, User_}; -use crate::db::user_mention_view::{UserMentionQueryBuilder, UserMentionView}; -use crate::db::{ListingType, SortType}; +use crate::{ + db::{ + comment_view::{ReplyQueryBuilder, ReplyView}, + community::Community, + post_view::{PostQueryBuilder, PostView}, + site_view::SiteView, + user::{Claims, User_}, + user_mention_view::{UserMentionQueryBuilder, UserMentionView}, + ListingType, + SortType, + }, + markdown_to_html, + routes::DbPoolParam, + settings::Settings, +}; +use actix_web::{error::ErrorBadRequest, *}; +use chrono::{DateTime, NaiveDateTime, Utc}; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; +use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder}; +use serde::Deserialize; +use std::str::FromStr; +use strum::ParseError; #[derive(Deserialize)] pub struct Params { @@ -21,8 +38,8 @@ enum RequestType { pub fn config(cfg: &mut web::ServiceConfig) { cfg - .route("/feeds/{type}/{name}.xml", web::get().to(feeds::get_feed)) - .route("/feeds/all.xml", web::get().to(feeds::get_all_feed)); + .route("/feeds/{type}/{name}.xml", web::get().to(get_feed)) + .route("/feeds/all.xml", web::get().to(get_all_feed)); } async fn get_all_feed(info: web::Query, db: DbPoolParam) -> Result { diff --git a/server/src/routes/index.rs b/server/src/routes/index.rs index 895af4350..2f462aa5f 100644 --- a/server/src/routes/index.rs +++ b/server/src/routes/index.rs @@ -1,4 +1,6 @@ -use super::*; +use crate::settings::Settings; +use actix_files::NamedFile; +use actix_web::*; pub fn config(cfg: &mut web::ServiceConfig) { cfg diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs index 109dbd76d..bcb7e45fa 100644 --- a/server/src/routes/mod.rs +++ b/server/src/routes/mod.rs @@ -1,33 +1,3 @@ -use crate::api::{Oper, Perform}; -use crate::apub::get_apub_protocol_string; -use crate::db::site_view::SiteView; -use crate::rate_limit::rate_limiter::RateLimiter; -use crate::websocket::{server::ChatServer, WebsocketInfo}; -use crate::{get_ip, markdown_to_html, version, Settings}; -use actix::prelude::*; -use actix_files::NamedFile; -use actix_web::{body::Body, error::ErrorBadRequest, web::Query, *}; -use actix_web_actors::ws; -use chrono::{DateTime, NaiveDateTime, Utc}; -use diesel::{ - r2d2::{ConnectionManager, Pool}, - PgConnection, -}; -use log::{error, info}; -use regex::Regex; -use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder}; -use serde::{Deserialize, Serialize}; -use serde_json::json; -use std::str::FromStr; -use std::sync::{Arc, Mutex}; -use std::time::{Duration, Instant}; -use strum::ParseError; -use url::Url; - -pub type DbPoolParam = web::Data>>; -pub type RateLimitParam = web::Data>>; -pub type ChatServerParam = web::Data>; - pub mod api; pub mod federation; pub mod feeds; @@ -35,3 +5,16 @@ pub mod index; pub mod nodeinfo; pub mod webfinger; pub mod websocket; + +use crate::{rate_limit::rate_limiter::RateLimiter, websocket::server::ChatServer}; +use actix::prelude::*; +use actix_web::*; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; +use std::sync::{Arc, Mutex}; + +pub type DbPoolParam = web::Data>>; +pub type RateLimitParam = web::Data>>; +pub type ChatServerParam = web::Data>; diff --git a/server/src/routes/nodeinfo.rs b/server/src/routes/nodeinfo.rs index fa75d19bf..db206a3e8 100644 --- a/server/src/routes/nodeinfo.rs +++ b/server/src/routes/nodeinfo.rs @@ -1,4 +1,13 @@ -use super::*; +use crate::{ + apub::get_apub_protocol_string, + db::site_view::SiteView, + routes::DbPoolParam, + version, + Settings, +}; +use actix_web::{body::Body, error::ErrorBadRequest, *}; +use serde::{Deserialize, Serialize}; +use url::Url; pub fn config(cfg: &mut web::ServiceConfig) { cfg diff --git a/server/src/routes/webfinger.rs b/server/src/routes/webfinger.rs index 7bdce2067..e6ce84110 100644 --- a/server/src/routes/webfinger.rs +++ b/server/src/routes/webfinger.rs @@ -1,5 +1,8 @@ -use super::*; -use crate::db::community::Community; +use crate::{db::community::Community, routes::DbPoolParam, Settings}; +use actix_web::{error::ErrorBadRequest, web::Query, *}; +use regex::Regex; +use serde::Deserialize; +use serde_json::json; #[derive(Deserialize)] pub struct Params { diff --git a/server/src/routes/websocket.rs b/server/src/routes/websocket.rs index a95ff9ee8..06d9b66d2 100644 --- a/server/src/routes/websocket.rs +++ b/server/src/routes/websocket.rs @@ -1,5 +1,12 @@ -use super::*; -use crate::websocket::server::*; +use crate::{ + get_ip, + websocket::server::{ChatServer, *}, +}; +use actix::prelude::*; +use actix_web::*; +use actix_web_actors::ws; +use log::{error, info}; +use std::time::{Duration, Instant}; /// How often heartbeat pings are sent const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5); diff --git a/server/src/settings.rs b/server/src/settings.rs index c19cb7175..e1ac759c5 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -1,10 +1,7 @@ use config::{Config, ConfigError, Environment, File}; use failure::Error; use serde::Deserialize; -use std::env; -use std::fs; -use std::net::IpAddr; -use std::sync::RwLock; +use std::{env, fs, net::IpAddr, sync::RwLock}; static CONFIG_FILE_DEFAULTS: &str = "config/defaults.hjson"; static CONFIG_FILE: &str = "config/config.hjson"; diff --git a/server/src/websocket/mod.rs b/server/src/websocket/mod.rs index fd200d7d6..4eb43e49d 100644 --- a/server/src/websocket/mod.rs +++ b/server/src/websocket/mod.rs @@ -2,16 +2,20 @@ pub mod server; use crate::ConnectionId; use actix::prelude::*; -use diesel::r2d2::{ConnectionManager, Pool}; -use diesel::PgConnection; +use diesel::{ + r2d2::{ConnectionManager, Pool}, + PgConnection, +}; use failure::Error; use log::{error, info}; use rand::{rngs::ThreadRng, Rng}; use serde::{Deserialize, Serialize}; use serde_json::Value; use server::ChatServer; -use std::collections::{HashMap, HashSet}; -use std::str::FromStr; +use std::{ + collections::{HashMap, HashSet}, + str::FromStr, +}; #[derive(EnumString, ToString, Debug, Clone)] pub enum UserOperation { diff --git a/server/src/websocket/server.rs b/server/src/websocket/server.rs index da5098e91..e4543ea1f 100644 --- a/server/src/websocket/server.rs +++ b/server/src/websocket/server.rs @@ -3,15 +3,16 @@ //! room through `ChatServer`. use super::*; -use crate::api::comment::*; -use crate::api::community::*; -use crate::api::post::*; -use crate::api::site::*; -use crate::api::user::*; -use crate::api::*; -use crate::rate_limit::RateLimit; -use crate::websocket::UserOperation; -use crate::{CommunityId, ConnectionId, IPAddr, PostId, UserId}; +use crate::{ + api::{comment::*, community::*, post::*, site::*, user::*, *}, + rate_limit::RateLimit, + websocket::UserOperation, + CommunityId, + ConnectionId, + IPAddr, + PostId, + UserId, +}; /// Chat server sends this messages to session #[derive(Message)] @@ -940,7 +941,7 @@ impl Handler for ChatServer { id, SessionInfo { addr: msg.addr, - ip: msg.ip.to_owned(), + ip: msg.ip, }, );