From: nutomic Date: Thu, 3 Sep 2020 19:45:12 +0000 (+0000) Subject: Various things refactored (#95) X-Git-Url: http://these/git/%22https:/image.com/readmes/%7B%60%24%7BarchiveUrl%7D/static/%24%7Bargs.pageFn.next%7D?a=commitdiff_plain;h=bd0e69b2bbda8e37190f506e5858cf9c5b2abbfd;p=lemmy.git Various things refactored (#95) Remove unused derive macros lemmy_rate_limit doesnt depend on lemmy_api_structs anymore Dont use "pub extern crate" Co-authored-by: Felix Ableitner Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/95 --- diff --git a/server/Cargo.lock b/server/Cargo.lock index 305af342..023a3f9d 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1800,7 +1800,6 @@ version = "0.1.0" dependencies = [ "lemmy_db", "serde 1.0.114", - "thiserror", ] [[package]] @@ -1827,7 +1826,6 @@ version = "0.1.0" dependencies = [ "actix-web", "futures", - "lemmy_api_structs", "lemmy_utils", "log", "strum", @@ -1904,6 +1902,7 @@ dependencies = [ "regex", "serde 1.0.114", "serde_json", + "thiserror", "url", ] diff --git a/server/lemmy_api_structs/Cargo.toml b/server/lemmy_api_structs/Cargo.toml index 93653fba..3778422b 100644 --- a/server/lemmy_api_structs/Cargo.toml +++ b/server/lemmy_api_structs/Cargo.toml @@ -11,4 +11,3 @@ path = "src/lib.rs" [dependencies] lemmy_db = { path = "../lemmy_db" } serde = { version = "1.0.105", features = ["derive"] } -thiserror = "1.0.20" diff --git a/server/lemmy_api_structs/src/comment.rs b/server/lemmy_api_structs/src/comment.rs index 8dbefff6..906c3996 100644 --- a/server/lemmy_api_structs/src/comment.rs +++ b/server/lemmy_api_structs/src/comment.rs @@ -1,7 +1,7 @@ use lemmy_db::comment_view::CommentView; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct CreateComment { pub content: String, pub parent_id: Option, @@ -10,7 +10,7 @@ pub struct CreateComment { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct EditComment { pub content: String, pub edit_id: i32, @@ -18,14 +18,14 @@ pub struct EditComment { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct DeleteComment { pub edit_id: i32, pub deleted: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct RemoveComment { pub edit_id: i32, pub removed: bool, @@ -33,35 +33,35 @@ pub struct RemoveComment { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct MarkCommentAsRead { pub edit_id: i32, pub read: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct SaveComment { pub comment_id: i32, pub save: bool, pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct CommentResponse { pub comment: CommentView, pub recipient_ids: Vec, pub form_id: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct CreateCommentLike { pub comment_id: i32, pub score: i16, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetComments { pub type_: String, pub sort: String, @@ -71,7 +71,7 @@ pub struct GetComments { pub auth: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetCommentsResponse { pub comments: Vec, } diff --git a/server/lemmy_api_structs/src/community.rs b/server/lemmy_api_structs/src/community.rs index 8d07360e..52c2ec55 100644 --- a/server/lemmy_api_structs/src/community.rs +++ b/server/lemmy_api_structs/src/community.rs @@ -4,21 +4,21 @@ use lemmy_db::{ }; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetCommunity { pub id: Option, pub name: Option, pub auth: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetCommunityResponse { pub community: CommunityView, pub moderators: Vec, pub online: usize, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct CreateCommunity { pub name: String, pub title: String, @@ -30,12 +30,12 @@ pub struct CreateCommunity { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct CommunityResponse { pub community: CommunityView, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct ListCommunities { pub sort: String, pub page: Option, @@ -43,12 +43,12 @@ pub struct ListCommunities { pub auth: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Debug)] pub struct ListCommunitiesResponse { pub communities: Vec, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Deserialize, Clone)] pub struct BanFromCommunity { pub community_id: i32, pub user_id: i32, @@ -59,13 +59,13 @@ pub struct BanFromCommunity { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct BanFromCommunityResponse { pub user: UserView, pub banned: bool, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct AddModToCommunity { pub community_id: i32, pub user_id: i32, @@ -73,12 +73,12 @@ pub struct AddModToCommunity { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct AddModToCommunityResponse { pub moderators: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct EditCommunity { pub edit_id: i32, pub title: String, @@ -90,14 +90,14 @@ pub struct EditCommunity { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct DeleteCommunity { pub edit_id: i32, pub deleted: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct RemoveCommunity { pub edit_id: i32, pub removed: bool, @@ -106,24 +106,24 @@ pub struct RemoveCommunity { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct FollowCommunity { pub community_id: i32, pub follow: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetFollowedCommunities { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetFollowedCommunitiesResponse { pub communities: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct TransferCommunity { pub community_id: i32, pub user_id: i32, diff --git a/server/lemmy_api_structs/src/lib.rs b/server/lemmy_api_structs/src/lib.rs index df583040..b3576a0d 100644 --- a/server/lemmy_api_structs/src/lib.rs +++ b/server/lemmy_api_structs/src/lib.rs @@ -1,24 +1,7 @@ -pub extern crate serde; -pub extern crate thiserror; +extern crate serde; pub mod comment; pub mod community; pub mod post; pub mod site; pub mod user; - -use thiserror::Error; - -#[derive(Debug, Error)] -#[error("{{\"error\":\"{message}\"}}")] -pub struct APIError { - pub message: String, -} - -impl APIError { - pub fn err(msg: &str) -> Self { - APIError { - message: msg.to_string(), - } - } -} diff --git a/server/lemmy_api_structs/src/post.rs b/server/lemmy_api_structs/src/post.rs index 5860b2b2..d1adf1bd 100644 --- a/server/lemmy_api_structs/src/post.rs +++ b/server/lemmy_api_structs/src/post.rs @@ -5,7 +5,7 @@ use lemmy_db::{ }; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct CreatePost { pub name: String, pub url: Option, @@ -15,18 +15,18 @@ pub struct CreatePost { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct PostResponse { pub post: PostView, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetPost { pub id: i32, pub auth: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetPostResponse { pub post: PostView, pub comments: Vec, @@ -35,7 +35,7 @@ pub struct GetPostResponse { pub online: usize, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct GetPosts { pub type_: String, pub sort: String, @@ -46,19 +46,19 @@ pub struct GetPosts { pub auth: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Debug)] pub struct GetPostsResponse { pub posts: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct CreatePostLike { pub post_id: i32, pub score: i16, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct EditPost { pub edit_id: i32, pub name: String, @@ -68,14 +68,14 @@ pub struct EditPost { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct DeletePost { pub edit_id: i32, pub deleted: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct RemovePost { pub edit_id: i32, pub removed: bool, @@ -83,21 +83,21 @@ pub struct RemovePost { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct LockPost { pub edit_id: i32, pub locked: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct StickyPost { pub edit_id: i32, pub stickied: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct SavePost { pub post_id: i32, pub save: bool, diff --git a/server/lemmy_api_structs/src/site.rs b/server/lemmy_api_structs/src/site.rs index 7766a5f9..b82b325e 100644 --- a/server/lemmy_api_structs/src/site.rs +++ b/server/lemmy_api_structs/src/site.rs @@ -10,15 +10,15 @@ use lemmy_db::{ }; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct ListCategories {} -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct ListCategoriesResponse { pub categories: Vec, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct Search { pub q: String, pub type_: String, @@ -29,7 +29,7 @@ pub struct Search { pub auth: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Debug)] pub struct SearchResponse { pub type_: String, pub comments: Vec, @@ -38,7 +38,7 @@ pub struct SearchResponse { pub users: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetModlog { pub mod_user_id: Option, pub community_id: Option, @@ -46,7 +46,7 @@ pub struct GetModlog { pub limit: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetModlogResponse { pub removed_posts: Vec, pub locked_posts: Vec, @@ -59,7 +59,7 @@ pub struct GetModlogResponse { pub added: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct CreateSite { pub name: String, pub description: Option, @@ -71,7 +71,7 @@ pub struct CreateSite { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct EditSite { pub name: String, pub description: Option, @@ -83,17 +83,17 @@ pub struct EditSite { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetSite { pub auth: Option, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct SiteResponse { pub site: SiteView, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetSiteResponse { pub site: Option, pub admins: Vec, @@ -104,23 +104,23 @@ pub struct GetSiteResponse { pub federated_instances: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct TransferSite { pub user_id: i32, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetSiteConfig { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetSiteConfigResponse { pub config_hjson: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct SaveSiteConfig { pub config_hjson: String, pub auth: String, diff --git a/server/lemmy_api_structs/src/user.rs b/server/lemmy_api_structs/src/user.rs index 5954e2b9..43eadb11 100644 --- a/server/lemmy_api_structs/src/user.rs +++ b/server/lemmy_api_structs/src/user.rs @@ -8,13 +8,13 @@ use lemmy_db::{ }; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct Login { pub username_or_email: String, pub password: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct Register { pub username: String, pub email: Option, @@ -26,22 +26,22 @@ pub struct Register { pub captcha_answer: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetCaptcha {} -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetCaptchaResponse { pub ok: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct CaptchaResponse { pub png: String, // A Base64 encoded png pub wav: Option, // A Base64 encoded wav audio pub uuid: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct SaveUserSettings { pub show_nsfw: bool, pub theme: String, @@ -62,12 +62,12 @@ pub struct SaveUserSettings { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct LoginResponse { pub jwt: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetUserDetails { pub user_id: Option, pub username: Option, @@ -79,7 +79,7 @@ pub struct GetUserDetails { pub auth: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetUserDetailsResponse { pub user: UserView, pub follows: Vec, @@ -88,34 +88,34 @@ pub struct GetUserDetailsResponse { pub posts: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetRepliesResponse { pub replies: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize)] pub struct GetUserMentionsResponse { pub mentions: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct MarkAllAsRead { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct AddAdmin { pub user_id: i32, pub added: bool, pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct AddAdminResponse { pub admins: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct BanUser { pub user_id: i32, pub ban: bool, @@ -125,13 +125,13 @@ pub struct BanUser { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct BanUserResponse { pub user: UserView, pub banned: bool, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetReplies { pub sort: String, pub page: Option, @@ -140,7 +140,7 @@ pub struct GetReplies { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetUserMentions { pub sort: String, pub page: Option, @@ -149,68 +149,68 @@ pub struct GetUserMentions { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct MarkUserMentionAsRead { pub user_mention_id: i32, pub read: bool, pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct UserMentionResponse { pub mention: UserMentionView, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct DeleteAccount { pub password: String, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct PasswordReset { pub email: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct PasswordResetResponse {} -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct PasswordChange { pub token: String, pub password: String, pub password_verify: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct CreatePrivateMessage { pub content: String, pub recipient_id: i32, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct EditPrivateMessage { pub edit_id: i32, pub content: String, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct DeletePrivateMessage { pub edit_id: i32, pub deleted: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct MarkPrivateMessageAsRead { pub edit_id: i32, pub read: bool, pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] pub struct GetPrivateMessages { pub unread_only: bool, pub page: Option, @@ -218,22 +218,22 @@ pub struct GetPrivateMessages { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct PrivateMessagesResponse { pub messages: Vec, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct PrivateMessageResponse { pub message: PrivateMessageView, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct UserJoin { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Clone)] pub struct UserJoinResponse { pub user_id: i32, } diff --git a/server/lemmy_db/src/activity.rs b/server/lemmy_db/src/activity.rs index c28eda45..6a5beb3b 100644 --- a/server/lemmy_db/src/activity.rs +++ b/server/lemmy_db/src/activity.rs @@ -1,14 +1,14 @@ use crate::{schema::activity, Crud}; use diesel::{dsl::*, result::Error, *}; use log::debug; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; use serde_json::Value; use std::{ fmt::Debug, io::{Error as IoError, ErrorKind}, }; -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "activity"] pub struct Activity { pub id: i32, @@ -19,7 +19,7 @@ pub struct Activity { pub updated: Option, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "activity"] pub struct ActivityForm { pub user_id: i32, diff --git a/server/lemmy_db/src/category.rs b/server/lemmy_db/src/category.rs index ff4e757b..c4165c22 100644 --- a/server/lemmy_db/src/category.rs +++ b/server/lemmy_db/src/category.rs @@ -3,16 +3,16 @@ use crate::{ Crud, }; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize)] #[table_name = "category"] pub struct Category { pub id: i32, pub name: String, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "category"] pub struct CategoryForm { pub name: String, diff --git a/server/lemmy_db/src/comment.rs b/server/lemmy_db/src/comment.rs index 76fa5ea0..bc2a574e 100644 --- a/server/lemmy_db/src/comment.rs +++ b/server/lemmy_db/src/comment.rs @@ -7,7 +7,6 @@ use crate::{ Saveable, }; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; use url::{ParseError, Url}; // WITH RECURSIVE MyTree AS ( @@ -17,7 +16,7 @@ use url::{ParseError, Url}; // ) // SELECT * FROM MyTree; -#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug)] #[belongs_to(Post)] #[table_name = "comment"] pub struct Comment { @@ -230,7 +229,7 @@ pub struct CommentSaved { pub published: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset)] #[table_name = "comment_saved"] pub struct CommentSavedForm { pub comment_id: i32, diff --git a/server/lemmy_db/src/comment_view.rs b/server/lemmy_db/src/comment_view.rs index a1751ca6..d7e5c08d 100644 --- a/server/lemmy_db/src/comment_view.rs +++ b/server/lemmy_db/src/comment_view.rs @@ -85,7 +85,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "comment_fast_view"] pub struct CommentView { diff --git a/server/lemmy_db/src/community.rs b/server/lemmy_db/src/community.rs index d033412c..918d44f1 100644 --- a/server/lemmy_db/src/community.rs +++ b/server/lemmy_db/src/community.rs @@ -7,9 +7,8 @@ use crate::{ Joinable, }; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; -#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, Queryable, Identifiable, PartialEq, Debug)] #[table_name = "community"] pub struct Community { pub id: i32, @@ -32,7 +31,7 @@ pub struct Community { pub banner: Option, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize, Debug)] +#[derive(Insertable, AsChangeset, Debug)] #[table_name = "community"] pub struct CommunityForm { pub name: String, diff --git a/server/lemmy_db/src/community_view.rs b/server/lemmy_db/src/community_view.rs index e8353779..1ecca0a1 100644 --- a/server/lemmy_db/src/community_view.rs +++ b/server/lemmy_db/src/community_view.rs @@ -124,7 +124,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "community_fast_view"] pub struct CommunityView { diff --git a/server/lemmy_db/src/lib.rs b/server/lemmy_db/src/lib.rs index 4a4748ce..ed6e1dfb 100644 --- a/server/lemmy_db/src/lib.rs +++ b/server/lemmy_db/src/lib.rs @@ -1,17 +1,17 @@ #[macro_use] -pub extern crate diesel; +extern crate diesel; #[macro_use] -pub extern crate strum_macros; +extern crate strum_macros; #[macro_use] -pub extern crate lazy_static; -pub extern crate bcrypt; -pub extern crate chrono; -pub extern crate log; -pub extern crate regex; -pub extern crate serde; -pub extern crate serde_json; -pub extern crate sha2; -pub extern crate strum; +extern crate lazy_static; +extern crate bcrypt; +extern crate chrono; +extern crate log; +extern crate regex; +extern crate serde; +extern crate serde_json; +extern crate sha2; +extern crate strum; use chrono::NaiveDateTime; use diesel::{result::Error, *}; diff --git a/server/lemmy_db/src/moderator.rs b/server/lemmy_db/src/moderator.rs index 7d453d35..aaed1314 100644 --- a/server/lemmy_db/src/moderator.rs +++ b/server/lemmy_db/src/moderator.rs @@ -13,9 +13,8 @@ use crate::{ Crud, }; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_remove_post"] pub struct ModRemovePost { pub id: i32, @@ -26,7 +25,7 @@ pub struct ModRemovePost { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_remove_post"] pub struct ModRemovePostForm { pub mod_user_id: i32, @@ -56,7 +55,7 @@ impl Crud for ModRemovePost { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_lock_post"] pub struct ModLockPost { pub id: i32, @@ -66,7 +65,7 @@ pub struct ModLockPost { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_lock_post"] pub struct ModLockPostForm { pub mod_user_id: i32, @@ -95,7 +94,7 @@ impl Crud for ModLockPost { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_sticky_post"] pub struct ModStickyPost { pub id: i32, @@ -105,7 +104,7 @@ pub struct ModStickyPost { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_sticky_post"] pub struct ModStickyPostForm { pub mod_user_id: i32, @@ -134,7 +133,7 @@ impl Crud for ModStickyPost { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_remove_comment"] pub struct ModRemoveComment { pub id: i32, @@ -145,7 +144,7 @@ pub struct ModRemoveComment { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_remove_comment"] pub struct ModRemoveCommentForm { pub mod_user_id: i32, @@ -175,7 +174,7 @@ impl Crud for ModRemoveComment { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_remove_community"] pub struct ModRemoveCommunity { pub id: i32, @@ -187,7 +186,7 @@ pub struct ModRemoveCommunity { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_remove_community"] pub struct ModRemoveCommunityForm { pub mod_user_id: i32, @@ -222,7 +221,7 @@ impl Crud for ModRemoveCommunity { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_ban_from_community"] pub struct ModBanFromCommunity { pub id: i32, @@ -235,7 +234,7 @@ pub struct ModBanFromCommunity { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_ban_from_community"] pub struct ModBanFromCommunityForm { pub mod_user_id: i32, @@ -271,7 +270,7 @@ impl Crud for ModBanFromCommunity { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_ban"] pub struct ModBan { pub id: i32, @@ -283,7 +282,7 @@ pub struct ModBan { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_ban"] pub struct ModBanForm { pub mod_user_id: i32, @@ -312,7 +311,7 @@ impl Crud for ModBan { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_add_community"] pub struct ModAddCommunity { pub id: i32, @@ -323,7 +322,7 @@ pub struct ModAddCommunity { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_add_community"] pub struct ModAddCommunityForm { pub mod_user_id: i32, @@ -353,7 +352,7 @@ impl Crud for ModAddCommunity { } } -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "mod_add"] pub struct ModAdd { pub id: i32, @@ -363,7 +362,7 @@ pub struct ModAdd { pub when_: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "mod_add"] pub struct ModAddForm { pub mod_user_id: i32, diff --git a/server/lemmy_db/src/moderator_views.rs b/server/lemmy_db/src/moderator_views.rs index 024907c3..7054a05a 100644 --- a/server/lemmy_db/src/moderator_views.rs +++ b/server/lemmy_db/src/moderator_views.rs @@ -1,6 +1,6 @@ use crate::limit_and_offset; use diesel::{result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; table! { mod_remove_post_view (id) { @@ -18,7 +18,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_remove_post_view"] pub struct ModRemovePostView { @@ -78,7 +78,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_lock_post_view"] pub struct ModLockPostView { @@ -137,7 +137,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_sticky_post_view"] pub struct ModStickyPostView { @@ -201,7 +201,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_remove_comment_view"] pub struct ModRemoveCommentView { @@ -265,7 +265,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_remove_community_view"] pub struct ModRemoveCommunityView { @@ -321,7 +321,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_ban_from_community_view"] pub struct ModBanFromCommunityView { @@ -382,7 +382,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_ban_view"] pub struct ModBanView { @@ -436,7 +436,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_add_community_view"] pub struct ModAddCommunityView { @@ -493,7 +493,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "mod_add_view"] pub struct ModAddView { diff --git a/server/lemmy_db/src/password_reset_request.rs b/server/lemmy_db/src/password_reset_request.rs index 0b058743..fde47c98 100644 --- a/server/lemmy_db/src/password_reset_request.rs +++ b/server/lemmy_db/src/password_reset_request.rs @@ -14,7 +14,7 @@ pub struct PasswordResetRequest { pub published: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset)] #[table_name = "password_reset_request"] pub struct PasswordResetRequestForm { pub user_id: i32, diff --git a/server/lemmy_db/src/post.rs b/server/lemmy_db/src/post.rs index 177659eb..7d13eb80 100644 --- a/server/lemmy_db/src/post.rs +++ b/server/lemmy_db/src/post.rs @@ -7,10 +7,9 @@ use crate::{ Saveable, }; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; use url::{ParseError, Url}; -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "post"] pub struct Post { pub id: i32, @@ -34,7 +33,7 @@ pub struct Post { pub local: bool, } -#[derive(Insertable, AsChangeset, Clone, Debug)] +#[derive(Insertable, AsChangeset)] #[table_name = "post"] pub struct PostForm { pub name: String, @@ -261,7 +260,7 @@ pub struct PostSaved { pub published: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset)] #[table_name = "post_saved"] pub struct PostSavedForm { pub post_id: i32, @@ -299,7 +298,7 @@ pub struct PostRead { pub published: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset)] #[table_name = "post_read"] pub struct PostReadForm { pub post_id: i32, diff --git a/server/lemmy_db/src/post_view.rs b/server/lemmy_db/src/post_view.rs index eb2429c6..3d3afb70 100644 --- a/server/lemmy_db/src/post_view.rs +++ b/server/lemmy_db/src/post_view.rs @@ -1,7 +1,7 @@ use super::post_view::post_fast_view::BoxedQuery; use crate::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType}; use diesel::{dsl::*, pg::Pg, result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; // The faked schema since diesel doesn't do views table! { @@ -107,7 +107,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "post_fast_view"] pub struct PostView { diff --git a/server/lemmy_db/src/private_message.rs b/server/lemmy_db/src/private_message.rs index be54b9b2..2484ebea 100644 --- a/server/lemmy_db/src/private_message.rs +++ b/server/lemmy_db/src/private_message.rs @@ -1,8 +1,7 @@ use crate::{naive_now, schema::private_message, Crud}; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "private_message"] pub struct PrivateMessage { pub id: i32, @@ -17,7 +16,7 @@ pub struct PrivateMessage { pub local: bool, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset)] #[table_name = "private_message"] pub struct PrivateMessageForm { pub creator_id: i32, diff --git a/server/lemmy_db/src/private_message_view.rs b/server/lemmy_db/src/private_message_view.rs index c9b4249b..39fe66ef 100644 --- a/server/lemmy_db/src/private_message_view.rs +++ b/server/lemmy_db/src/private_message_view.rs @@ -1,6 +1,6 @@ use crate::{limit_and_offset, MaybeOptional}; use diesel::{pg::Pg, result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; // The faked schema since diesel doesn't do views table! { @@ -29,7 +29,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "private_message_view"] pub struct PrivateMessageView { diff --git a/server/lemmy_db/src/site.rs b/server/lemmy_db/src/site.rs index 36b3e833..5e68fead 100644 --- a/server/lemmy_db/src/site.rs +++ b/server/lemmy_db/src/site.rs @@ -1,8 +1,7 @@ use crate::{naive_now, schema::site, Crud}; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "site"] pub struct Site { pub id: i32, @@ -18,7 +17,7 @@ pub struct Site { pub banner: Option, } -#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] +#[derive(Insertable, AsChangeset)] #[table_name = "site"] pub struct SiteForm { pub name: String, diff --git a/server/lemmy_db/src/site_view.rs b/server/lemmy_db/src/site_view.rs index 75cb29cb..0edfd2b7 100644 --- a/server/lemmy_db/src/site_view.rs +++ b/server/lemmy_db/src/site_view.rs @@ -1,5 +1,5 @@ use diesel::{result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; table! { site_view (id) { @@ -25,7 +25,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "site_view"] pub struct SiteView { diff --git a/server/lemmy_db/src/user.rs b/server/lemmy_db/src/user.rs index 0a39bdb2..247b5b36 100644 --- a/server/lemmy_db/src/user.rs +++ b/server/lemmy_db/src/user.rs @@ -6,9 +6,9 @@ use crate::{ }; use bcrypt::{hash, DEFAULT_COST}; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; -#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] #[table_name = "user_"] pub struct User_ { pub id: i32, @@ -38,7 +38,7 @@ pub struct User_ { pub banner: Option, } -#[derive(Insertable, AsChangeset, Clone, Debug)] +#[derive(Insertable, AsChangeset, Clone)] #[table_name = "user_"] pub struct UserForm { pub name: String, diff --git a/server/lemmy_db/src/user_mention.rs b/server/lemmy_db/src/user_mention.rs index a5985223..bcb3a143 100644 --- a/server/lemmy_db/src/user_mention.rs +++ b/server/lemmy_db/src/user_mention.rs @@ -1,9 +1,8 @@ use super::comment::Comment; use crate::{schema::user_mention, Crud}; use diesel::{dsl::*, result::Error, *}; -use serde::{Deserialize, Serialize}; -#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Queryable, Associations, Identifiable, PartialEq, Debug)] #[belongs_to(Comment)] #[table_name = "user_mention"] pub struct UserMention { @@ -14,7 +13,7 @@ pub struct UserMention { pub published: chrono::NaiveDateTime, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset)] #[table_name = "user_mention"] pub struct UserMentionForm { pub recipient_id: i32, diff --git a/server/lemmy_db/src/user_mention_view.rs b/server/lemmy_db/src/user_mention_view.rs index f74adc31..c35ad361 100644 --- a/server/lemmy_db/src/user_mention_view.rs +++ b/server/lemmy_db/src/user_mention_view.rs @@ -1,6 +1,6 @@ use crate::{limit_and_offset, MaybeOptional, SortType}; use diesel::{dsl::*, pg::Pg, result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; // The faked schema since diesel doesn't do views table! { @@ -84,7 +84,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "user_mention_fast_view"] pub struct UserMentionView { diff --git a/server/lemmy_db/src/user_view.rs b/server/lemmy_db/src/user_view.rs index 09a17aee..a4f6f47a 100644 --- a/server/lemmy_db/src/user_view.rs +++ b/server/lemmy_db/src/user_view.rs @@ -1,7 +1,7 @@ use super::user_view::user_fast::BoxedQuery; use crate::{fuzzy_search, limit_and_offset, MaybeOptional, SortType}; use diesel::{dsl::*, pg::Pg, result::Error, *}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; table! { user_view (id) { @@ -52,7 +52,7 @@ table! { } #[derive( - Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, + Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone, )] #[table_name = "user_fast"] pub struct UserView { diff --git a/server/lemmy_rate_limit/Cargo.toml b/server/lemmy_rate_limit/Cargo.toml index 001297fc..949f72f9 100644 --- a/server/lemmy_rate_limit/Cargo.toml +++ b/server/lemmy_rate_limit/Cargo.toml @@ -10,7 +10,6 @@ path = "src/lib.rs" [dependencies] lemmy_utils = { path = "../lemmy_utils" } -lemmy_api_structs = { path = "../lemmy_api_structs" } tokio = "0.2.21" strum = "0.18.0" strum_macros = "0.18.0" diff --git a/server/lemmy_rate_limit/src/lib.rs b/server/lemmy_rate_limit/src/lib.rs index 2d3553f0..260f7e2c 100644 --- a/server/lemmy_rate_limit/src/lib.rs +++ b/server/lemmy_rate_limit/src/lib.rs @@ -1,9 +1,9 @@ #[macro_use] -pub extern crate strum_macros; -pub extern crate actix_web; -pub extern crate futures; -pub extern crate log; -pub extern crate tokio; +extern crate strum_macros; +extern crate actix_web; +extern crate futures; +extern crate log; +extern crate tokio; use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; use futures::future::{ok, Ready}; diff --git a/server/lemmy_rate_limit/src/rate_limiter.rs b/server/lemmy_rate_limit/src/rate_limiter.rs index b4854729..1c355acf 100644 --- a/server/lemmy_rate_limit/src/rate_limiter.rs +++ b/server/lemmy_rate_limit/src/rate_limiter.rs @@ -1,5 +1,4 @@ -use lemmy_api_structs::APIError; -use lemmy_utils::{IPAddr, LemmyError}; +use lemmy_utils::{APIError, IPAddr, LemmyError}; use log::debug; use std::{collections::HashMap, time::SystemTime}; use strum::IntoEnumIterator; diff --git a/server/lemmy_utils/Cargo.toml b/server/lemmy_utils/Cargo.toml index d0806e29..a852cb85 100644 --- a/server/lemmy_utils/Cargo.toml +++ b/server/lemmy_utils/Cargo.toml @@ -20,6 +20,7 @@ itertools = "0.9.0" rand = "0.7.3" serde = { version = "1.0.105", features = ["derive"] } serde_json = { version = "1.0.52", features = ["preserve_order"]} +thiserror = "1.0.20" comrak = "0.7" lazy_static = "1.3.0" openssl = "0.10" diff --git a/server/lemmy_utils/src/lib.rs b/server/lemmy_utils/src/lib.rs index 20509343..d2821828 100644 --- a/server/lemmy_utils/src/lib.rs +++ b/server/lemmy_utils/src/lib.rs @@ -1,15 +1,16 @@ #[macro_use] -pub extern crate lazy_static; -pub extern crate actix_web; -pub extern crate anyhow; -pub extern crate comrak; -pub extern crate lettre; -pub extern crate lettre_email; -pub extern crate openssl; -pub extern crate rand; -pub extern crate regex; -pub extern crate serde_json; -pub extern crate url; +extern crate lazy_static; +extern crate actix_web; +extern crate anyhow; +extern crate comrak; +extern crate lettre; +extern crate lettre_email; +extern crate openssl; +extern crate rand; +extern crate regex; +extern crate serde_json; +extern crate thiserror; +extern crate url; pub mod settings; @@ -32,6 +33,7 @@ use openssl::{pkey::PKey, rsa::Rsa}; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use regex::{Regex, RegexBuilder}; use std::io::{Error, ErrorKind}; +use thiserror::Error; use url::Url; pub type ConnectionId = usize; @@ -52,6 +54,20 @@ macro_rules! location_info { }; } +#[derive(Debug, Error)] +#[error("{{\"error\":\"{message}\"}}")] +pub struct APIError { + pub message: String, +} + +impl APIError { + pub fn err(msg: &str) -> Self { + APIError { + message: msg.to_string(), + } + } +} + #[derive(Debug)] pub struct LemmyError { inner: anyhow::Error, diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index 9ad52108..f0e56810 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -17,7 +17,7 @@ use crate::{ LemmyContext, }; use actix_web::web::Data; -use lemmy_api_structs::{comment::*, APIError}; +use lemmy_api_structs::comment::*; use lemmy_db::{ comment::*, comment_view::*, @@ -38,6 +38,7 @@ use lemmy_utils::{ scrape_text_for_mentions, send_email, settings::Settings, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 17eb1c5c..6fb67b33 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -18,7 +18,7 @@ use crate::{ }; use actix_web::web::Data; use anyhow::Context; -use lemmy_api_structs::{community::*, APIError}; +use lemmy_api_structs::community::*; use lemmy_db::{ comment::Comment, comment_view::CommentQueryBuilder, @@ -42,6 +42,7 @@ use lemmy_utils::{ location_info, make_apub_endpoint, naive_from_unix, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index 03a585f7..a1b8c188 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -1,6 +1,5 @@ use crate::{api::claims::Claims, blocking, DbPool, LemmyContext}; use actix_web::web::Data; -use lemmy_api_structs::APIError; use lemmy_db::{ community::Community, community_view::CommunityUserBanView, @@ -8,7 +7,7 @@ use lemmy_db::{ user::User_, Crud, }; -use lemmy_utils::{slur_check, slurs_vec_to_str, ConnectionId, LemmyError}; +use lemmy_utils::{slur_check, slurs_vec_to_str, APIError, ConnectionId, LemmyError}; pub mod claims; pub mod comment; diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 0eeaae43..9e1e97d5 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -18,7 +18,7 @@ use crate::{ LemmyContext, }; use actix_web::web::Data; -use lemmy_api_structs::{post::*, APIError}; +use lemmy_api_structs::post::*; use lemmy_db::{ comment_view::*, community_view::*, @@ -36,6 +36,7 @@ use lemmy_db::{ use lemmy_utils::{ is_valid_post_title, make_apub_endpoint, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/api/site.rs b/server/src/api/site.rs index abc4161e..8bcc4b77 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -18,7 +18,7 @@ use crate::{ }; use actix_web::web::Data; use anyhow::Context; -use lemmy_api_structs::{site::*, user::Register, APIError}; +use lemmy_api_structs::{site::*, user::Register}; use lemmy_db::{ category::*, comment_view::*, @@ -35,7 +35,7 @@ use lemmy_db::{ SearchType, SortType, }; -use lemmy_utils::{location_info, settings::Settings, ConnectionId, LemmyError}; +use lemmy_utils::{location_info, settings::Settings, APIError, ConnectionId, LemmyError}; use log::{debug, info}; use std::str::FromStr; diff --git a/server/src/api/user.rs b/server/src/api/user.rs index a40f296e..1a71b3aa 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -14,7 +14,7 @@ use anyhow::Context; use bcrypt::verify; use captcha::{gen, Difficulty}; use chrono::Duration; -use lemmy_api_structs::{user::*, APIError}; +use lemmy_api_structs::user::*; use lemmy_db::{ comment::*, comment_view::*, @@ -51,6 +51,7 @@ use lemmy_utils::{ remove_slurs, send_email, settings::Settings, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/lib.rs b/server/src/lib.rs index 380dc445..d811d908 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1,25 +1,25 @@ #![recursion_limit = "512"] #[macro_use] -pub extern crate strum_macros; +extern crate strum_macros; #[macro_use] -pub extern crate lazy_static; -pub extern crate actix; -pub extern crate actix_web; -pub extern crate base64; -pub extern crate bcrypt; -pub extern crate captcha; -pub extern crate chrono; -pub extern crate diesel; -pub extern crate dotenv; -pub extern crate jsonwebtoken; +extern crate lazy_static; +extern crate actix; +extern crate actix_web; +extern crate base64; +extern crate bcrypt; +extern crate captcha; +extern crate chrono; +extern crate diesel; +extern crate dotenv; +extern crate jsonwebtoken; extern crate log; -pub extern crate openssl; -pub extern crate reqwest; -pub extern crate rss; -pub extern crate serde; -pub extern crate serde_json; -pub extern crate sha2; -pub extern crate strum; +extern crate openssl; +extern crate reqwest; +extern crate rss; +extern crate serde; +extern crate serde_json; +extern crate sha2; +extern crate strum; pub mod api; pub mod apub; diff --git a/server/src/main.rs b/server/src/main.rs index 48549e46..92619b7c 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,7 +1,5 @@ #[macro_use] extern crate diesel_migrations; -#[macro_use] -pub extern crate lazy_static; use actix::prelude::*; use actix_web::{ @@ -17,6 +15,7 @@ use diesel::{ r2d2::{ConnectionManager, Pool}, PgConnection, }; +use lazy_static::lazy_static; use lemmy_db::get_database_url_from_env; use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit}; use lemmy_server::{ diff --git a/server/src/routes/api.rs b/server/src/routes/api.rs index 6a715f47..dd727df9 100644 --- a/server/src/routes/api.rs +++ b/server/src/routes/api.rs @@ -2,7 +2,7 @@ use crate::{api::Perform, LemmyContext}; use actix_web::{error::ErrorBadRequest, *}; use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*}; use lemmy_rate_limit::RateLimit; -use serde::Serialize; +use serde::Deserialize; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { cfg.service( @@ -187,22 +187,22 @@ where Ok(res) } -async fn route_get( +async fn route_get<'a, Data>( data: web::Query, context: web::Data, ) -> Result where - Data: Serialize + Send + 'static + Perform, + Data: Deserialize<'a> + Send + 'static + Perform, { perform::(data.0, context).await } -async fn route_post( +async fn route_post<'a, Data>( data: web::Json, context: web::Data, ) -> Result where - Data: Serialize + Send + 'static + Perform, + Data: Deserialize<'a> + Send + 'static + Perform, { perform::(data.0, context).await } diff --git a/server/src/websocket/chat_server.rs b/server/src/websocket/chat_server.rs index cb73b464..b8066eec 100644 --- a/server/src/websocket/chat_server.rs +++ b/server/src/websocket/chat_server.rs @@ -13,9 +13,18 @@ use diesel::{ r2d2::{ConnectionManager, Pool}, PgConnection, }; -use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*, APIError}; +use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*}; use lemmy_rate_limit::RateLimit; -use lemmy_utils::{location_info, CommunityId, ConnectionId, IPAddr, LemmyError, PostId, UserId}; +use lemmy_utils::{ + location_info, + APIError, + CommunityId, + ConnectionId, + IPAddr, + LemmyError, + PostId, + UserId, +}; use rand::rngs::ThreadRng; use reqwest::Client; use serde::Serialize;