Reorganize use statements
This commit is contained in:
parent
aa233abb41
commit
b55622f2b1
|
@ -8,15 +8,19 @@ use diesel::PgConnection;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::{broadcast, Id, IntoId};
|
use activity_pub::{
|
||||||
use activity_pub::actor::Actor as APActor;
|
broadcast, Id, IntoId,
|
||||||
use activity_pub::sign::*;
|
actor::Actor as APActor,
|
||||||
use models::blogs::Blog;
|
sign::*
|
||||||
use models::comments::*;
|
};
|
||||||
use models::follows;
|
use models::{
|
||||||
use models::likes;
|
blogs::Blog,
|
||||||
use models::posts::*;
|
comments::*,
|
||||||
use models::users::User;
|
follows,
|
||||||
|
likes,
|
||||||
|
posts::*,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Fail, Debug)]
|
#[derive(Fail, Debug)]
|
||||||
enum InboxError {
|
enum InboxError {
|
||||||
|
|
|
@ -2,9 +2,11 @@ use activitystreams_traits::{Activity, Actor, Object, Link};
|
||||||
use array_tool::vec::Uniq;
|
use array_tool::vec::Uniq;
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use rocket::http::{ContentType, Status};
|
use rocket::{
|
||||||
use rocket::response::{Response, Responder, Content};
|
http::{ContentType, Status},
|
||||||
use rocket::request::Request;
|
response::{Response, Responder, Content},
|
||||||
|
request::Request
|
||||||
|
};
|
||||||
use rocket_contrib::Json;
|
use rocket_contrib::Json;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,3 @@ pub trait Object {
|
||||||
|
|
||||||
fn compute_id(&self, conn: &PgConnection) -> String;
|
fn compute_id(&self, conn: &PgConnection) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,8 @@ pub fn signature<S: Signer>(signer: &S, headers: Headers, conn: &PgConnection) -
|
||||||
let signed_string = headers.iter().map(|h| format!("{}: {}", h.name().to_lowercase(), h.value_string())).collect::<Vec<String>>().join("\n");
|
let signed_string = headers.iter().map(|h| format!("{}: {}", h.name().to_lowercase(), h.value_string())).collect::<Vec<String>>().join("\n");
|
||||||
let signed_headers = headers.iter().map(|h| h.name().to_string()).collect::<Vec<String>>().join(" ").to_lowercase();
|
let signed_headers = headers.iter().map(|h| h.name().to_string()).collect::<Vec<String>>().join(" ").to_lowercase();
|
||||||
|
|
||||||
println!("Signing {}", signed_string);
|
|
||||||
println!("signed header {}", signed_headers);
|
|
||||||
let data = signer.sign(signed_string);
|
let data = signer.sign(signed_string);
|
||||||
let sign = base64::encode(&data[..]);
|
let sign = base64::encode(&data[..]);
|
||||||
println!("sigature {}", sign);
|
|
||||||
|
|
||||||
Signature(format!(
|
Signature(format!(
|
||||||
"keyId=\"{key_id}\",algorithm=\"rsa-sha256\",headers=\"{signed_headers}\",signature=\"{signature}\"",
|
"keyId=\"{key_id}\",algorithm=\"rsa-sha256\",headers=\"{signed_headers}\",signature=\"{signature}\"",
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use base64;
|
use base64;
|
||||||
|
use chrono::Utc;
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use hex;
|
use hex;
|
||||||
use chrono::Utc;
|
use openssl::{
|
||||||
use openssl::pkey::PKey;
|
pkey::PKey,
|
||||||
use openssl::rsa::Rsa;
|
rsa::Rsa,
|
||||||
use openssl::sha::sha256;
|
sha::sha256
|
||||||
|
};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
/// Returns (public key, private key)
|
/// Returns (public key, private key)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use reqwest::header::{Accept, qitem};
|
use reqwest::{
|
||||||
use reqwest::mime::Mime;
|
header::{Accept, qitem},
|
||||||
|
mime::Mime
|
||||||
|
};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::ap_url;
|
use activity_pub::ap_url;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use diesel::pg::PgConnection;
|
use diesel::{
|
||||||
use diesel::r2d2::{ConnectionManager, Pool, PooledConnection};
|
pg::PgConnection,
|
||||||
use rocket::{Request, State, Outcome};
|
r2d2::{ConnectionManager, Pool, PooledConnection}
|
||||||
use rocket::http::Status;
|
};
|
||||||
use rocket::request::{self, FromRequest};
|
use rocket::{Request, State, Outcome, http::Status, request::{self, FromRequest}};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
// From rocket documentation
|
// From rocket documentation
|
||||||
|
|
|
@ -33,8 +33,7 @@ extern crate serde_derive;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
|
|
||||||
use diesel::pg::PgConnection;
|
use diesel::{pg::PgConnection, r2d2::{ConnectionManager, Pool}};
|
||||||
use diesel::r2d2::{ConnectionManager, Pool};
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
|
@ -1,22 +1,28 @@
|
||||||
use activitystreams_traits::{Actor, Object};
|
use activitystreams_traits::{Actor, Object};
|
||||||
use activitystreams_types::collection::OrderedCollection;
|
use activitystreams_types::collection::OrderedCollection;
|
||||||
use reqwest::Client;
|
use reqwest::{
|
||||||
use reqwest::header::{Accept, qitem};
|
Client,
|
||||||
use reqwest::mime::Mime;
|
header::{Accept, qitem},
|
||||||
|
mime::Mime
|
||||||
|
};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
||||||
use openssl::hash::MessageDigest;
|
use openssl::{
|
||||||
use openssl::pkey::{PKey, Private};
|
hash::MessageDigest,
|
||||||
use openssl::rsa::Rsa;
|
pkey::{PKey, Private},
|
||||||
use openssl::sign::Signer;
|
rsa::Rsa,
|
||||||
|
sign::Signer
|
||||||
|
};
|
||||||
|
|
||||||
use activity_pub::{ActivityStream, Id, IntoId};
|
use activity_pub::{
|
||||||
use activity_pub::actor::{Actor as APActor, ActorType};
|
ActivityStream, Id, IntoId,
|
||||||
use activity_pub::inbox::WithInbox;
|
actor::{Actor as APActor, ActorType},
|
||||||
use activity_pub::sign;
|
inbox::WithInbox,
|
||||||
use activity_pub::webfinger::*;
|
sign,
|
||||||
|
webfinger::*
|
||||||
|
};
|
||||||
use models::instance::Instance;
|
use models::instance::Instance;
|
||||||
use schema::blogs;
|
use schema::blogs;
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,15 @@ use chrono;
|
||||||
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::{ap_url, IntoId, PUBLIC_VISIBILTY};
|
use activity_pub::{
|
||||||
use activity_pub::actor::Actor;
|
ap_url, IntoId, PUBLIC_VISIBILTY,
|
||||||
use activity_pub::object::Object;
|
actor::Actor,
|
||||||
use models::posts::Post;
|
object::Object
|
||||||
use models::users::User;
|
};
|
||||||
|
use models::{
|
||||||
|
posts::Post,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
use schema::comments;
|
use schema::comments;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, Serialize, Clone)]
|
#[derive(Queryable, Identifiable, Serialize, Clone)]
|
||||||
|
|
|
@ -3,11 +3,15 @@ use chrono;
|
||||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::IntoId;
|
use activity_pub::{
|
||||||
use activity_pub::actor::Actor;
|
IntoId,
|
||||||
use activity_pub::object::Object;
|
actor::Actor,
|
||||||
use models::posts::Post;
|
object::Object
|
||||||
use models::users::User;
|
};
|
||||||
|
use models::{
|
||||||
|
posts::Post,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
use schema::likes;
|
use schema::likes;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable)]
|
#[derive(Queryable, Identifiable)]
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||||
|
|
||||||
use models::posts::Post;
|
use models::{
|
||||||
use models::users::User;
|
posts::Post,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
use schema::post_authors;
|
use schema::post_authors;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, Associations)]
|
#[derive(Queryable, Identifiable, Associations)]
|
||||||
|
|
|
@ -8,13 +8,17 @@ use diesel::dsl::any;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use BASE_URL;
|
use BASE_URL;
|
||||||
use activity_pub::{PUBLIC_VISIBILTY, ap_url, Id, IntoId};
|
use activity_pub::{
|
||||||
use activity_pub::actor::Actor;
|
PUBLIC_VISIBILTY, ap_url, Id, IntoId,
|
||||||
use activity_pub::object::Object;
|
actor::Actor,
|
||||||
use models::blogs::Blog;
|
object::Object
|
||||||
use models::likes::Like;
|
};
|
||||||
use models::users::User;
|
use models::{
|
||||||
use models::post_authors::PostAuthor;
|
blogs::Blog,
|
||||||
|
likes::Like,
|
||||||
|
post_authors::PostAuthor,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
use schema::posts;
|
use schema::posts;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, Serialize)]
|
#[derive(Queryable, Identifiable, Serialize)]
|
||||||
|
|
|
@ -7,33 +7,42 @@ use activitystreams_types::{
|
||||||
};
|
};
|
||||||
use bcrypt;
|
use bcrypt;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, BelongingToDsl, PgConnection};
|
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, BelongingToDsl, PgConnection, dsl::any};
|
||||||
use diesel::dsl::any;
|
use openssl::{
|
||||||
use openssl::hash::MessageDigest;
|
hash::MessageDigest,
|
||||||
use openssl::pkey::{PKey, Private};
|
pkey::{PKey, Private},
|
||||||
use openssl::rsa::Rsa;
|
rsa::Rsa,
|
||||||
use openssl::sign;
|
sign
|
||||||
use reqwest::Client;
|
};
|
||||||
use reqwest::header::{Accept, qitem};
|
use reqwest::{
|
||||||
use reqwest::mime::Mime;
|
Client,
|
||||||
use rocket::request::{self, FromRequest, Request};
|
header::{Accept, qitem},
|
||||||
use rocket::outcome::IntoOutcome;
|
mime::Mime
|
||||||
|
};
|
||||||
|
use rocket::{
|
||||||
|
request::{self, FromRequest, Request},
|
||||||
|
outcome::IntoOutcome
|
||||||
|
};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use BASE_URL;
|
use BASE_URL;
|
||||||
use activity_pub::{ap_url, ActivityStream, Id, IntoId};
|
use activity_pub::{
|
||||||
use activity_pub::actor::{ActorType, Actor as APActor};
|
ap_url, ActivityStream, Id, IntoId,
|
||||||
use activity_pub::inbox::{Inbox, WithInbox};
|
actor::{ActorType, Actor as APActor},
|
||||||
use activity_pub::sign::{Signer, gen_keypair};
|
inbox::{Inbox, WithInbox},
|
||||||
use activity_pub::webfinger::{Webfinger, resolve};
|
sign::{Signer, gen_keypair},
|
||||||
|
webfinger::{Webfinger, resolve}
|
||||||
|
};
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::comments::Comment;
|
use models::{
|
||||||
use models::follows::Follow;
|
comments::Comment,
|
||||||
use models::instance::Instance;
|
follows::Follow,
|
||||||
use models::notifications::*;
|
instance::Instance,
|
||||||
use models::post_authors::PostAuthor;
|
notifications::*,
|
||||||
use models::posts::Post;
|
post_authors::PostAuthor,
|
||||||
|
posts::Post
|
||||||
|
};
|
||||||
use schema::users;
|
use schema::users;
|
||||||
|
|
||||||
pub const AUTH_COOKIE: &'static str = "user_id";
|
pub const AUTH_COOKIE: &'static str = "user_id";
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
use activitystreams_types::collection::OrderedCollection;
|
use activitystreams_types::collection::OrderedCollection;
|
||||||
use rocket::request::Form;
|
use rocket::{
|
||||||
use rocket::response::Redirect;
|
request::Form,
|
||||||
|
response::Redirect
|
||||||
|
};
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::{ActivityStream, ActivityPub};
|
use activity_pub::{ActivityStream, ActivityPub, actor::Actor};
|
||||||
use activity_pub::actor::Actor;
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blog_authors::*;
|
use models::{
|
||||||
use models::blogs::*;
|
blog_authors::*,
|
||||||
use models::instance::Instance;
|
blogs::*,
|
||||||
use models::posts::Post;
|
instance::Instance,
|
||||||
use models::users::User;
|
posts::Post,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
#[get("/~/<name>", rank = 2)]
|
#[get("/~/<name>", rank = 2)]
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use rocket::request::Form;
|
use rocket::{ request::Form, response::Redirect};
|
||||||
use rocket::response::Redirect;
|
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
|
|
||||||
use activity_pub::broadcast;
|
use activity_pub::broadcast;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::comments::*;
|
use models::{
|
||||||
use models::posts::Post;
|
comments::*,
|
||||||
use models::users::User;
|
posts::Post,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
|
|
||||||
#[get("/~/<_blog>/<slug>/comment")]
|
#[get("/~/<_blog>/<slug>/comment")]
|
||||||
fn new(_blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
fn new(_blog: String, slug: String, user: User, conn: DbConn) -> Template {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
use rocket::request::Form;
|
use rocket::{request::Form, response::Redirect};
|
||||||
use rocket::response::Redirect;
|
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use BASE_URL;
|
use BASE_URL;
|
||||||
use activity_pub::inbox::Inbox;
|
use activity_pub::inbox::Inbox;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::posts::Post;
|
use models::{
|
||||||
use models::users::User;
|
posts::Post,
|
||||||
use models::instance::*;
|
users::User,
|
||||||
|
instance::*
|
||||||
|
};
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index(conn: DbConn, user: Option<User>) -> Template {
|
fn index(conn: DbConn, user: Option<User>) -> Template {
|
||||||
|
|
|
@ -2,9 +2,11 @@ use rocket::response::Redirect;
|
||||||
|
|
||||||
use activity_pub::broadcast;
|
use activity_pub::broadcast;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::likes;
|
use models::{
|
||||||
use models::posts::Post;
|
likes,
|
||||||
use models::users::User;
|
posts::Post,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
|
|
||||||
#[get("/~/<blog>/<slug>/like")]
|
#[get("/~/<blog>/<slug>/like")]
|
||||||
fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::notifications::Notification;
|
use models::{notifications::Notification, users::User};
|
||||||
use models::users::User;
|
|
||||||
|
|
||||||
#[get("/notifications")]
|
#[get("/notifications")]
|
||||||
fn notifications(conn: DbConn, user: User) -> Template {
|
fn notifications(conn: DbConn, user: User) -> Template {
|
||||||
|
|
|
@ -4,14 +4,15 @@ use rocket::response::Redirect;
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::{broadcast, context, activity_pub, ActivityPub};
|
use activity_pub::{broadcast, context, activity_pub, ActivityPub, object::Object};
|
||||||
use activity_pub::object::Object;
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blogs::*;
|
use models::{
|
||||||
use models::comments::Comment;
|
blogs::*,
|
||||||
use models::post_authors::*;
|
comments::Comment,
|
||||||
use models::posts::*;
|
post_authors::*,
|
||||||
use models::users::User;
|
posts::*,
|
||||||
|
users::User
|
||||||
|
};
|
||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
#[get("/~/<blog>/<slug>", rank = 4)]
|
#[get("/~/<blog>/<slug>", rank = 4)]
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use rocket::http::{Cookie, Cookies};
|
use rocket::{
|
||||||
use rocket::response::Redirect;
|
http::{Cookie, Cookies},
|
||||||
use rocket::response::status::NotFound;
|
response::{Redirect, status::NotFound},
|
||||||
use rocket::request::Form;
|
request::Form
|
||||||
|
};
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
|
|
|
@ -2,19 +2,22 @@ use activitystreams_types::{
|
||||||
activity::Follow,
|
activity::Follow,
|
||||||
collection::OrderedCollection
|
collection::OrderedCollection
|
||||||
};
|
};
|
||||||
use rocket::request::Form;
|
use rocket::{request::Form, response::Redirect};
|
||||||
use rocket::response::Redirect;
|
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::{activity_pub, ActivityPub, ActivityStream, context, broadcast, Id, IntoId};
|
use activity_pub::{
|
||||||
use activity_pub::actor::Actor;
|
activity_pub, ActivityPub, ActivityStream, context, broadcast, Id, IntoId,
|
||||||
use activity_pub::inbox::Inbox;
|
actor::Actor,
|
||||||
|
object::Object
|
||||||
|
};
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::follows;
|
use models::{
|
||||||
use models::instance::Instance;
|
follows,
|
||||||
use models::posts::Post;
|
instance::Instance,
|
||||||
use models::users::*;
|
posts::Post,
|
||||||
|
users::*
|
||||||
|
};
|
||||||
|
|
||||||
#[get("/me")]
|
#[get("/me")]
|
||||||
fn me(user: User) -> Redirect {
|
fn me(user: User) -> Redirect {
|
||||||
|
|
|
@ -2,11 +2,9 @@ use rocket::http::ContentType;
|
||||||
use rocket::response::Content;
|
use rocket::response::Content;
|
||||||
|
|
||||||
use BASE_URL;
|
use BASE_URL;
|
||||||
use activity_pub::ap_url;
|
use activity_pub::{ap_url, webfinger::Webfinger};
|
||||||
use activity_pub::webfinger::Webfinger;
|
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blogs::Blog;
|
use models::{blogs::Blog, users::User};
|
||||||
use models::users::User;
|
|
||||||
|
|
||||||
#[get("/.well-known/host-meta", format = "application/xml")]
|
#[get("/.well-known/host-meta", format = "application/xml")]
|
||||||
fn host_meta() -> String {
|
fn host_meta() -> String {
|
||||||
|
|
Loading…
Reference in New Issue