From b55622f2b1cf6ed64f6763debc285a8c9d1bd195 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 19 May 2018 08:39:59 +0100 Subject: [PATCH] Reorganize use statements --- src/activity_pub/inbox.rs | 22 +++++++++------ src/activity_pub/mod.rs | 8 ++++-- src/activity_pub/object.rs | 1 - src/activity_pub/request.rs | 3 -- src/activity_pub/sign.rs | 10 ++++--- src/activity_pub/webfinger.rs | 6 ++-- src/db_conn.rs | 10 +++---- src/main.rs | 3 +- src/models/blogs.rs | 30 ++++++++++++-------- src/models/comments.rs | 14 +++++---- src/models/likes.rs | 14 +++++---- src/models/post_authors.rs | 6 ++-- src/models/posts.rs | 18 +++++++----- src/models/users.rs | 53 ++++++++++++++++++++--------------- src/routes/blogs.rs | 21 ++++++++------ src/routes/comments.rs | 11 ++++---- src/routes/instance.rs | 11 ++++---- src/routes/likes.rs | 8 ++++-- src/routes/notifications.rs | 3 +- src/routes/posts.rs | 15 +++++----- src/routes/session.rs | 9 +++--- src/routes/user.rs | 21 ++++++++------ src/routes/well_known.rs | 6 ++-- 23 files changed, 173 insertions(+), 130 deletions(-) diff --git a/src/activity_pub/inbox.rs b/src/activity_pub/inbox.rs index 55f22dae..e6629119 100644 --- a/src/activity_pub/inbox.rs +++ b/src/activity_pub/inbox.rs @@ -8,15 +8,19 @@ use diesel::PgConnection; use failure::Error; use serde_json; -use activity_pub::{broadcast, Id, IntoId}; -use activity_pub::actor::Actor as APActor; -use activity_pub::sign::*; -use models::blogs::Blog; -use models::comments::*; -use models::follows; -use models::likes; -use models::posts::*; -use models::users::User; +use activity_pub::{ + broadcast, Id, IntoId, + actor::Actor as APActor, + sign::* +}; +use models::{ + blogs::Blog, + comments::*, + follows, + likes, + posts::*, + users::User +}; #[derive(Fail, Debug)] enum InboxError { diff --git a/src/activity_pub/mod.rs b/src/activity_pub/mod.rs index cfb38314..35e5ee5e 100644 --- a/src/activity_pub/mod.rs +++ b/src/activity_pub/mod.rs @@ -2,9 +2,11 @@ use activitystreams_traits::{Activity, Actor, Object, Link}; use array_tool::vec::Uniq; use diesel::PgConnection; use reqwest::Client; -use rocket::http::{ContentType, Status}; -use rocket::response::{Response, Responder, Content}; -use rocket::request::Request; +use rocket::{ + http::{ContentType, Status}, + response::{Response, Responder, Content}, + request::Request +}; use rocket_contrib::Json; use serde_json; diff --git a/src/activity_pub/object.rs b/src/activity_pub/object.rs index c3d76893..a06c671e 100644 --- a/src/activity_pub/object.rs +++ b/src/activity_pub/object.rs @@ -6,4 +6,3 @@ pub trait Object { fn compute_id(&self, conn: &PgConnection) -> String; } - diff --git a/src/activity_pub/request.rs b/src/activity_pub/request.rs index 0db67b70..afde1b89 100644 --- a/src/activity_pub/request.rs +++ b/src/activity_pub/request.rs @@ -27,11 +27,8 @@ pub fn signature(signer: &S, headers: Headers, conn: &PgConnection) - let signed_string = headers.iter().map(|h| format!("{}: {}", h.name().to_lowercase(), h.value_string())).collect::>().join("\n"); let signed_headers = headers.iter().map(|h| h.name().to_string()).collect::>().join(" ").to_lowercase(); - println!("Signing {}", signed_string); - println!("signed header {}", signed_headers); let data = signer.sign(signed_string); let sign = base64::encode(&data[..]); - println!("sigature {}", sign); Signature(format!( "keyId=\"{key_id}\",algorithm=\"rsa-sha256\",headers=\"{signed_headers}\",signature=\"{signature}\"", diff --git a/src/activity_pub/sign.rs b/src/activity_pub/sign.rs index bc0197fb..cdc4c740 100644 --- a/src/activity_pub/sign.rs +++ b/src/activity_pub/sign.rs @@ -1,10 +1,12 @@ use base64; +use chrono::Utc; use diesel::PgConnection; use hex; -use chrono::Utc; -use openssl::pkey::PKey; -use openssl::rsa::Rsa; -use openssl::sha::sha256; +use openssl::{ + pkey::PKey, + rsa::Rsa, + sha::sha256 +}; use serde_json; /// Returns (public key, private key) diff --git a/src/activity_pub/webfinger.rs b/src/activity_pub/webfinger.rs index acc4f1ff..7803fa2e 100644 --- a/src/activity_pub/webfinger.rs +++ b/src/activity_pub/webfinger.rs @@ -1,7 +1,9 @@ use diesel::PgConnection; use reqwest::Client; -use reqwest::header::{Accept, qitem}; -use reqwest::mime::Mime; +use reqwest::{ + header::{Accept, qitem}, + mime::Mime +}; use serde_json; use activity_pub::ap_url; diff --git a/src/db_conn.rs b/src/db_conn.rs index f2c520d9..c12b011d 100644 --- a/src/db_conn.rs +++ b/src/db_conn.rs @@ -1,8 +1,8 @@ -use diesel::pg::PgConnection; -use diesel::r2d2::{ConnectionManager, Pool, PooledConnection}; -use rocket::{Request, State, Outcome}; -use rocket::http::Status; -use rocket::request::{self, FromRequest}; +use diesel::{ + pg::PgConnection, + r2d2::{ConnectionManager, Pool, PooledConnection} +}; +use rocket::{Request, State, Outcome, http::Status, request::{self, FromRequest}}; use std::ops::Deref; // From rocket documentation diff --git a/src/main.rs b/src/main.rs index 4d17a369..cbd27b47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,8 +33,7 @@ extern crate serde_derive; extern crate serde_json; extern crate url; -use diesel::pg::PgConnection; -use diesel::r2d2::{ConnectionManager, Pool}; +use diesel::{pg::PgConnection, r2d2::{ConnectionManager, Pool}}; use dotenv::dotenv; use rocket_contrib::Template; use std::env; diff --git a/src/models/blogs.rs b/src/models/blogs.rs index f246dda8..46765486 100644 --- a/src/models/blogs.rs +++ b/src/models/blogs.rs @@ -1,22 +1,28 @@ use activitystreams_traits::{Actor, Object}; use activitystreams_types::collection::OrderedCollection; -use reqwest::Client; -use reqwest::header::{Accept, qitem}; -use reqwest::mime::Mime; +use reqwest::{ + Client, + header::{Accept, qitem}, + mime::Mime +}; use serde_json; use url::Url; use chrono::NaiveDateTime; use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection}; -use openssl::hash::MessageDigest; -use openssl::pkey::{PKey, Private}; -use openssl::rsa::Rsa; -use openssl::sign::Signer; +use openssl::{ + hash::MessageDigest, + pkey::{PKey, Private}, + rsa::Rsa, + sign::Signer +}; -use activity_pub::{ActivityStream, Id, IntoId}; -use activity_pub::actor::{Actor as APActor, ActorType}; -use activity_pub::inbox::WithInbox; -use activity_pub::sign; -use activity_pub::webfinger::*; +use activity_pub::{ + ActivityStream, Id, IntoId, + actor::{Actor as APActor, ActorType}, + inbox::WithInbox, + sign, + webfinger::* +}; use models::instance::Instance; use schema::blogs; diff --git a/src/models/comments.rs b/src/models/comments.rs index 14a73bbf..8a24195e 100644 --- a/src/models/comments.rs +++ b/src/models/comments.rs @@ -6,11 +6,15 @@ use chrono; use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods}; use serde_json; -use activity_pub::{ap_url, IntoId, PUBLIC_VISIBILTY}; -use activity_pub::actor::Actor; -use activity_pub::object::Object; -use models::posts::Post; -use models::users::User; +use activity_pub::{ + ap_url, IntoId, PUBLIC_VISIBILTY, + actor::Actor, + object::Object +}; +use models::{ + posts::Post, + users::User +}; use schema::comments; #[derive(Queryable, Identifiable, Serialize, Clone)] diff --git a/src/models/likes.rs b/src/models/likes.rs index 31de4f0d..acf505dc 100644 --- a/src/models/likes.rs +++ b/src/models/likes.rs @@ -3,11 +3,15 @@ use chrono; use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods}; use serde_json; -use activity_pub::IntoId; -use activity_pub::actor::Actor; -use activity_pub::object::Object; -use models::posts::Post; -use models::users::User; +use activity_pub::{ + IntoId, + actor::Actor, + object::Object +}; +use models::{ + posts::Post, + users::User +}; use schema::likes; #[derive(Queryable, Identifiable)] diff --git a/src/models/post_authors.rs b/src/models/post_authors.rs index 1220deb0..e5849c65 100644 --- a/src/models/post_authors.rs +++ b/src/models/post_authors.rs @@ -1,7 +1,9 @@ use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods}; -use models::posts::Post; -use models::users::User; +use models::{ + posts::Post, + users::User +}; use schema::post_authors; #[derive(Queryable, Identifiable, Associations)] diff --git a/src/models/posts.rs b/src/models/posts.rs index 743f7ea6..dcb94837 100644 --- a/src/models/posts.rs +++ b/src/models/posts.rs @@ -8,13 +8,17 @@ use diesel::dsl::any; use serde_json; use BASE_URL; -use activity_pub::{PUBLIC_VISIBILTY, ap_url, Id, IntoId}; -use activity_pub::actor::Actor; -use activity_pub::object::Object; -use models::blogs::Blog; -use models::likes::Like; -use models::users::User; -use models::post_authors::PostAuthor; +use activity_pub::{ + PUBLIC_VISIBILTY, ap_url, Id, IntoId, + actor::Actor, + object::Object +}; +use models::{ + blogs::Blog, + likes::Like, + post_authors::PostAuthor, + users::User +}; use schema::posts; #[derive(Queryable, Identifiable, Serialize)] diff --git a/src/models/users.rs b/src/models/users.rs index b4614454..92b85715 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -7,33 +7,42 @@ use activitystreams_types::{ }; use bcrypt; use chrono::NaiveDateTime; -use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, BelongingToDsl, PgConnection}; -use diesel::dsl::any; -use openssl::hash::MessageDigest; -use openssl::pkey::{PKey, Private}; -use openssl::rsa::Rsa; -use openssl::sign; -use reqwest::Client; -use reqwest::header::{Accept, qitem}; -use reqwest::mime::Mime; -use rocket::request::{self, FromRequest, Request}; -use rocket::outcome::IntoOutcome; +use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, BelongingToDsl, PgConnection, dsl::any}; +use openssl::{ + hash::MessageDigest, + pkey::{PKey, Private}, + rsa::Rsa, + sign +}; +use reqwest::{ + Client, + header::{Accept, qitem}, + mime::Mime +}; +use rocket::{ + request::{self, FromRequest, Request}, + outcome::IntoOutcome +}; use serde_json; use url::Url; use BASE_URL; -use activity_pub::{ap_url, ActivityStream, Id, IntoId}; -use activity_pub::actor::{ActorType, Actor as APActor}; -use activity_pub::inbox::{Inbox, WithInbox}; -use activity_pub::sign::{Signer, gen_keypair}; -use activity_pub::webfinger::{Webfinger, resolve}; +use activity_pub::{ + ap_url, ActivityStream, Id, IntoId, + actor::{ActorType, Actor as APActor}, + inbox::{Inbox, WithInbox}, + sign::{Signer, gen_keypair}, + webfinger::{Webfinger, resolve} +}; use db_conn::DbConn; -use models::comments::Comment; -use models::follows::Follow; -use models::instance::Instance; -use models::notifications::*; -use models::post_authors::PostAuthor; -use models::posts::Post; +use models::{ + comments::Comment, + follows::Follow, + instance::Instance, + notifications::*, + post_authors::PostAuthor, + posts::Post +}; use schema::users; pub const AUTH_COOKIE: &'static str = "user_id"; diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index db957a01..08fea83b 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -1,17 +1,20 @@ use activitystreams_types::collection::OrderedCollection; -use rocket::request::Form; -use rocket::response::Redirect; +use rocket::{ + request::Form, + response::Redirect +}; use rocket_contrib::Template; use serde_json; -use activity_pub::{ActivityStream, ActivityPub}; -use activity_pub::actor::Actor; +use activity_pub::{ActivityStream, ActivityPub, actor::Actor}; use db_conn::DbConn; -use models::blog_authors::*; -use models::blogs::*; -use models::instance::Instance; -use models::posts::Post; -use models::users::User; +use models::{ + blog_authors::*, + blogs::*, + instance::Instance, + posts::Post, + users::User +}; use utils; #[get("/~/", rank = 2)] diff --git a/src/routes/comments.rs b/src/routes/comments.rs index 4561b731..2a47b87f 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -1,12 +1,13 @@ -use rocket::request::Form; -use rocket::response::Redirect; +use rocket::{ request::Form, response::Redirect}; use rocket_contrib::Template; use activity_pub::broadcast; use db_conn::DbConn; -use models::comments::*; -use models::posts::Post; -use models::users::User; +use models::{ + comments::*, + posts::Post, + users::User +}; #[get("/~/<_blog>//comment")] fn new(_blog: String, slug: String, user: User, conn: DbConn) -> Template { diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 77cf1d9e..f181ecf2 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -1,14 +1,15 @@ -use rocket::request::Form; -use rocket::response::Redirect; +use rocket::{request::Form, response::Redirect}; use rocket_contrib::Template; use serde_json; use BASE_URL; use activity_pub::inbox::Inbox; use db_conn::DbConn; -use models::posts::Post; -use models::users::User; -use models::instance::*; +use models::{ + posts::Post, + users::User, + instance::* +}; #[get("/")] fn index(conn: DbConn, user: Option) -> Template { diff --git a/src/routes/likes.rs b/src/routes/likes.rs index 13049922..11c578bb 100644 --- a/src/routes/likes.rs +++ b/src/routes/likes.rs @@ -2,9 +2,11 @@ use rocket::response::Redirect; use activity_pub::broadcast; use db_conn::DbConn; -use models::likes; -use models::posts::Post; -use models::users::User; +use models::{ + likes, + posts::Post, + users::User +}; #[get("/~///like")] fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect { diff --git a/src/routes/notifications.rs b/src/routes/notifications.rs index deb96267..ae8c0d0b 100644 --- a/src/routes/notifications.rs +++ b/src/routes/notifications.rs @@ -1,8 +1,7 @@ use rocket_contrib::Template; use db_conn::DbConn; -use models::notifications::Notification; -use models::users::User; +use models::{notifications::Notification, users::User}; #[get("/notifications")] fn notifications(conn: DbConn, user: User) -> Template { diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 3732dcbc..857d16f3 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -4,14 +4,15 @@ use rocket::response::Redirect; use rocket_contrib::Template; use serde_json; -use activity_pub::{broadcast, context, activity_pub, ActivityPub}; -use activity_pub::object::Object; +use activity_pub::{broadcast, context, activity_pub, ActivityPub, object::Object}; use db_conn::DbConn; -use models::blogs::*; -use models::comments::Comment; -use models::post_authors::*; -use models::posts::*; -use models::users::User; +use models::{ + blogs::*, + comments::Comment, + post_authors::*, + posts::*, + users::User +}; use utils; #[get("/~//", rank = 4)] diff --git a/src/routes/session.rs b/src/routes/session.rs index 721d8575..f8a1ed94 100644 --- a/src/routes/session.rs +++ b/src/routes/session.rs @@ -1,7 +1,8 @@ -use rocket::http::{Cookie, Cookies}; -use rocket::response::Redirect; -use rocket::response::status::NotFound; -use rocket::request::Form; +use rocket::{ + http::{Cookie, Cookies}, + response::{Redirect, status::NotFound}, + request::Form +}; use rocket_contrib::Template; use db_conn::DbConn; diff --git a/src/routes/user.rs b/src/routes/user.rs index d1115de1..4c7854d7 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -2,19 +2,22 @@ use activitystreams_types::{ activity::Follow, collection::OrderedCollection }; -use rocket::request::Form; -use rocket::response::Redirect; +use rocket::{request::Form, response::Redirect}; use rocket_contrib::Template; use serde_json; -use activity_pub::{activity_pub, ActivityPub, ActivityStream, context, broadcast, Id, IntoId}; -use activity_pub::actor::Actor; -use activity_pub::inbox::Inbox; +use activity_pub::{ + activity_pub, ActivityPub, ActivityStream, context, broadcast, Id, IntoId, + actor::Actor, + object::Object +}; use db_conn::DbConn; -use models::follows; -use models::instance::Instance; -use models::posts::Post; -use models::users::*; +use models::{ + follows, + instance::Instance, + posts::Post, + users::* +}; #[get("/me")] fn me(user: User) -> Redirect { diff --git a/src/routes/well_known.rs b/src/routes/well_known.rs index 6f07a46c..e0cdae50 100644 --- a/src/routes/well_known.rs +++ b/src/routes/well_known.rs @@ -2,11 +2,9 @@ use rocket::http::ContentType; use rocket::response::Content; use BASE_URL; -use activity_pub::ap_url; -use activity_pub::webfinger::Webfinger; +use activity_pub::{ap_url, webfinger::Webfinger}; use db_conn::DbConn; -use models::blogs::Blog; -use models::users::User; +use models::{blogs::Blog, users::User}; #[get("/.well-known/host-meta", format = "application/xml")] fn host_meta() -> String {