From 1751337d824ca68a10b63a421cdb47e201081eef Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 10 Jun 2020 16:18:47 +0200 Subject: [PATCH] wip: try workbench --- server/Cargo.lock | 46 +++++++- server/Cargo.toml | 48 ++------ server/db/Cargo.toml | 20 ++++ server/{src/db => db/src}/category.rs | 4 +- server/{src/db => db/src}/comment.rs | 22 ++-- server/{src/db => db/src}/comment_view.rs | 0 server/{src/db => db/src}/community.rs | 27 ++--- server/{src/db => db/src}/community_view.rs | 0 server/{src/db/mod.rs => db/src/lib.rs} | 13 ++- server/{src/db => db/src}/moderator.rs | 74 ++++++------ server/{src/db => db/src}/moderator_views.rs | 0 .../db => db/src}/password_reset_request.rs | 6 +- server/{src/db => db/src}/post.rs | 24 ++-- server/{src/db => db/src}/post_view.rs | 0 server/{src/db => db/src}/private_message.rs | 10 +- .../db => db/src}/private_message_view.rs | 0 server/{src/db => db/src}/site.rs | 10 +- server/{src/db => db/src}/site_view.rs | 0 server/{src/db => db/src}/user.rs | 6 +- server/{src/db => db/src}/user_mention.rs | 10 +- .../{src/db => db/src}/user_mention_view.rs | 0 server/{src/db => db/src}/user_view.rs | 0 server/lemmy_server/Cargo.toml | 38 ++++++ server/{ => lemmy_server}/src/api/comment.rs | 0 .../{ => lemmy_server}/src/api/community.rs | 0 server/{ => lemmy_server}/src/api/mod.rs | 40 +++---- server/{ => lemmy_server}/src/api/post.rs | 0 server/{ => lemmy_server}/src/api/site.rs | 0 server/{ => lemmy_server}/src/api/user.rs | 0 server/{ => lemmy_server}/src/lib.rs | 109 ++++++++---------- server/{ => lemmy_server}/src/main.rs | 19 +-- .../{ => lemmy_server}/src/rate_limit/mod.rs | 5 +- .../src/rate_limit/rate_limiter.rs | 0 server/{ => lemmy_server}/src/routes/api.rs | 0 server/{ => lemmy_server}/src/routes/feeds.rs | 14 +-- server/{ => lemmy_server}/src/routes/index.rs | 0 server/{ => lemmy_server}/src/routes/mod.rs | 10 +- .../{ => lemmy_server}/src/routes/nodeinfo.rs | 0 .../src/routes/webfinger.rs | 3 +- .../src/routes/websocket.rs | 0 server/{ => lemmy_server}/src/version.rs | 0 .../{ => lemmy_server}/src/websocket/mod.rs | 2 - .../src/websocket/server.rs | 3 + server/schema/Cargo.toml | 10 ++ server/schema/src/lib.rs | 4 + server/{ => schema}/src/schema.rs | 0 server/src/apub/community.rs | 109 ------------------ server/src/apub/mod.rs | 107 ----------------- server/src/apub/post.rs | 38 ------ server/src/apub/user.rs | 74 ------------ server/src/routes/federation.rs | 18 --- server/utils/Cargo.toml | 16 +++ server/utils/src/lib.rs | 14 +++ server/{ => utils}/src/settings.rs | 0 54 files changed, 351 insertions(+), 602 deletions(-) create mode 100644 server/db/Cargo.toml rename server/{src/db => db/src}/category.rs (95%) rename server/{src/db => db/src}/comment.rs (94%) rename server/{src/db => db/src}/comment_view.rs (100%) rename server/{src/db => db/src}/community.rs (92%) rename server/{src/db => db/src}/community_view.rs (100%) rename server/{src/db/mod.rs => db/src/lib.rs} (93%) rename server/{src/db => db/src}/moderator.rs (92%) rename server/{src/db => db/src}/moderator_views.rs (100%) rename server/{src/db => db/src}/password_reset_request.rs (96%) rename server/{src/db => db/src}/post.rs (94%) rename server/{src/db => db/src}/post_view.rs (100%) rename server/{src/db => db/src}/private_message.rs (94%) rename server/{src/db => db/src}/private_message_view.rs (100%) rename server/{src/db => db/src}/site.rs (88%) rename server/{src/db => db/src}/site_view.rs (100%) rename server/{src/db => db/src}/user.rs (98%) rename server/{src/db => db/src}/user_mention.rs (96%) rename server/{src/db => db/src}/user_mention_view.rs (100%) rename server/{src/db => db/src}/user_view.rs (100%) create mode 100644 server/lemmy_server/Cargo.toml rename server/{ => lemmy_server}/src/api/comment.rs (100%) rename server/{ => lemmy_server}/src/api/community.rs (100%) rename server/{ => lemmy_server}/src/api/mod.rs (67%) rename server/{ => lemmy_server}/src/api/post.rs (100%) rename server/{ => lemmy_server}/src/api/site.rs (100%) rename server/{ => lemmy_server}/src/api/user.rs (100%) rename server/{ => lemmy_server}/src/lib.rs (93%) rename server/{ => lemmy_server}/src/main.rs (89%) rename server/{ => lemmy_server}/src/rate_limit/mod.rs (98%) rename server/{ => lemmy_server}/src/rate_limit/rate_limiter.rs (100%) rename server/{ => lemmy_server}/src/routes/api.rs (100%) rename server/{ => lemmy_server}/src/routes/feeds.rs (96%) rename server/{ => lemmy_server}/src/routes/index.rs (100%) rename server/{ => lemmy_server}/src/routes/mod.rs (88%) rename server/{ => lemmy_server}/src/routes/nodeinfo.rs (100%) rename server/{ => lemmy_server}/src/routes/webfinger.rs (97%) rename server/{ => lemmy_server}/src/routes/websocket.rs (100%) rename server/{ => lemmy_server}/src/version.rs (100%) rename server/{ => lemmy_server}/src/websocket/mod.rs (94%) rename server/{ => lemmy_server}/src/websocket/server.rs (99%) create mode 100644 server/schema/Cargo.toml create mode 100644 server/schema/src/lib.rs rename server/{ => schema}/src/schema.rs (100%) delete mode 100644 server/src/apub/community.rs delete mode 100644 server/src/apub/mod.rs delete mode 100644 server/src/apub/post.rs delete mode 100644 server/src/apub/user.rs delete mode 100644 server/src/routes/federation.rs create mode 100644 server/utils/Cargo.toml create mode 100644 server/utils/src/lib.rs rename server/{ => utils}/src/settings.rs (100%) diff --git a/server/Cargo.lock b/server/Cargo.lock index b4c995265..f82624a89 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -791,6 +791,23 @@ dependencies = [ "syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "db" +version = "0.1.0" +dependencies = [ + "bcrypt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonwebtoken 7.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "schema 0.1.0", + "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "strum 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", + "strum_macros 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", + "utils 0.1.0", +] + [[package]] name = "derive_builder" version = "0.9.0" @@ -1415,31 +1432,28 @@ dependencies = [ "bcrypt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "comrak 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "config 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "db 0.1.0", "dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "isahc 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonwebtoken 7.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lettre 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "lettre_email 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "rss 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "strum 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "strum_macros 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "utils 0.1.0", ] [[package]] @@ -2243,6 +2257,13 @@ dependencies = [ "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "schema" +version = "0.1.0" +dependencies = [ + "diesel 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -2784,6 +2805,19 @@ name = "utf8-ranges" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "utils" +version = "0.1.0" +dependencies = [ + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "config 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "uuid" version = "0.7.4" diff --git a/server/Cargo.toml b/server/Cargo.toml index e658f03ad..c4c40609e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,41 +1,7 @@ -[package] -name = "lemmy_server" -version = "0.0.1" -authors = ["Dessalines "] -edition = "2018" - -[dependencies] -diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2", "64-column-tables"] } -diesel_migrations = "1.4.0" -dotenv = "0.15.0" -bcrypt = "0.7.0" -activitypub = "0.2.0" -chrono = { version = "0.4.7", features = ["serde"] } -failure = "0.1.8" -serde_json = { version = "1.0.52", features = ["preserve_order"]} -serde = { version = "1.0.105", features = ["derive"] } -actix = "0.9.0" -actix-web = "2.0.0" -actix-files = "0.2.1" -actix-web-actors = "2.0.0" -actix-rt = "1.1.1" -log = "0.4.0" -env_logger = "0.7.1" -rand = "0.7.3" -strum = "0.18.0" -strum_macros = "0.18.0" -jsonwebtoken = "7.0.1" -regex = "1.3.5" -lazy_static = "1.3.0" -lettre = "0.9.3" -lettre_email = "0.9.4" -sha2 = "0.8.1" -rss = "1.9.0" -htmlescape = "0.3.1" -config = "0.10.1" -hjson = "0.8.2" -percent-encoding = "2.1.0" -isahc = "0.9" -comrak = "0.7" -tokio = "0.2.20" -futures = "0.3.4" +[workspace] +members = [ + "lemmy_server", + "db", + "schema", + "utils", +] diff --git a/server/db/Cargo.toml b/server/db/Cargo.toml new file mode 100644 index 000000000..7a2d2962b --- /dev/null +++ b/server/db/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "db" +version = "0.1.0" +authors = ["Felix Ableitner "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +utils = { path = "../utils" } +schema = { path = "../schema" } +diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2", "64-column-tables"] } +diesel_migrations = "1.4.0" +chrono = { version = "0.4.7", features = ["serde"] } +serde = { version = "1.0.105", features = ["derive"] } +strum = "0.18.0" +strum_macros = "0.18.0" +sha2 = "0.8.1" +bcrypt = "0.7.0" +jsonwebtoken = "7.0.1" \ No newline at end of file diff --git a/server/src/db/category.rs b/server/db/src/category.rs similarity index 95% rename from server/src/db/category.rs rename to server/db/src/category.rs index 408c8231b..76c0da9d6 100644 --- a/server/src/db/category.rs +++ b/server/db/src/category.rs @@ -1,6 +1,6 @@ use super::*; -use crate::schema::category; -use crate::schema::category::dsl::*; +use schema::schema::category; +use schema::schema::category::dsl::*; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "category"] diff --git a/server/src/db/comment.rs b/server/db/src/comment.rs similarity index 94% rename from server/src/db/comment.rs rename to server/db/src/comment.rs index c9bfbac6c..31d5fc861 100644 --- a/server/src/db/comment.rs +++ b/server/db/src/comment.rs @@ -1,6 +1,6 @@ use super::post::Post; use super::*; -use crate::schema::{comment, comment_like, comment_saved}; +use schema::schema::{comment, comment_like, comment_saved}; // WITH RECURSIVE MyTree AS ( // SELECT * FROM comment WHERE parent_id IS NULL @@ -40,17 +40,17 @@ pub struct CommentForm { impl Crud for Comment { fn read(conn: &PgConnection, comment_id: i32) -> Result { - use crate::schema::comment::dsl::*; + use schema::schema::comment::dsl::*; comment.find(comment_id).first::(conn) } fn delete(conn: &PgConnection, comment_id: i32) -> Result { - use crate::schema::comment::dsl::*; + use schema::schema::comment::dsl::*; diesel::delete(comment.find(comment_id)).execute(conn) } fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result { - use crate::schema::comment::dsl::*; + use schema::schema::comment::dsl::*; insert_into(comment) .values(comment_form) .get_result::(conn) @@ -61,7 +61,7 @@ impl Crud for Comment { comment_id: i32, comment_form: &CommentForm, ) -> Result { - use crate::schema::comment::dsl::*; + use schema::schema::comment::dsl::*; diesel::update(comment.find(comment_id)) .set(comment_form) .get_result::(conn) @@ -91,20 +91,20 @@ pub struct CommentLikeForm { impl Likeable for CommentLike { fn read(conn: &PgConnection, comment_id_from: i32) -> Result, Error> { - use crate::schema::comment_like::dsl::*; + use schema::schema::comment_like::dsl::*; comment_like .filter(comment_id.eq(comment_id_from)) .load::(conn) } fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result { - use crate::schema::comment_like::dsl::*; + use schema::schema::comment_like::dsl::*; insert_into(comment_like) .values(comment_like_form) .get_result::(conn) } fn remove(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result { - use crate::schema::comment_like::dsl::*; + use schema::schema::comment_like::dsl::*; diesel::delete( comment_like .filter(comment_id.eq(comment_like_form.comment_id)) @@ -116,7 +116,7 @@ impl Likeable for CommentLike { impl CommentLike { pub fn from_post(conn: &PgConnection, post_id_from: i32) -> Result, Error> { - use crate::schema::comment_like::dsl::*; + use schema::schema::comment_like::dsl::*; comment_like .filter(post_id.eq(post_id_from)) .load::(conn) @@ -142,13 +142,13 @@ pub struct CommentSavedForm { impl Saveable for CommentSaved { fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result { - use crate::schema::comment_saved::dsl::*; + use schema::schema::comment_saved::dsl::*; insert_into(comment_saved) .values(comment_saved_form) .get_result::(conn) } fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result { - use crate::schema::comment_saved::dsl::*; + use schema::schema::comment_saved::dsl::*; diesel::delete( comment_saved .filter(comment_id.eq(comment_saved_form.comment_id)) diff --git a/server/src/db/comment_view.rs b/server/db/src/comment_view.rs similarity index 100% rename from server/src/db/comment_view.rs rename to server/db/src/comment_view.rs diff --git a/server/src/db/community.rs b/server/db/src/community.rs similarity index 92% rename from server/src/db/community.rs rename to server/db/src/community.rs index 635009635..d5f42f64a 100644 --- a/server/src/db/community.rs +++ b/server/db/src/community.rs @@ -1,5 +1,6 @@ use super::*; -use crate::schema::{community, community_follower, community_moderator, community_user_ban}; +use schema::schema::{community, community_follower, community_moderator, community_user_ban}; +use utils::settings::Settings; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "community"] @@ -33,17 +34,17 @@ pub struct CommunityForm { impl Crud for Community { fn read(conn: &PgConnection, community_id: i32) -> Result { - use crate::schema::community::dsl::*; + use schema::schema::community::dsl::*; community.find(community_id).first::(conn) } fn delete(conn: &PgConnection, community_id: i32) -> Result { - use crate::schema::community::dsl::*; + use schema::schema::community::dsl::*; diesel::delete(community.find(community_id)).execute(conn) } fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result { - use crate::schema::community::dsl::*; + use schema::schema::community::dsl::*; insert_into(community) .values(new_community) .get_result::(conn) @@ -54,7 +55,7 @@ impl Crud for Community { community_id: i32, new_community: &CommunityForm, ) -> Result { - use crate::schema::community::dsl::*; + use schema::schema::community::dsl::*; diesel::update(community.find(community_id)) .set(new_community) .get_result::(conn) @@ -63,7 +64,7 @@ impl Crud for Community { impl Community { pub fn read_from_name(conn: &PgConnection, community_name: String) -> Result { - use crate::schema::community::dsl::*; + use schema::schema::community::dsl::*; community .filter(name.eq(community_name)) .first::(conn) @@ -96,7 +97,7 @@ impl Joinable for CommunityModerator { conn: &PgConnection, community_user_form: &CommunityModeratorForm, ) -> Result { - use crate::schema::community_moderator::dsl::*; + use schema::schema::community_moderator::dsl::*; insert_into(community_moderator) .values(community_user_form) .get_result::(conn) @@ -106,7 +107,7 @@ impl Joinable for CommunityModerator { conn: &PgConnection, community_user_form: &CommunityModeratorForm, ) -> Result { - use crate::schema::community_moderator::dsl::*; + use schema::schema::community_moderator::dsl::*; diesel::delete( community_moderator .filter(community_id.eq(community_user_form.community_id)) @@ -118,7 +119,7 @@ impl Joinable for CommunityModerator { impl CommunityModerator { pub fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result { - use crate::schema::community_moderator::dsl::*; + use schema::schema::community_moderator::dsl::*; diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn) } } @@ -145,7 +146,7 @@ impl Bannable for CommunityUserBan { conn: &PgConnection, community_user_ban_form: &CommunityUserBanForm, ) -> Result { - use crate::schema::community_user_ban::dsl::*; + use schema::schema::community_user_ban::dsl::*; insert_into(community_user_ban) .values(community_user_ban_form) .get_result::(conn) @@ -155,7 +156,7 @@ impl Bannable for CommunityUserBan { conn: &PgConnection, community_user_ban_form: &CommunityUserBanForm, ) -> Result { - use crate::schema::community_user_ban::dsl::*; + use schema::schema::community_user_ban::dsl::*; diesel::delete( community_user_ban .filter(community_id.eq(community_user_ban_form.community_id)) @@ -187,7 +188,7 @@ impl Followable for CommunityFollower { conn: &PgConnection, community_follower_form: &CommunityFollowerForm, ) -> Result { - use crate::schema::community_follower::dsl::*; + use schema::schema::community_follower::dsl::*; insert_into(community_follower) .values(community_follower_form) .get_result::(conn) @@ -196,7 +197,7 @@ impl Followable for CommunityFollower { conn: &PgConnection, community_follower_form: &CommunityFollowerForm, ) -> Result { - use crate::schema::community_follower::dsl::*; + use schema::schema::community_follower::dsl::*; diesel::delete( community_follower .filter(community_id.eq(&community_follower_form.community_id)) diff --git a/server/src/db/community_view.rs b/server/db/src/community_view.rs similarity index 100% rename from server/src/db/community_view.rs rename to server/db/src/community_view.rs diff --git a/server/src/db/mod.rs b/server/db/src/lib.rs similarity index 93% rename from server/src/db/mod.rs rename to server/db/src/lib.rs index e0d358ffe..0115e8146 100644 --- a/server/src/db/mod.rs +++ b/server/db/src/lib.rs @@ -1,4 +1,11 @@ -use crate::settings::Settings; +#[macro_use] +pub extern crate diesel; +#[macro_use] +pub extern crate strum_macros; +#[macro_use] +extern crate diesel_migrations; + +use utils::settings::Settings; use diesel::dsl::*; use diesel::result::Error; use diesel::*; @@ -23,6 +30,10 @@ pub mod user_mention; pub mod user_mention_view; pub mod user_view; +// TODO: need to execute this +embed_migrations!(); +//embedded_migrations::run(&conn).unwrap(); + pub trait Crud { fn create(conn: &PgConnection, form: &T) -> Result where diff --git a/server/src/db/moderator.rs b/server/db/src/moderator.rs similarity index 92% rename from server/src/db/moderator.rs rename to server/db/src/moderator.rs index a8c3df4f1..20e1dc524 100644 --- a/server/src/db/moderator.rs +++ b/server/db/src/moderator.rs @@ -1,5 +1,5 @@ use super::*; -use crate::schema::{ +use schema::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, }; @@ -26,24 +26,24 @@ pub struct ModRemovePostForm { impl Crud for ModRemovePost { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_remove_post::dsl::*; + use schema::schema::mod_remove_post::dsl::*; mod_remove_post.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_remove_post::dsl::*; + use schema::schema::mod_remove_post::dsl::*; diesel::delete(mod_remove_post.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result { - use crate::schema::mod_remove_post::dsl::*; + use schema::schema::mod_remove_post::dsl::*; insert_into(mod_remove_post) .values(form) .get_result::(conn) } fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result { - use crate::schema::mod_remove_post::dsl::*; + use schema::schema::mod_remove_post::dsl::*; diesel::update(mod_remove_post.find(from_id)) .set(form) .get_result::(conn) @@ -70,24 +70,24 @@ pub struct ModLockPostForm { impl Crud for ModLockPost { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_lock_post::dsl::*; + use schema::schema::mod_lock_post::dsl::*; mod_lock_post.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_lock_post::dsl::*; + use schema::schema::mod_lock_post::dsl::*; diesel::delete(mod_lock_post.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result { - use crate::schema::mod_lock_post::dsl::*; + use schema::schema::mod_lock_post::dsl::*; insert_into(mod_lock_post) .values(form) .get_result::(conn) } fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result { - use crate::schema::mod_lock_post::dsl::*; + use schema::schema::mod_lock_post::dsl::*; diesel::update(mod_lock_post.find(from_id)) .set(form) .get_result::(conn) @@ -114,24 +114,24 @@ pub struct ModStickyPostForm { impl Crud for ModStickyPost { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_sticky_post::dsl::*; + use schema::schema::mod_sticky_post::dsl::*; mod_sticky_post.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_sticky_post::dsl::*; + use schema::schema::mod_sticky_post::dsl::*; diesel::delete(mod_sticky_post.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result { - use crate::schema::mod_sticky_post::dsl::*; + use schema::schema::mod_sticky_post::dsl::*; insert_into(mod_sticky_post) .values(form) .get_result::(conn) } fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result { - use crate::schema::mod_sticky_post::dsl::*; + use schema::schema::mod_sticky_post::dsl::*; diesel::update(mod_sticky_post.find(from_id)) .set(form) .get_result::(conn) @@ -160,24 +160,24 @@ pub struct ModRemoveCommentForm { impl Crud for ModRemoveComment { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_remove_comment::dsl::*; + use schema::schema::mod_remove_comment::dsl::*; mod_remove_comment.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_remove_comment::dsl::*; + use schema::schema::mod_remove_comment::dsl::*; diesel::delete(mod_remove_comment.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result { - use crate::schema::mod_remove_comment::dsl::*; + use schema::schema::mod_remove_comment::dsl::*; insert_into(mod_remove_comment) .values(form) .get_result::(conn) } fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result { - use crate::schema::mod_remove_comment::dsl::*; + use schema::schema::mod_remove_comment::dsl::*; diesel::update(mod_remove_comment.find(from_id)) .set(form) .get_result::(conn) @@ -208,17 +208,17 @@ pub struct ModRemoveCommunityForm { impl Crud for ModRemoveCommunity { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_remove_community::dsl::*; + use schema::schema::mod_remove_community::dsl::*; mod_remove_community.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_remove_community::dsl::*; + use schema::schema::mod_remove_community::dsl::*; diesel::delete(mod_remove_community.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result { - use crate::schema::mod_remove_community::dsl::*; + use schema::schema::mod_remove_community::dsl::*; insert_into(mod_remove_community) .values(form) .get_result::(conn) @@ -229,7 +229,7 @@ impl Crud for ModRemoveCommunity { from_id: i32, form: &ModRemoveCommunityForm, ) -> Result { - use crate::schema::mod_remove_community::dsl::*; + use schema::schema::mod_remove_community::dsl::*; diesel::update(mod_remove_community.find(from_id)) .set(form) .get_result::(conn) @@ -262,17 +262,17 @@ pub struct ModBanFromCommunityForm { impl Crud for ModBanFromCommunity { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_ban_from_community::dsl::*; + use schema::schema::mod_ban_from_community::dsl::*; mod_ban_from_community.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_ban_from_community::dsl::*; + use schema::schema::mod_ban_from_community::dsl::*; diesel::delete(mod_ban_from_community.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result { - use crate::schema::mod_ban_from_community::dsl::*; + use schema::schema::mod_ban_from_community::dsl::*; insert_into(mod_ban_from_community) .values(form) .get_result::(conn) @@ -283,7 +283,7 @@ impl Crud for ModBanFromCommunity { from_id: i32, form: &ModBanFromCommunityForm, ) -> Result { - use crate::schema::mod_ban_from_community::dsl::*; + use schema::schema::mod_ban_from_community::dsl::*; diesel::update(mod_ban_from_community.find(from_id)) .set(form) .get_result::(conn) @@ -314,22 +314,22 @@ pub struct ModBanForm { impl Crud for ModBan { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_ban::dsl::*; + use schema::schema::mod_ban::dsl::*; mod_ban.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_ban::dsl::*; + use schema::schema::mod_ban::dsl::*; diesel::delete(mod_ban.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModBanForm) -> Result { - use crate::schema::mod_ban::dsl::*; + use schema::schema::mod_ban::dsl::*; insert_into(mod_ban).values(form).get_result::(conn) } fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result { - use crate::schema::mod_ban::dsl::*; + use schema::schema::mod_ban::dsl::*; diesel::update(mod_ban.find(from_id)) .set(form) .get_result::(conn) @@ -358,24 +358,24 @@ pub struct ModAddCommunityForm { impl Crud for ModAddCommunity { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_add_community::dsl::*; + use schema::schema::mod_add_community::dsl::*; mod_add_community.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_add_community::dsl::*; + use schema::schema::mod_add_community::dsl::*; diesel::delete(mod_add_community.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result { - use crate::schema::mod_add_community::dsl::*; + use schema::schema::mod_add_community::dsl::*; insert_into(mod_add_community) .values(form) .get_result::(conn) } fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result { - use crate::schema::mod_add_community::dsl::*; + use schema::schema::mod_add_community::dsl::*; diesel::update(mod_add_community.find(from_id)) .set(form) .get_result::(conn) @@ -402,22 +402,22 @@ pub struct ModAddForm { impl Crud for ModAdd { fn read(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_add::dsl::*; + use schema::schema::mod_add::dsl::*; mod_add.find(from_id).first::(conn) } fn delete(conn: &PgConnection, from_id: i32) -> Result { - use crate::schema::mod_add::dsl::*; + use schema::schema::mod_add::dsl::*; diesel::delete(mod_add.find(from_id)).execute(conn) } fn create(conn: &PgConnection, form: &ModAddForm) -> Result { - use crate::schema::mod_add::dsl::*; + use schema::schema::mod_add::dsl::*; insert_into(mod_add).values(form).get_result::(conn) } fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result { - use crate::schema::mod_add::dsl::*; + use schema::schema::mod_add::dsl::*; diesel::update(mod_add.find(from_id)) .set(form) .get_result::(conn) diff --git a/server/src/db/moderator_views.rs b/server/db/src/moderator_views.rs similarity index 100% rename from server/src/db/moderator_views.rs rename to server/db/src/moderator_views.rs diff --git a/server/src/db/password_reset_request.rs b/server/db/src/password_reset_request.rs similarity index 96% rename from server/src/db/password_reset_request.rs rename to server/db/src/password_reset_request.rs index 6951fd399..766733685 100644 --- a/server/src/db/password_reset_request.rs +++ b/server/db/src/password_reset_request.rs @@ -1,6 +1,6 @@ use super::*; -use crate::schema::password_reset_request; -use crate::schema::password_reset_request::dsl::*; +use schema::schema::password_reset_request; +use schema::schema::password_reset_request::dsl::*; use sha2::{Digest, Sha256}; #[derive(Queryable, Identifiable, PartialEq, Debug)] @@ -21,7 +21,7 @@ pub struct PasswordResetRequestForm { impl Crud for PasswordResetRequest { fn read(conn: &PgConnection, password_reset_request_id: i32) -> Result { - use crate::schema::password_reset_request::dsl::*; + use schema::schema::password_reset_request::dsl::*; password_reset_request .find(password_reset_request_id) .first::(conn) diff --git a/server/src/db/post.rs b/server/db/src/post.rs similarity index 94% rename from server/src/db/post.rs rename to server/db/src/post.rs index ffde14d3d..c0e1dc863 100644 --- a/server/src/db/post.rs +++ b/server/db/src/post.rs @@ -1,5 +1,5 @@ use super::*; -use crate::schema::{post, post_like, post_read, post_saved}; +use schema::schema::{post, post_like, post_read, post_saved}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "post"] @@ -45,22 +45,22 @@ pub struct PostForm { impl Crud for Post { fn read(conn: &PgConnection, post_id: i32) -> Result { - use crate::schema::post::dsl::*; + use schema::schema::post::dsl::*; post.find(post_id).first::(conn) } fn delete(conn: &PgConnection, post_id: i32) -> Result { - use crate::schema::post::dsl::*; + use schema::schema::post::dsl::*; diesel::delete(post.find(post_id)).execute(conn) } fn create(conn: &PgConnection, new_post: &PostForm) -> Result { - use crate::schema::post::dsl::*; + use schema::schema::post::dsl::*; insert_into(post).values(new_post).get_result::(conn) } fn update(conn: &PgConnection, post_id: i32, new_post: &PostForm) -> Result { - use crate::schema::post::dsl::*; + use schema::schema::post::dsl::*; diesel::update(post.find(post_id)) .set(new_post) .get_result::(conn) @@ -88,19 +88,19 @@ pub struct PostLikeForm { impl Likeable for PostLike { fn read(conn: &PgConnection, post_id_from: i32) -> Result, Error> { - use crate::schema::post_like::dsl::*; + use schema::schema::post_like::dsl::*; post_like .filter(post_id.eq(post_id_from)) .load::(conn) } fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result { - use crate::schema::post_like::dsl::*; + use schema::schema::post_like::dsl::*; insert_into(post_like) .values(post_like_form) .get_result::(conn) } fn remove(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result { - use crate::schema::post_like::dsl::*; + use schema::schema::post_like::dsl::*; diesel::delete( post_like .filter(post_id.eq(post_like_form.post_id)) @@ -129,13 +129,13 @@ pub struct PostSavedForm { impl Saveable for PostSaved { fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result { - use crate::schema::post_saved::dsl::*; + use schema::schema::post_saved::dsl::*; insert_into(post_saved) .values(post_saved_form) .get_result::(conn) } fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result { - use crate::schema::post_saved::dsl::*; + use schema::schema::post_saved::dsl::*; diesel::delete( post_saved .filter(post_id.eq(post_saved_form.post_id)) @@ -164,13 +164,13 @@ pub struct PostReadForm { impl Readable for PostRead { fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result { - use crate::schema::post_read::dsl::*; + use schema::schema::post_read::dsl::*; insert_into(post_read) .values(post_read_form) .get_result::(conn) } fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result { - use crate::schema::post_read::dsl::*; + use schema::schema::post_read::dsl::*; diesel::delete( post_read .filter(post_id.eq(post_read_form.post_id)) diff --git a/server/src/db/post_view.rs b/server/db/src/post_view.rs similarity index 100% rename from server/src/db/post_view.rs rename to server/db/src/post_view.rs diff --git a/server/src/db/private_message.rs b/server/db/src/private_message.rs similarity index 94% rename from server/src/db/private_message.rs rename to server/db/src/private_message.rs index cc073b594..49a480ce1 100644 --- a/server/src/db/private_message.rs +++ b/server/db/src/private_message.rs @@ -1,5 +1,5 @@ use super::*; -use crate::schema::private_message; +use schema::schema::private_message; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "private_message"] @@ -27,17 +27,17 @@ pub struct PrivateMessageForm { impl Crud for PrivateMessage { fn read(conn: &PgConnection, private_message_id: i32) -> Result { - use crate::schema::private_message::dsl::*; + use schema::schema::private_message::dsl::*; private_message.find(private_message_id).first::(conn) } fn delete(conn: &PgConnection, private_message_id: i32) -> Result { - use crate::schema::private_message::dsl::*; + use schema::schema::private_message::dsl::*; diesel::delete(private_message.find(private_message_id)).execute(conn) } fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result { - use crate::schema::private_message::dsl::*; + use schema::schema::private_message::dsl::*; insert_into(private_message) .values(private_message_form) .get_result::(conn) @@ -48,7 +48,7 @@ impl Crud for PrivateMessage { private_message_id: i32, private_message_form: &PrivateMessageForm, ) -> Result { - use crate::schema::private_message::dsl::*; + use schema::schema::private_message::dsl::*; diesel::update(private_message.find(private_message_id)) .set(private_message_form) .get_result::(conn) diff --git a/server/src/db/private_message_view.rs b/server/db/src/private_message_view.rs similarity index 100% rename from server/src/db/private_message_view.rs rename to server/db/src/private_message_view.rs diff --git a/server/src/db/site.rs b/server/db/src/site.rs similarity index 88% rename from server/src/db/site.rs rename to server/db/src/site.rs index 3b8366d81..a589a05b4 100644 --- a/server/src/db/site.rs +++ b/server/db/src/site.rs @@ -1,5 +1,5 @@ use super::*; -use crate::schema::site; +use schema::schema::site; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "site"] @@ -29,22 +29,22 @@ pub struct SiteForm { impl Crud for Site { fn read(conn: &PgConnection, _site_id: i32) -> Result { - use crate::schema::site::dsl::*; + use schema::schema::site::dsl::*; site.first::(conn) } fn delete(conn: &PgConnection, site_id: i32) -> Result { - use crate::schema::site::dsl::*; + use schema::schema::site::dsl::*; diesel::delete(site.find(site_id)).execute(conn) } fn create(conn: &PgConnection, new_site: &SiteForm) -> Result { - use crate::schema::site::dsl::*; + use schema::schema::site::dsl::*; insert_into(site).values(new_site).get_result::(conn) } fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result { - use crate::schema::site::dsl::*; + use schema::schema::site::dsl::*; diesel::update(site.find(site_id)) .set(new_site) .get_result::(conn) diff --git a/server/src/db/site_view.rs b/server/db/src/site_view.rs similarity index 100% rename from server/src/db/site_view.rs rename to server/db/src/site_view.rs diff --git a/server/src/db/user.rs b/server/db/src/user.rs similarity index 98% rename from server/src/db/user.rs rename to server/db/src/user.rs index e7c769650..31b38c0d0 100644 --- a/server/src/db/user.rs +++ b/server/db/src/user.rs @@ -1,7 +1,7 @@ use super::*; -use crate::schema::user_; -use crate::schema::user_::dsl::*; -use crate::{is_email_regex, Settings}; +use schema::schema::user_; +use schema::schema::user_::dsl::*; +use utils::{is_email_regex, settings::Settings}; use bcrypt::{hash, DEFAULT_COST}; use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; diff --git a/server/src/db/user_mention.rs b/server/db/src/user_mention.rs similarity index 96% rename from server/src/db/user_mention.rs rename to server/db/src/user_mention.rs index 0cf257955..b59c09fba 100644 --- a/server/src/db/user_mention.rs +++ b/server/db/src/user_mention.rs @@ -1,6 +1,6 @@ use super::comment::Comment; use super::*; -use crate::schema::user_mention; +use schema::schema::user_mention; #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[belongs_to(Comment)] @@ -23,17 +23,17 @@ pub struct UserMentionForm { impl Crud for UserMention { fn read(conn: &PgConnection, user_mention_id: i32) -> Result { - use crate::schema::user_mention::dsl::*; + use schema::schema::user_mention::dsl::*; user_mention.find(user_mention_id).first::(conn) } fn delete(conn: &PgConnection, user_mention_id: i32) -> Result { - use crate::schema::user_mention::dsl::*; + use schema::schema::user_mention::dsl::*; diesel::delete(user_mention.find(user_mention_id)).execute(conn) } fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result { - use crate::schema::user_mention::dsl::*; + use schema::schema::user_mention::dsl::*; insert_into(user_mention) .values(user_mention_form) .get_result::(conn) @@ -44,7 +44,7 @@ impl Crud for UserMention { user_mention_id: i32, user_mention_form: &UserMentionForm, ) -> Result { - use crate::schema::user_mention::dsl::*; + use schema::schema::user_mention::dsl::*; diesel::update(user_mention.find(user_mention_id)) .set(user_mention_form) .get_result::(conn) diff --git a/server/src/db/user_mention_view.rs b/server/db/src/user_mention_view.rs similarity index 100% rename from server/src/db/user_mention_view.rs rename to server/db/src/user_mention_view.rs diff --git a/server/src/db/user_view.rs b/server/db/src/user_view.rs similarity index 100% rename from server/src/db/user_view.rs rename to server/db/src/user_view.rs diff --git a/server/lemmy_server/Cargo.toml b/server/lemmy_server/Cargo.toml new file mode 100644 index 000000000..9c86f6631 --- /dev/null +++ b/server/lemmy_server/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "lemmy_server" +version = "0.0.1" +authors = ["Dessalines "] +edition = "2018" + +[dependencies] +utils = { path = "../utils" } +db = { path = "../db" } +r2d2 = { version = ">= 0.8, < 0.9" } +chrono = { version = "0.4.7", features = ["serde"] } +serde_json = { version = "1.0.52", features = ["preserve_order"]} +serde = { version = "1.0.105", features = ["derive"] } +strum = "0.18.0" +strum_macros = "0.18.0" +dotenv = "0.15.0" +activitypub = "0.2.0" +failure = "0.1.8" +actix = "0.9.0" +actix-web = "2.0.0" +actix-files = "0.2.1" +actix-web-actors = "2.0.0" +actix-rt = "1.1.1" +log = "0.4.0" +env_logger = "0.7.1" +rand = "0.7.3" +regex = "1.3.5" +lazy_static = "1.3.0" +lettre = "0.9.3" +lettre_email = "0.9.4" +rss = "1.9.0" +htmlescape = "0.3.1" +percent-encoding = "2.1.0" +isahc = "0.9" +comrak = "0.7" +tokio = "0.2.20" +futures = "0.3.4" +bcrypt = "0.7.0" diff --git a/server/src/api/comment.rs b/server/lemmy_server/src/api/comment.rs similarity index 100% rename from server/src/api/comment.rs rename to server/lemmy_server/src/api/comment.rs diff --git a/server/src/api/community.rs b/server/lemmy_server/src/api/community.rs similarity index 100% rename from server/src/api/community.rs rename to server/lemmy_server/src/api/community.rs diff --git a/server/src/api/mod.rs b/server/lemmy_server/src/api/mod.rs similarity index 67% rename from server/src/api/mod.rs rename to server/lemmy_server/src/api/mod.rs index 3488a8c42..e05480ccb 100644 --- a/server/src/api/mod.rs +++ b/server/lemmy_server/src/api/mod.rs @@ -1,28 +1,28 @@ -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 db::category::*; +use db::comment::*; +use db::comment_view::*; +use db::community::*; +use db::community_view::*; +use db::moderator::*; +use db::moderator_views::*; +use db::password_reset_request::*; +use db::post::*; +use db::post_view::*; +use db::private_message::*; +use db::private_message_view::*; +use db::site::*; +use db::site_view::*; +use db::user::*; +use db::user_mention::*; +use db::user_mention_view::*; +use db::user_view::*; +use 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::settings::Settings; +use utils::settings::Settings; use crate::websocket::UserOperation; use crate::websocket::{ server::{ diff --git a/server/src/api/post.rs b/server/lemmy_server/src/api/post.rs similarity index 100% rename from server/src/api/post.rs rename to server/lemmy_server/src/api/post.rs diff --git a/server/src/api/site.rs b/server/lemmy_server/src/api/site.rs similarity index 100% rename from server/src/api/site.rs rename to server/lemmy_server/src/api/site.rs diff --git a/server/src/api/user.rs b/server/lemmy_server/src/api/user.rs similarity index 100% rename from server/src/api/user.rs rename to server/lemmy_server/src/api/user.rs diff --git a/server/src/lib.rs b/server/lemmy_server/src/lib.rs similarity index 93% rename from server/src/lib.rs rename to server/lemmy_server/src/lib.rs index ca4bedea7..3e4ea0dc6 100644 --- a/server/src/lib.rs +++ b/server/lemmy_server/src/lib.rs @@ -5,15 +5,13 @@ pub extern crate strum_macros; pub extern crate lazy_static; #[macro_use] pub extern crate failure; -#[macro_use] -pub extern crate diesel; pub extern crate actix; pub extern crate actix_web; -pub extern crate bcrypt; +//pub extern crate bcrypt; pub extern crate chrono; pub extern crate comrak; pub extern crate dotenv; -pub extern crate jsonwebtoken; +//pub extern crate jsonwebtoken; pub extern crate lettre; pub extern crate lettre_email; pub extern crate rand; @@ -21,16 +19,10 @@ pub extern crate regex; pub extern crate rss; pub extern crate serde; pub extern crate serde_json; -pub extern crate sha2; -pub extern crate strum; pub mod api; -pub mod apub; -pub mod db; pub mod rate_limit; pub mod routes; -pub mod schema; -pub mod settings; pub mod version; pub mod websocket; @@ -49,7 +41,7 @@ use rand::{thread_rng, Rng}; use regex::{Regex, RegexBuilder}; use serde::Deserialize; -use crate::settings::Settings; +use utils::settings::Settings; pub type ConnectionId = usize; pub type PostId = i32; @@ -57,6 +49,49 @@ pub type CommunityId = i32; pub type UserId = i32; pub type IPAddr = String; +pub fn send_email( + subject: &str, + to_email: &str, + to_username: &str, + html: &str, +) -> Result<(), String> { + let email_config = Settings::get().email.ok_or("no_email_setup")?; + + let email = Email::builder() + .to((to_email, to_username)) + .from(email_config.smtp_from_address.to_owned()) + .subject(subject) + .html(html) + .build() + .unwrap(); + + let mailer = if email_config.use_tls { + SmtpClient::new_simple(&email_config.smtp_server).unwrap() + } else { + SmtpClient::new(&email_config.smtp_server, ClientSecurity::None).unwrap() + } + .hello_name(ClientId::Domain(Settings::get().hostname)) + .smtp_utf8(true) + .authentication_mechanism(Mechanism::Plain) + .connection_reuse(ConnectionReuseParameters::ReuseUnlimited); + let mailer = if let (Some(login), Some(password)) = + (&email_config.smtp_login, &email_config.smtp_password) + { + mailer.credentials(Credentials::new(login.to_owned(), password.to_owned())) + } else { + mailer + }; + + let mut transport = mailer.transport(); + let result = transport.send(email.into()); + transport.close(); + + match result { + Ok(_) => Ok(()), + Err(e) => Err(e.to_string()), + } +} + pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime { DateTime::::from_utc(ndt, Utc) } @@ -69,10 +104,6 @@ pub fn naive_from_unix(time: i64) -> NaiveDateTime { NaiveDateTime::from_timestamp(time, 0) } -pub fn is_email_regex(test: &str) -> bool { - EMAIL_REGEX.is_match(test) -} - pub fn is_image_content_type(test: &str) -> Result<(), failure::Error> { if isahc::get(test)? .headers() @@ -129,49 +160,6 @@ pub fn generate_random_string() -> String { thread_rng().sample_iter(&Alphanumeric).take(30).collect() } -pub fn send_email( - subject: &str, - to_email: &str, - to_username: &str, - html: &str, -) -> Result<(), String> { - let email_config = Settings::get().email.ok_or("no_email_setup")?; - - let email = Email::builder() - .to((to_email, to_username)) - .from(email_config.smtp_from_address.to_owned()) - .subject(subject) - .html(html) - .build() - .unwrap(); - - let mailer = if email_config.use_tls { - SmtpClient::new_simple(&email_config.smtp_server).unwrap() - } else { - SmtpClient::new(&email_config.smtp_server, ClientSecurity::None).unwrap() - } - .hello_name(ClientId::Domain(Settings::get().hostname)) - .smtp_utf8(true) - .authentication_mechanism(Mechanism::Plain) - .connection_reuse(ConnectionReuseParameters::ReuseUnlimited); - let mailer = if let (Some(login), Some(password)) = - (&email_config.smtp_login, &email_config.smtp_password) - { - mailer.credentials(Credentials::new(login.to_owned(), password.to_owned())) - } else { - mailer - }; - - let mut transport = mailer.transport(); - let result = transport.send(email.into()); - transport.close(); - - match result { - Ok(_) => Ok(()), - Err(e) => Err(e.to_string()), - } -} - #[derive(Deserialize, Debug)] pub struct IframelyResponse { title: Option, @@ -286,7 +274,7 @@ mod tests { assert!(is_image_content_type( "https://twitter.com/BenjaminNorton/status/1259922424272957440?s=20" ) - .is_err()); + .is_err()); } #[test] @@ -362,8 +350,7 @@ mod tests { } lazy_static! { - static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap(); static ref SLUR_REGEX: Regex = RegexBuilder::new(r"(fag(g|got|tard)?|maricos?|cock\s?sucker(s|ing)?|nig(\b|g?(a|er)?(s|z)?)\b|dindu(s?)|mudslime?s?|kikes?|mongoloids?|towel\s*heads?|\bspi(c|k)s?\b|\bchinks?|niglets?|beaners?|\bnips?\b|\bcoons?\b|jungle\s*bunn(y|ies?)|jigg?aboo?s?|\bpakis?\b|rag\s*heads?|gooks?|cunts?|bitch(es|ing|y)?|puss(y|ies?)|twats?|feminazis?|whor(es?|ing)|\bslut(s|t?y)?|\btrann?(y|ies?)|ladyboy(s?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build().unwrap(); static ref USERNAME_MATCHES_REGEX: Regex = Regex::new(r"/u/[a-zA-Z][0-9a-zA-Z_]*").unwrap(); static ref VALID_USERNAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_]{3,20}$").unwrap(); -} +} \ No newline at end of file diff --git a/server/src/main.rs b/server/lemmy_server/src/main.rs similarity index 89% rename from server/src/main.rs rename to server/lemmy_server/src/main.rs index 3f91965e1..5af0ac586 100644 --- a/server/src/main.rs +++ b/server/lemmy_server/src/main.rs @@ -1,7 +1,5 @@ extern crate lemmy_server; #[macro_use] -extern crate diesel_migrations; -#[macro_use] pub extern crate lazy_static; use crate::lemmy_server::actix_web::dev::Service; @@ -11,17 +9,18 @@ use actix_web::dev::{ServiceRequest, ServiceResponse}; use actix_web::http::header::CONTENT_TYPE; use actix_web::http::{header::CACHE_CONTROL, HeaderValue}; use actix_web::*; -use diesel::r2d2::{ConnectionManager, Pool}; -use diesel::PgConnection; use lemmy_server::{ rate_limit::{rate_limiter::RateLimiter, RateLimit}, - routes::{api, federation, feeds, index, nodeinfo, webfinger}, - settings::Settings, + routes::{api, feeds, index, nodeinfo, webfinger}, websocket::server::*, }; +use utils::settings::Settings; use regex::Regex; use std::{io, sync::Arc}; use tokio::sync::Mutex; +use db::diesel::r2d2::ConnectionManager; +use r2d2::Pool; +use db::diesel::PgConnection; lazy_static! { static ref CACHE_CONTROL_REGEX: Regex = @@ -31,10 +30,9 @@ lazy_static! { static ref CACHE_CONTROL_VALUE: String = format!("public, max-age={}", 60 * 60); } -embed_migrations!(); - #[actix_rt::main] async fn main() -> io::Result<()> { + println!("test"); env_logger::init(); let settings = Settings::get(); @@ -45,10 +43,6 @@ async fn main() -> io::Result<()> { .build(manager) .unwrap_or_else(|_| panic!("Error connecting to {}", settings.get_database_url())); - // Run the migrations from code - let conn = pool.get().unwrap(); - embedded_migrations::run(&conn).unwrap(); - // Set up the rate limiter let rate_limiter = RateLimit { rate_limiter: Arc::new(Mutex::new(RateLimiter::default())), @@ -73,7 +67,6 @@ async fn main() -> io::Result<()> { .data(server.clone()) // The routes .configure(move |cfg| api::config(cfg, &rate_limiter)) - .configure(federation::config) .configure(feeds::config) .configure(index::config) .configure(nodeinfo::config) diff --git a/server/src/rate_limit/mod.rs b/server/lemmy_server/src/rate_limit/mod.rs similarity index 98% rename from server/src/rate_limit/mod.rs rename to server/lemmy_server/src/rate_limit/mod.rs index 8d698b78b..2b2c0833c 100644 --- a/server/src/rate_limit/mod.rs +++ b/server/lemmy_server/src/rate_limit/mod.rs @@ -1,9 +1,10 @@ pub mod rate_limiter; -use super::{IPAddr, Settings}; +use super::IPAddr; +use utils::settings::Settings; use crate::api::APIError; use crate::get_ip; -use crate::settings::RateLimitConfig; +use utils::settings::RateLimitConfig; use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; use failure::Error; use futures::future::{ok, Ready}; diff --git a/server/src/rate_limit/rate_limiter.rs b/server/lemmy_server/src/rate_limit/rate_limiter.rs similarity index 100% rename from server/src/rate_limit/rate_limiter.rs rename to server/lemmy_server/src/rate_limit/rate_limiter.rs diff --git a/server/src/routes/api.rs b/server/lemmy_server/src/routes/api.rs similarity index 100% rename from server/src/routes/api.rs rename to server/lemmy_server/src/routes/api.rs diff --git a/server/src/routes/feeds.rs b/server/lemmy_server/src/routes/feeds.rs similarity index 96% rename from server/src/routes/feeds.rs rename to server/lemmy_server/src/routes/feeds.rs index 815953c55..9d34f53d8 100644 --- a/server/src/routes/feeds.rs +++ b/server/lemmy_server/src/routes/feeds.rs @@ -1,11 +1,11 @@ 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 db::comment_view::{ReplyQueryBuilder, ReplyView}; +use db::community::Community; +use db::post_view::{PostQueryBuilder, PostView}; +use db::site_view::SiteView; +use db::user::{Claims, User_}; +use db::user_mention_view::{UserMentionQueryBuilder, UserMentionView}; +use db::{ListingType, SortType}; #[derive(Deserialize)] pub struct Params { diff --git a/server/src/routes/index.rs b/server/lemmy_server/src/routes/index.rs similarity index 100% rename from server/src/routes/index.rs rename to server/lemmy_server/src/routes/index.rs diff --git a/server/src/routes/mod.rs b/server/lemmy_server/src/routes/mod.rs similarity index 88% rename from server/src/routes/mod.rs rename to server/lemmy_server/src/routes/mod.rs index 37c56eba0..23510d7f8 100644 --- a/server/src/routes/mod.rs +++ b/server/lemmy_server/src/routes/mod.rs @@ -1,5 +1,5 @@ use crate::api::{Oper, Perform}; -use crate::db::site_view::SiteView; +use 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}; @@ -8,10 +8,6 @@ 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}; @@ -21,13 +17,15 @@ use std::str::FromStr; use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; use strum::ParseError; +use db::diesel::r2d2::ConnectionManager; +use r2d2::Pool; +use db::diesel::PgConnection; pub type DbPoolParam = web::Data>>; pub type RateLimitParam = web::Data>>; pub type ChatServerParam = web::Data>; pub mod api; -pub mod federation; pub mod feeds; pub mod index; pub mod nodeinfo; diff --git a/server/src/routes/nodeinfo.rs b/server/lemmy_server/src/routes/nodeinfo.rs similarity index 100% rename from server/src/routes/nodeinfo.rs rename to server/lemmy_server/src/routes/nodeinfo.rs diff --git a/server/src/routes/webfinger.rs b/server/lemmy_server/src/routes/webfinger.rs similarity index 97% rename from server/src/routes/webfinger.rs rename to server/lemmy_server/src/routes/webfinger.rs index 18a21efa1..db7ececc9 100644 --- a/server/src/routes/webfinger.rs +++ b/server/lemmy_server/src/routes/webfinger.rs @@ -1,5 +1,6 @@ use super::*; -use crate::db::community::Community; +use db::community::Community; +use db::diesel::r2d2::ConnectionManager; #[derive(Deserialize)] pub struct Params { diff --git a/server/src/routes/websocket.rs b/server/lemmy_server/src/routes/websocket.rs similarity index 100% rename from server/src/routes/websocket.rs rename to server/lemmy_server/src/routes/websocket.rs diff --git a/server/src/version.rs b/server/lemmy_server/src/version.rs similarity index 100% rename from server/src/version.rs rename to server/lemmy_server/src/version.rs diff --git a/server/src/websocket/mod.rs b/server/lemmy_server/src/websocket/mod.rs similarity index 94% rename from server/src/websocket/mod.rs rename to server/lemmy_server/src/websocket/mod.rs index fd200d7d6..3fa7f4c9c 100644 --- a/server/src/websocket/mod.rs +++ b/server/lemmy_server/src/websocket/mod.rs @@ -2,8 +2,6 @@ pub mod server; use crate::ConnectionId; use actix::prelude::*; -use diesel::r2d2::{ConnectionManager, Pool}; -use diesel::PgConnection; use failure::Error; use log::{error, info}; use rand::{rngs::ThreadRng, Rng}; diff --git a/server/src/websocket/server.rs b/server/lemmy_server/src/websocket/server.rs similarity index 99% rename from server/src/websocket/server.rs rename to server/lemmy_server/src/websocket/server.rs index 25766011c..4143a30eb 100644 --- a/server/src/websocket/server.rs +++ b/server/lemmy_server/src/websocket/server.rs @@ -12,6 +12,9 @@ use crate::api::*; use crate::rate_limit::RateLimit; use crate::websocket::UserOperation; use crate::{CommunityId, ConnectionId, IPAddr, PostId, UserId}; +use r2d2::Pool; +use db::diesel::r2d2::ConnectionManager; +use db::diesel::PgConnection; /// Chat server sends this messages to session #[derive(Message)] diff --git a/server/schema/Cargo.toml b/server/schema/Cargo.toml new file mode 100644 index 000000000..8416b03a4 --- /dev/null +++ b/server/schema/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "schema" +version = "0.1.0" +authors = ["Felix Ableitner "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +diesel = { version = "1.4.2", features = ["postgres", "64-column-tables"] } diff --git a/server/schema/src/lib.rs b/server/schema/src/lib.rs new file mode 100644 index 000000000..cf6847fb2 --- /dev/null +++ b/server/schema/src/lib.rs @@ -0,0 +1,4 @@ +#[macro_use] +pub extern crate diesel; + +pub mod schema; diff --git a/server/src/schema.rs b/server/schema/src/schema.rs similarity index 100% rename from server/src/schema.rs rename to server/schema/src/schema.rs diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs deleted file mode 100644 index 32f14eeb2..000000000 --- a/server/src/apub/community.rs +++ /dev/null @@ -1,109 +0,0 @@ -use crate::apub::make_apub_endpoint; -use crate::db::community::Community; -use crate::db::community_view::CommunityFollowerView; -use crate::db::establish_unpooled_connection; -use crate::to_datetime_utc; -use activitypub::{actor::Group, collection::UnorderedCollection, context}; -use actix_web::body::Body; -use actix_web::web::Path; -use actix_web::HttpResponse; -use serde::Deserialize; - -impl Community { - pub fn as_group(&self) -> Group { - let base_url = make_apub_endpoint("c", &self.name); - - let mut group = Group::default(); - - group.object_props.set_context_object(context()).ok(); - group.object_props.set_id_string(base_url.to_string()).ok(); - group - .object_props - .set_name_string(self.name.to_owned()) - .ok(); - group - .object_props - .set_published_utctime(to_datetime_utc(self.published)) - .ok(); - if let Some(updated) = self.updated { - group - .object_props - .set_updated_utctime(to_datetime_utc(updated)) - .ok(); - } - - if let Some(description) = &self.description { - group - .object_props - .set_summary_string(description.to_string()) - .ok(); - } - - group - .ap_actor_props - .set_inbox_string(format!("{}/inbox", &base_url)) - .ok(); - group - .ap_actor_props - .set_outbox_string(format!("{}/outbox", &base_url)) - .ok(); - group - .ap_actor_props - .set_followers_string(format!("{}/followers", &base_url)) - .ok(); - - group - } - - pub fn followers_as_collection(&self) -> UnorderedCollection { - let base_url = make_apub_endpoint("c", &self.name); - - let mut collection = UnorderedCollection::default(); - collection.object_props.set_context_object(context()).ok(); - collection.object_props.set_id_string(base_url).ok(); - - let connection = establish_unpooled_connection(); - //As we are an object, we validated that the community id was valid - let community_followers = CommunityFollowerView::for_community(&connection, self.id).unwrap(); - - let ap_followers = community_followers - .iter() - .map(|follower| make_apub_endpoint("u", &follower.user_name)) - .collect(); - - collection - .collection_props - .set_items_string_vec(ap_followers) - .unwrap(); - collection - } -} - -#[derive(Deserialize)] -pub struct CommunityQuery { - community_name: String, -} - -pub async fn get_apub_community(info: Path) -> HttpResponse { - let connection = establish_unpooled_connection(); - - if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) { - HttpResponse::Ok() - .content_type("application/activity+json") - .body(serde_json::to_string(&community.as_group()).unwrap()) - } else { - HttpResponse::NotFound().finish() - } -} - -pub async fn get_apub_community_followers(info: Path) -> HttpResponse { - let connection = establish_unpooled_connection(); - - if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) { - HttpResponse::Ok() - .content_type("application/activity+json") - .body(serde_json::to_string(&community.followers_as_collection()).unwrap()) - } else { - HttpResponse::NotFound().finish() - } -} diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs deleted file mode 100644 index e224e2591..000000000 --- a/server/src/apub/mod.rs +++ /dev/null @@ -1,107 +0,0 @@ -pub mod community; -pub mod post; -pub mod user; -use crate::Settings; - -use std::fmt::Display; - -#[cfg(test)] -mod tests { - use crate::db::community::Community; - use crate::db::post::Post; - use crate::db::user::User_; - use crate::db::{ListingType, SortType}; - use crate::{naive_now, Settings}; - - #[test] - fn test_person() { - let user = User_ { - id: 52, - name: "thom".into(), - fedi_name: "rrf".into(), - preferred_username: None, - password_encrypted: "here".into(), - email: None, - matrix_user_id: None, - avatar: None, - published: naive_now(), - admin: false, - banned: false, - updated: None, - show_nsfw: false, - theme: "darkly".into(), - default_sort_type: SortType::Hot as i16, - default_listing_type: ListingType::Subscribed as i16, - lang: "browser".into(), - show_avatars: true, - send_notifications_to_email: false, - }; - - let person = user.as_person(); - assert_eq!( - format!("https://{}/federation/u/thom", Settings::get().hostname), - person.object_props.id_string().unwrap() - ); - } - - #[test] - fn test_community() { - let community = Community { - id: 42, - name: "Test".into(), - title: "Test Title".into(), - description: Some("Test community".into()), - category_id: 32, - creator_id: 52, - removed: false, - published: naive_now(), - updated: Some(naive_now()), - deleted: false, - nsfw: false, - }; - - let group = community.as_group(); - assert_eq!( - format!("https://{}/federation/c/Test", Settings::get().hostname), - group.object_props.id_string().unwrap() - ); - } - - #[test] - fn test_post() { - let post = Post { - id: 62, - name: "A test post".into(), - url: None, - body: None, - creator_id: 52, - community_id: 42, - published: naive_now(), - removed: false, - locked: false, - stickied: false, - nsfw: false, - deleted: false, - updated: None, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - }; - - let page = post.as_page(); - assert_eq!( - format!("https://{}/federation/post/62", Settings::get().hostname), - page.object_props.id_string().unwrap() - ); - } -} - -pub fn make_apub_endpoint(point: S, value: T) -> String { - format!( - "https://{}/federation/{}/{}", - Settings::get().hostname, - point, - value - ) -} diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs deleted file mode 100644 index ebb171290..000000000 --- a/server/src/apub/post.rs +++ /dev/null @@ -1,38 +0,0 @@ -use crate::apub::make_apub_endpoint; -use crate::db::post::Post; -use crate::to_datetime_utc; -use activitypub::{context, object::Page}; - -impl Post { - pub fn as_page(&self) -> Page { - let base_url = make_apub_endpoint("post", self.id); - let mut page = Page::default(); - - page.object_props.set_context_object(context()).ok(); - page.object_props.set_id_string(base_url).ok(); - page.object_props.set_name_string(self.name.to_owned()).ok(); - - if let Some(body) = &self.body { - page.object_props.set_content_string(body.to_owned()).ok(); - } - - if let Some(url) = &self.url { - page.object_props.set_url_string(url.to_owned()).ok(); - } - - //page.object_props.set_attributed_to_string - - page - .object_props - .set_published_utctime(to_datetime_utc(self.published)) - .ok(); - if let Some(updated) = self.updated { - page - .object_props - .set_updated_utctime(to_datetime_utc(updated)) - .ok(); - } - - page - } -} diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs deleted file mode 100644 index 5f2421f11..000000000 --- a/server/src/apub/user.rs +++ /dev/null @@ -1,74 +0,0 @@ -use crate::apub::make_apub_endpoint; -use crate::db::establish_unpooled_connection; -use crate::db::user::User_; -use crate::to_datetime_utc; -use activitypub::{actor::Person, context}; -use actix_web::body::Body; -use actix_web::web::Path; -use actix_web::HttpResponse; -use serde::Deserialize; - -impl User_ { - pub fn as_person(&self) -> Person { - let base_url = make_apub_endpoint("u", &self.name); - let mut person = Person::default(); - person.object_props.set_context_object(context()).ok(); - person.object_props.set_id_string(base_url.to_string()).ok(); - person - .object_props - .set_name_string(self.name.to_owned()) - .ok(); - person - .object_props - .set_published_utctime(to_datetime_utc(self.published)) - .ok(); - if let Some(updated) = self.updated { - person - .object_props - .set_updated_utctime(to_datetime_utc(updated)) - .ok(); - } - - person - .ap_actor_props - .set_inbox_string(format!("{}/inbox", &base_url)) - .ok(); - person - .ap_actor_props - .set_outbox_string(format!("{}/outbox", &base_url)) - .ok(); - person - .ap_actor_props - .set_following_string(format!("{}/following", &base_url)) - .ok(); - person - .ap_actor_props - .set_liked_string(format!("{}/liked", &base_url)) - .ok(); - if let Some(i) = &self.preferred_username { - person - .ap_actor_props - .set_preferred_username_string(i.to_string()) - .ok(); - } - - person - } -} - -#[derive(Deserialize)] -pub struct UserQuery { - user_name: String, -} - -pub async fn get_apub_user(info: Path) -> HttpResponse { - let connection = establish_unpooled_connection(); - - if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) { - HttpResponse::Ok() - .content_type("application/activity+json") - .body(serde_json::to_string(&user.as_person()).unwrap()) - } else { - HttpResponse::NotFound().finish() - } -} diff --git a/server/src/routes/federation.rs b/server/src/routes/federation.rs deleted file mode 100644 index bc627cb0e..000000000 --- a/server/src/routes/federation.rs +++ /dev/null @@ -1,18 +0,0 @@ -use super::*; -use crate::apub; - -pub fn config(cfg: &mut web::ServiceConfig) { - cfg - .route( - "/federation/c/{community_name}", - web::get().to(apub::community::get_apub_community), - ) - .route( - "/federation/c/{community_name}/followers", - web::get().to(apub::community::get_apub_community_followers), - ) - .route( - "/federation/u/{user_name}", - web::get().to(apub::user::get_apub_user), - ); -} diff --git a/server/utils/Cargo.toml b/server/utils/Cargo.toml new file mode 100644 index 000000000..3e3328a53 --- /dev/null +++ b/server/utils/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "utils" +version = "0.1.0" +authors = ["Felix Ableitner "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +lazy_static = "1.3.0" +regex = "1.3.5" +serde = { version = "1.0.105", features = ["derive"] } +failure = "0.1.8" +config = "0.10.1" +hjson = "0.8.2" +chrono = { version = "0.4.7", features = ["serde"] } diff --git a/server/utils/src/lib.rs b/server/utils/src/lib.rs new file mode 100644 index 000000000..4b4e0618b --- /dev/null +++ b/server/utils/src/lib.rs @@ -0,0 +1,14 @@ +#[macro_use] +pub extern crate lazy_static; +use regex::{Regex, RegexBuilder}; +use chrono::{NaiveDateTime, DateTime, Utc}; + +pub mod settings; + +pub fn is_email_regex(test: &str) -> bool { + EMAIL_REGEX.is_match(test) +} + +lazy_static! { + static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap(); +} \ No newline at end of file diff --git a/server/src/settings.rs b/server/utils/src/settings.rs similarity index 100% rename from server/src/settings.rs rename to server/utils/src/settings.rs