]> Untitled Git - lemmy.git/commitdiff
Move api structs and rate limit into separate workspaces
authorFelix Ableitner <me@nutomic.com>
Tue, 1 Sep 2020 14:25:34 +0000 (16:25 +0200)
committerFelix Ableitner <me@nutomic.com>
Wed, 2 Sep 2020 11:27:31 +0000 (13:27 +0200)
55 files changed:
server/Cargo.lock
server/Cargo.toml
server/lemmy_api_structs/Cargo.toml [new file with mode: 0644]
server/lemmy_api_structs/src/comment.rs [new file with mode: 0644]
server/lemmy_api_structs/src/community.rs [new file with mode: 0644]
server/lemmy_api_structs/src/lib.rs [new file with mode: 0644]
server/lemmy_api_structs/src/post.rs [new file with mode: 0644]
server/lemmy_api_structs/src/site.rs [new file with mode: 0644]
server/lemmy_api_structs/src/user.rs [new file with mode: 0644]
server/lemmy_rate_limit/Cargo.toml [new file with mode: 0644]
server/lemmy_rate_limit/src/lib.rs [moved from server/src/rate_limit/mod.rs with 96% similarity]
server/lemmy_rate_limit/src/rate_limiter.rs [moved from server/src/rate_limit/rate_limiter.rs with 94% similarity]
server/lemmy_utils/Cargo.toml
server/lemmy_utils/src/lib.rs
server/src/api/comment.rs
server/src/api/community.rs
server/src/api/mod.rs
server/src/api/post.rs
server/src/api/site.rs
server/src/api/user.rs
server/src/apub/activities.rs
server/src/apub/activity_queue.rs
server/src/apub/comment.rs
server/src/apub/community.rs
server/src/apub/extensions/group_extensions.rs
server/src/apub/extensions/signatures.rs
server/src/apub/fetcher.rs
server/src/apub/inbox/activities/announce.rs
server/src/apub/inbox/activities/create.rs
server/src/apub/inbox/activities/delete.rs
server/src/apub/inbox/activities/dislike.rs
server/src/apub/inbox/activities/like.rs
server/src/apub/inbox/activities/remove.rs
server/src/apub/inbox/activities/undo.rs
server/src/apub/inbox/activities/update.rs
server/src/apub/inbox/community_inbox.rs
server/src/apub/inbox/shared_inbox.rs
server/src/apub/inbox/user_inbox.rs
server/src/apub/mod.rs
server/src/apub/post.rs
server/src/apub/private_message.rs
server/src/apub/user.rs
server/src/code_migrations.rs
server/src/lib.rs
server/src/main.rs
server/src/request.rs
server/src/routes/api.rs
server/src/routes/feeds.rs
server/src/routes/images.rs
server/src/routes/nodeinfo.rs
server/src/routes/webfinger.rs
server/src/routes/websocket.rs
server/src/websocket/chat_server.rs
server/src/websocket/handlers.rs
server/src/websocket/messages.rs

index 815ebc0a81bd107c961b8eb96a4a5f33909f4573..305af342b75edc2e3c172d8746c0ebd23569130f 100644 (file)
@@ -1794,6 +1794,15 @@ version = "1.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
 
+[[package]]
+name = "lemmy_api_structs"
+version = "0.1.0"
+dependencies = [
+ "lemmy_db",
+ "serde 1.0.114",
+ "thiserror",
+]
+
 [[package]]
 name = "lemmy_db"
 version = "0.1.0"
@@ -1812,6 +1821,20 @@ dependencies = [
  "url",
 ]
 
+[[package]]
+name = "lemmy_rate_limit"
+version = "0.1.0"
+dependencies = [
+ "actix-web",
+ "futures",
+ "lemmy_api_structs",
+ "lemmy_utils",
+ "log",
+ "strum",
+ "strum_macros",
+ "tokio",
+]
+
 [[package]]
 name = "lemmy_server"
 version = "0.0.1"
@@ -1841,7 +1864,9 @@ dependencies = [
  "itertools",
  "jsonwebtoken",
  "lazy_static",
+ "lemmy_api_structs",
  "lemmy_db",
+ "lemmy_rate_limit",
  "lemmy_utils",
  "log",
  "openssl",
@@ -1864,6 +1889,8 @@ dependencies = [
 name = "lemmy_utils"
 version = "0.1.0"
 dependencies = [
+ "actix-web",
+ "anyhow",
  "chrono",
  "comrak",
  "config",
index c5bf9c888cbd9e407b96758d54a7435b569d4d4e..912d130d42bee929916f83e9ce808aaa4f7ef08a 100644 (file)
@@ -9,12 +9,15 @@ lto = true
 [workspace]
 members = [
     "lemmy_utils",
-    "lemmy_db"
+    "lemmy_db",
+    "lemmy_api_structs",
 ]
 
 [dependencies]
 lemmy_utils = { path = "./lemmy_utils" }
 lemmy_db = { path = "./lemmy_db" }
+lemmy_api_structs = { path = "./lemmy_api_structs" }
+lemmy_rate_limit = { path = "./lemmy_rate_limit" }
 diesel = "1.4.4"
 diesel_migrations = "1.4.0"
 dotenv = "0.15.0"
diff --git a/server/lemmy_api_structs/Cargo.toml b/server/lemmy_api_structs/Cargo.toml
new file mode 100644 (file)
index 0000000..d1695ec
--- /dev/null
@@ -0,0 +1,10 @@
+[package]
+name = "lemmy_api_structs"
+version = "0.1.0"
+authors = ["Felix Ableitner <me@nutomic.com>"]
+edition = "2018"
+
+[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
new file mode 100644 (file)
index 0000000..8dbefff
--- /dev/null
@@ -0,0 +1,77 @@
+use lemmy_db::comment_view::CommentView;
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize)]
+pub struct CreateComment {
+  pub content: String,
+  pub parent_id: Option<i32>,
+  pub post_id: i32,
+  pub form_id: Option<String>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct EditComment {
+  pub content: String,
+  pub edit_id: i32,
+  pub form_id: Option<String>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct DeleteComment {
+  pub edit_id: i32,
+  pub deleted: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct RemoveComment {
+  pub edit_id: i32,
+  pub removed: bool,
+  pub reason: Option<String>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct MarkCommentAsRead {
+  pub edit_id: i32,
+  pub read: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct SaveComment {
+  pub comment_id: i32,
+  pub save: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct CommentResponse {
+  pub comment: CommentView,
+  pub recipient_ids: Vec<i32>,
+  pub form_id: Option<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct CreateCommentLike {
+  pub comment_id: i32,
+  pub score: i16,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetComments {
+  pub type_: String,
+  pub sort: String,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub community_id: Option<i32>,
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetCommentsResponse {
+  pub comments: Vec<CommentView>,
+}
diff --git a/server/lemmy_api_structs/src/community.rs b/server/lemmy_api_structs/src/community.rs
new file mode 100644 (file)
index 0000000..8d07360
--- /dev/null
@@ -0,0 +1,131 @@
+use lemmy_db::{
+  community_view::{CommunityFollowerView, CommunityModeratorView, CommunityView},
+  user_view::UserView,
+};
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize)]
+pub struct GetCommunity {
+  pub id: Option<i32>,
+  pub name: Option<String>,
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetCommunityResponse {
+  pub community: CommunityView,
+  pub moderators: Vec<CommunityModeratorView>,
+  pub online: usize,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct CreateCommunity {
+  pub name: String,
+  pub title: String,
+  pub description: Option<String>,
+  pub icon: Option<String>,
+  pub banner: Option<String>,
+  pub category_id: i32,
+  pub nsfw: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct CommunityResponse {
+  pub community: CommunityView,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ListCommunities {
+  pub sort: String,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ListCommunitiesResponse {
+  pub communities: Vec<CommunityView>,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct BanFromCommunity {
+  pub community_id: i32,
+  pub user_id: i32,
+  pub ban: bool,
+  pub remove_data: Option<bool>,
+  pub reason: Option<String>,
+  pub expires: Option<i64>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct BanFromCommunityResponse {
+  pub user: UserView,
+  pub banned: bool,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct AddModToCommunity {
+  pub community_id: i32,
+  pub user_id: i32,
+  pub added: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct AddModToCommunityResponse {
+  pub moderators: Vec<CommunityModeratorView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct EditCommunity {
+  pub edit_id: i32,
+  pub title: String,
+  pub description: Option<String>,
+  pub icon: Option<String>,
+  pub banner: Option<String>,
+  pub category_id: i32,
+  pub nsfw: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct DeleteCommunity {
+  pub edit_id: i32,
+  pub deleted: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct RemoveCommunity {
+  pub edit_id: i32,
+  pub removed: bool,
+  pub reason: Option<String>,
+  pub expires: Option<i64>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct FollowCommunity {
+  pub community_id: i32,
+  pub follow: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetFollowedCommunities {
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetFollowedCommunitiesResponse {
+  pub communities: Vec<CommunityFollowerView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct TransferCommunity {
+  pub community_id: i32,
+  pub user_id: i32,
+  pub auth: String,
+}
diff --git a/server/lemmy_api_structs/src/lib.rs b/server/lemmy_api_structs/src/lib.rs
new file mode 100644 (file)
index 0000000..df58304
--- /dev/null
@@ -0,0 +1,24 @@
+pub extern crate serde;
+pub extern crate thiserror;
+
+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
new file mode 100644 (file)
index 0000000..5860b2b
--- /dev/null
@@ -0,0 +1,105 @@
+use lemmy_db::{
+  comment_view::CommentView,
+  community_view::{CommunityModeratorView, CommunityView},
+  post_view::PostView,
+};
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct CreatePost {
+  pub name: String,
+  pub url: Option<String>,
+  pub body: Option<String>,
+  pub nsfw: bool,
+  pub community_id: i32,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct PostResponse {
+  pub post: PostView,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetPost {
+  pub id: i32,
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetPostResponse {
+  pub post: PostView,
+  pub comments: Vec<CommentView>,
+  pub community: CommunityView,
+  pub moderators: Vec<CommunityModeratorView>,
+  pub online: usize,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct GetPosts {
+  pub type_: String,
+  pub sort: String,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub community_id: Option<i32>,
+  pub community_name: Option<String>,
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct GetPostsResponse {
+  pub posts: Vec<PostView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct CreatePostLike {
+  pub post_id: i32,
+  pub score: i16,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct EditPost {
+  pub edit_id: i32,
+  pub name: String,
+  pub url: Option<String>,
+  pub body: Option<String>,
+  pub nsfw: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct DeletePost {
+  pub edit_id: i32,
+  pub deleted: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct RemovePost {
+  pub edit_id: i32,
+  pub removed: bool,
+  pub reason: Option<String>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct LockPost {
+  pub edit_id: i32,
+  pub locked: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct StickyPost {
+  pub edit_id: i32,
+  pub stickied: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct SavePost {
+  pub post_id: i32,
+  pub save: bool,
+  pub auth: String,
+}
diff --git a/server/lemmy_api_structs/src/site.rs b/server/lemmy_api_structs/src/site.rs
new file mode 100644 (file)
index 0000000..7766a5f
--- /dev/null
@@ -0,0 +1,127 @@
+use lemmy_db::{
+  category::*,
+  comment_view::*,
+  community_view::*,
+  moderator_views::*,
+  post_view::*,
+  site_view::*,
+  user::*,
+  user_view::*,
+};
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize)]
+pub struct ListCategories {}
+
+#[derive(Serialize, Deserialize)]
+pub struct ListCategoriesResponse {
+  pub categories: Vec<Category>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct Search {
+  pub q: String,
+  pub type_: String,
+  pub community_id: Option<i32>,
+  pub sort: String,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct SearchResponse {
+  pub type_: String,
+  pub comments: Vec<CommentView>,
+  pub posts: Vec<PostView>,
+  pub communities: Vec<CommunityView>,
+  pub users: Vec<UserView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetModlog {
+  pub mod_user_id: Option<i32>,
+  pub community_id: Option<i32>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetModlogResponse {
+  pub removed_posts: Vec<ModRemovePostView>,
+  pub locked_posts: Vec<ModLockPostView>,
+  pub stickied_posts: Vec<ModStickyPostView>,
+  pub removed_comments: Vec<ModRemoveCommentView>,
+  pub removed_communities: Vec<ModRemoveCommunityView>,
+  pub banned_from_community: Vec<ModBanFromCommunityView>,
+  pub banned: Vec<ModBanView>,
+  pub added_to_community: Vec<ModAddCommunityView>,
+  pub added: Vec<ModAddView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct CreateSite {
+  pub name: String,
+  pub description: Option<String>,
+  pub icon: Option<String>,
+  pub banner: Option<String>,
+  pub enable_downvotes: bool,
+  pub open_registration: bool,
+  pub enable_nsfw: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct EditSite {
+  pub name: String,
+  pub description: Option<String>,
+  pub icon: Option<String>,
+  pub banner: Option<String>,
+  pub enable_downvotes: bool,
+  pub open_registration: bool,
+  pub enable_nsfw: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetSite {
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct SiteResponse {
+  pub site: SiteView,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetSiteResponse {
+  pub site: Option<SiteView>,
+  pub admins: Vec<UserView>,
+  pub banned: Vec<UserView>,
+  pub online: usize,
+  pub version: String,
+  pub my_user: Option<User_>,
+  pub federated_instances: Vec<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct TransferSite {
+  pub user_id: i32,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetSiteConfig {
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetSiteConfigResponse {
+  pub config_hjson: String,
+}
+
+#[derive(Serialize, 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
new file mode 100644 (file)
index 0000000..5954e2b
--- /dev/null
@@ -0,0 +1,239 @@
+use lemmy_db::{
+  comment_view::{CommentView, ReplyView},
+  community_view::{CommunityFollowerView, CommunityModeratorView},
+  post_view::PostView,
+  private_message_view::PrivateMessageView,
+  user_mention_view::UserMentionView,
+  user_view::UserView,
+};
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct Login {
+  pub username_or_email: String,
+  pub password: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Register {
+  pub username: String,
+  pub email: Option<String>,
+  pub password: String,
+  pub password_verify: String,
+  pub admin: bool,
+  pub show_nsfw: bool,
+  pub captcha_uuid: Option<String>,
+  pub captcha_answer: Option<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetCaptcha {}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetCaptchaResponse {
+  pub ok: Option<CaptchaResponse>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct CaptchaResponse {
+  pub png: String,         // A Base64 encoded png
+  pub wav: Option<String>, // A Base64 encoded wav audio
+  pub uuid: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct SaveUserSettings {
+  pub show_nsfw: bool,
+  pub theme: String,
+  pub default_sort_type: i16,
+  pub default_listing_type: i16,
+  pub lang: String,
+  pub avatar: Option<String>,
+  pub banner: Option<String>,
+  pub preferred_username: Option<String>,
+  pub email: Option<String>,
+  pub bio: Option<String>,
+  pub matrix_user_id: Option<String>,
+  pub new_password: Option<String>,
+  pub new_password_verify: Option<String>,
+  pub old_password: Option<String>,
+  pub show_avatars: bool,
+  pub send_notifications_to_email: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct LoginResponse {
+  pub jwt: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetUserDetails {
+  pub user_id: Option<i32>,
+  pub username: Option<String>,
+  pub sort: String,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub community_id: Option<i32>,
+  pub saved_only: bool,
+  pub auth: Option<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetUserDetailsResponse {
+  pub user: UserView,
+  pub follows: Vec<CommunityFollowerView>,
+  pub moderates: Vec<CommunityModeratorView>,
+  pub comments: Vec<CommentView>,
+  pub posts: Vec<PostView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetRepliesResponse {
+  pub replies: Vec<ReplyView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetUserMentionsResponse {
+  pub mentions: Vec<UserMentionView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct MarkAllAsRead {
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct AddAdmin {
+  pub user_id: i32,
+  pub added: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct AddAdminResponse {
+  pub admins: Vec<UserView>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct BanUser {
+  pub user_id: i32,
+  pub ban: bool,
+  pub remove_data: Option<bool>,
+  pub reason: Option<String>,
+  pub expires: Option<i64>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct BanUserResponse {
+  pub user: UserView,
+  pub banned: bool,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetReplies {
+  pub sort: String,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub unread_only: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetUserMentions {
+  pub sort: String,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub unread_only: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct MarkUserMentionAsRead {
+  pub user_mention_id: i32,
+  pub read: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct UserMentionResponse {
+  pub mention: UserMentionView,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct DeleteAccount {
+  pub password: String,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct PasswordReset {
+  pub email: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct PasswordResetResponse {}
+
+#[derive(Serialize, Deserialize)]
+pub struct PasswordChange {
+  pub token: String,
+  pub password: String,
+  pub password_verify: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct CreatePrivateMessage {
+  pub content: String,
+  pub recipient_id: i32,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct EditPrivateMessage {
+  pub edit_id: i32,
+  pub content: String,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct DeletePrivateMessage {
+  pub edit_id: i32,
+  pub deleted: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct MarkPrivateMessageAsRead {
+  pub edit_id: i32,
+  pub read: bool,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct GetPrivateMessages {
+  pub unread_only: bool,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct PrivateMessagesResponse {
+  pub messages: Vec<PrivateMessageView>,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct PrivateMessageResponse {
+  pub message: PrivateMessageView,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct UserJoin {
+  pub auth: String,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct UserJoinResponse {
+  pub user_id: i32,
+}
diff --git a/server/lemmy_rate_limit/Cargo.toml b/server/lemmy_rate_limit/Cargo.toml
new file mode 100644 (file)
index 0000000..4fc6525
--- /dev/null
@@ -0,0 +1,15 @@
+[package]
+name = "lemmy_rate_limit"
+version = "0.1.0"
+authors = ["Felix Ableitner <me@nutomic.com>"]
+edition = "2018"
+
+[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"
+futures = "0.3.5"
+actix-web = { version = "3.0.0-alpha.3", features = ["rustls"] }
+log = "0.4.0"
similarity index 96%
rename from server/src/rate_limit/mod.rs
rename to server/lemmy_rate_limit/src/lib.rs
index 39df726505c02ea03915120747604c003b506f3c..431a2d7602a5fdd33a6f0d5990fc341f5c6a4b6a 100644 (file)
@@ -1,5 +1,10 @@
-use super::IPAddr;
-use crate::{get_ip, LemmyError};
+#[macro_use]
+pub extern crate strum_macros;
+pub extern crate tokio;
+pub extern crate futures;
+pub extern crate actix_web;
+pub extern crate log;
+
 use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
 use futures::future::{ok, Ready};
 use lemmy_utils::settings::{RateLimitConfig, Settings};
@@ -11,6 +16,8 @@ use std::{
   task::{Context, Poll},
 };
 use tokio::sync::Mutex;
+use lemmy_utils::get_ip;
+use lemmy_utils::LemmyError;
 
 pub mod rate_limiter;
 
similarity index 94%
rename from server/src/rate_limit/rate_limiter.rs
rename to server/lemmy_rate_limit/src/rate_limiter.rs
index f1a38841244c4a5c429a03945825a5dcdfb4ed4e..1c90f90e09905bdc148882037aff9bb5f722ba07 100644 (file)
@@ -1,5 +1,6 @@
-use super::IPAddr;
-use crate::{api::APIError, LemmyError};
+use lemmy_utils::IPAddr;
+use lemmy_utils::LemmyError;
+use lemmy_api_structs::APIError;
 use log::debug;
 use std::{collections::HashMap, time::SystemTime};
 use strum::IntoEnumIterator;
@@ -27,7 +28,7 @@ pub struct RateLimiter {
 impl Default for RateLimiter {
   fn default() -> Self {
     Self {
-      buckets: HashMap::new(),
+      buckets: HashMap::<RateLimitType, HashMap<IPAddr, RateLimitBucket>>::new(),
     }
   }
 }
index 9685c0edaafef7b0017fab6ed4a196b706ad5618..c6ab744bc1942e49ddb9596c5ebbee68927c3ba3 100644 (file)
@@ -20,3 +20,5 @@ comrak = "0.7"
 lazy_static = "1.3.0"
 openssl = "0.10"
 url = { version = "2.1.1", features = ["serde"] }
+actix-web = "3.0.0-alpha.3"
+anyhow = "1.0.32"
index 41cdcec8e3b842706b3a4f72caac355561d28e29..97f32f27f8504535110dfb542669c0c4ef9c315d 100644 (file)
@@ -8,6 +8,8 @@ pub extern crate rand;
 pub extern crate regex;
 pub extern crate serde_json;
 pub extern crate url;
+pub extern crate actix_web;
+pub extern crate anyhow;
 
 pub mod settings;
 
@@ -30,6 +32,13 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
 use regex::{Regex, RegexBuilder};
 use std::io::{Error, ErrorKind};
 use url::Url;
+use actix_web::dev::ConnectionInfo;
+
+pub type ConnectionId = usize;
+pub type PostId = i32;
+pub type CommunityId = i32;
+pub type UserId = i32;
+pub type IPAddr = String;
 
 #[macro_export]
 macro_rules! location_info {
@@ -43,6 +52,28 @@ macro_rules! location_info {
   };
 }
 
+#[derive(Debug)]
+pub struct LemmyError {
+  inner: anyhow::Error,
+}
+
+impl<T> From<T> for LemmyError
+  where
+    T: Into<anyhow::Error>,
+{
+  fn from(t: T) -> Self {
+    LemmyError { inner: t.into() }
+  }
+}
+
+impl std::fmt::Display for LemmyError {
+  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+    self.inner.fmt(f)
+  }
+}
+
+impl actix_web::error::ResponseError for LemmyError {}
+
 pub fn naive_from_unix(time: i64) -> NaiveDateTime {
   NaiveDateTime::from_timestamp(time, 0)
 }
@@ -346,3 +377,13 @@ pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
   ))
   .unwrap()
 }
+
+pub fn get_ip(conn_info: &ConnectionInfo) -> String {
+  conn_info
+    .realip_remote_addr()
+    .unwrap_or("127.0.0.1:12345")
+    .split(':')
+    .next()
+    .unwrap_or("127.0.0.1")
+    .to_string()
+}
\ No newline at end of file
index 0d250a7b2d2e65dd10da096237e91e6ff1977e21..9ad52108b2e99ab7a8b04c03677368e18084ee0d 100644 (file)
@@ -5,7 +5,6 @@ use crate::{
     get_user_from_jwt,
     get_user_from_jwt_opt,
     is_mod_or_admin,
-    APIError,
     Perform,
   },
   apub::{ApubLikeableType, ApubObjectType},
@@ -14,12 +13,11 @@ use crate::{
     messages::{JoinCommunityRoom, SendComment},
     UserOperation,
   },
-  ConnectionId,
   DbPool,
   LemmyContext,
-  LemmyError,
 };
 use actix_web::web::Data;
+use lemmy_api_structs::{comment::*, APIError};
 use lemmy_db::{
   comment::*,
   comment_view::*,
@@ -40,88 +38,14 @@ use lemmy_utils::{
   scrape_text_for_mentions,
   send_email,
   settings::Settings,
+  ConnectionId,
   EndpointType,
+  LemmyError,
   MentionData,
 };
 use log::error;
-use serde::{Deserialize, Serialize};
 use std::str::FromStr;
 
-#[derive(Serialize, Deserialize)]
-pub struct CreateComment {
-  content: String,
-  parent_id: Option<i32>,
-  pub post_id: i32,
-  form_id: Option<String>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct EditComment {
-  content: String,
-  edit_id: i32,
-  form_id: Option<String>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct DeleteComment {
-  edit_id: i32,
-  deleted: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct RemoveComment {
-  edit_id: i32,
-  removed: bool,
-  reason: Option<String>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct MarkCommentAsRead {
-  edit_id: i32,
-  read: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct SaveComment {
-  comment_id: i32,
-  save: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct CommentResponse {
-  pub comment: CommentView,
-  pub recipient_ids: Vec<i32>,
-  pub form_id: Option<String>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct CreateCommentLike {
-  comment_id: i32,
-  score: i16,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetComments {
-  type_: String,
-  sort: String,
-  page: Option<i64>,
-  limit: Option<i64>,
-  pub community_id: Option<i32>,
-  auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetCommentsResponse {
-  comments: Vec<CommentView>,
-}
-
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateComment {
   type Response = CommentResponse;
index 763a9114fbbc3c90500989648de2adec7599f1fb..17eb1c5c8ab8a6b66e8ec4fde3a951b337b1d6e4 100644 (file)
@@ -6,7 +6,6 @@ use crate::{
     get_user_from_jwt_opt,
     is_admin,
     is_mod_or_admin,
-    APIError,
     Perform,
   },
   apub::ActorType,
@@ -15,12 +14,11 @@ use crate::{
     messages::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
     UserOperation,
   },
-  ConnectionId,
   LemmyContext,
-  LemmyError,
 };
 use actix_web::web::Data;
 use anyhow::Context;
+use lemmy_api_structs::{community::*, APIError};
 use lemmy_db::{
   comment::Comment,
   comment_view::CommentQueryBuilder,
@@ -44,137 +42,12 @@ use lemmy_utils::{
   location_info,
   make_apub_endpoint,
   naive_from_unix,
+  ConnectionId,
   EndpointType,
+  LemmyError,
 };
-use serde::{Deserialize, Serialize};
 use std::str::FromStr;
 
-#[derive(Serialize, Deserialize)]
-pub struct GetCommunity {
-  id: Option<i32>,
-  pub name: Option<String>,
-  auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetCommunityResponse {
-  pub community: CommunityView,
-  pub moderators: Vec<CommunityModeratorView>,
-  pub online: usize,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct CreateCommunity {
-  name: String,
-  title: String,
-  description: Option<String>,
-  icon: Option<String>,
-  banner: Option<String>,
-  category_id: i32,
-  nsfw: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct CommunityResponse {
-  pub community: CommunityView,
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct ListCommunities {
-  pub sort: String,
-  pub page: Option<i64>,
-  pub limit: Option<i64>,
-  pub auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct ListCommunitiesResponse {
-  pub communities: Vec<CommunityView>,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct BanFromCommunity {
-  pub community_id: i32,
-  user_id: i32,
-  ban: bool,
-  remove_data: Option<bool>,
-  reason: Option<String>,
-  expires: Option<i64>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct BanFromCommunityResponse {
-  user: UserView,
-  banned: bool,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct AddModToCommunity {
-  pub community_id: i32,
-  user_id: i32,
-  added: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddModToCommunityResponse {
-  moderators: Vec<CommunityModeratorView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct EditCommunity {
-  pub edit_id: i32,
-  title: String,
-  description: Option<String>,
-  icon: Option<String>,
-  banner: Option<String>,
-  category_id: i32,
-  nsfw: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct DeleteCommunity {
-  pub edit_id: i32,
-  deleted: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct RemoveCommunity {
-  pub edit_id: i32,
-  removed: bool,
-  reason: Option<String>,
-  expires: Option<i64>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct FollowCommunity {
-  community_id: i32,
-  follow: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetFollowedCommunities {
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetFollowedCommunitiesResponse {
-  communities: Vec<CommunityFollowerView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct TransferCommunity {
-  community_id: i32,
-  user_id: i32,
-  auth: String,
-}
-
 #[async_trait::async_trait(?Send)]
 impl Perform for GetCommunity {
   type Response = GetCommunityResponse;
index 1b213d9f4d22098c365c1ddfa68a728e113eaf91..03a585f7fda7a0e2962745ec135f7838062b2436 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{api::claims::Claims, blocking, ConnectionId, DbPool, LemmyContext, LemmyError};
+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,
@@ -7,8 +8,7 @@ use lemmy_db::{
   user::User_,
   Crud,
 };
-use lemmy_utils::{slur_check, slurs_vec_to_str};
-use thiserror::Error;
+use lemmy_utils::{slur_check, slurs_vec_to_str, ConnectionId, LemmyError};
 
 pub mod claims;
 pub mod comment;
@@ -17,20 +17,6 @@ pub mod post;
 pub mod site;
 pub mod user;
 
-#[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(),
-    }
-  }
-}
-
 #[async_trait::async_trait(?Send)]
 pub trait Perform {
   type Response: serde::ser::Serialize + Send;
index 84842173e8d0c75cfde823d76b21f594c9b7b282..0eeaae43ed3d53bce5cc4634d618caf1236d4663 100644 (file)
@@ -6,7 +6,6 @@ use crate::{
     get_user_from_jwt,
     get_user_from_jwt_opt,
     is_mod_or_admin,
-    APIError,
     Perform,
   },
   apub::{ApubLikeableType, ApubObjectType},
@@ -16,11 +15,10 @@ use crate::{
     messages::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
     UserOperation,
   },
-  ConnectionId,
   LemmyContext,
-  LemmyError,
 };
 use actix_web::web::Data;
+use lemmy_api_structs::{post::*, APIError};
 use lemmy_db::{
   comment_view::*,
   community_view::*,
@@ -35,110 +33,16 @@ use lemmy_db::{
   Saveable,
   SortType,
 };
-use lemmy_utils::{is_valid_post_title, make_apub_endpoint, EndpointType};
-use serde::{Deserialize, Serialize};
+use lemmy_utils::{
+  is_valid_post_title,
+  make_apub_endpoint,
+  ConnectionId,
+  EndpointType,
+  LemmyError,
+};
 use std::str::FromStr;
 use url::Url;
 
-#[derive(Serialize, Deserialize, Debug)]
-pub struct CreatePost {
-  name: String,
-  url: Option<String>,
-  body: Option<String>,
-  nsfw: bool,
-  pub community_id: i32,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct PostResponse {
-  pub post: PostView,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetPost {
-  pub id: i32,
-  auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetPostResponse {
-  post: PostView,
-  comments: Vec<CommentView>,
-  community: CommunityView,
-  moderators: Vec<CommunityModeratorView>,
-  pub online: usize,
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct GetPosts {
-  type_: String,
-  sort: String,
-  page: Option<i64>,
-  limit: Option<i64>,
-  pub community_id: Option<i32>,
-  pub community_name: Option<String>,
-  auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct GetPostsResponse {
-  pub posts: Vec<PostView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct CreatePostLike {
-  post_id: i32,
-  score: i16,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct EditPost {
-  pub edit_id: i32,
-  name: String,
-  url: Option<String>,
-  body: Option<String>,
-  nsfw: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct DeletePost {
-  pub edit_id: i32,
-  deleted: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct RemovePost {
-  pub edit_id: i32,
-  removed: bool,
-  reason: Option<String>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct LockPost {
-  pub edit_id: i32,
-  locked: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct StickyPost {
-  pub edit_id: i32,
-  stickied: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct SavePost {
-  post_id: i32,
-  save: bool,
-  auth: String,
-}
-
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePost {
   type Response = PostResponse;
index 2ea4a390c83197bb82be14c372dcaca0d09eda9c..abc4161e74751c7701a2fcbe95bc9811df77084f 100644 (file)
@@ -1,4 +1,3 @@
-use super::user::Register;
 use crate::{
   api::{
     check_slurs,
@@ -6,7 +5,6 @@ use crate::{
     get_user_from_jwt,
     get_user_from_jwt_opt,
     is_admin,
-    APIError,
     Perform,
   },
   apub::fetcher::search_by_apub_id,
@@ -16,12 +14,11 @@ use crate::{
     messages::{GetUsersOnline, SendAllMessage},
     UserOperation,
   },
-  ConnectionId,
   LemmyContext,
-  LemmyError,
 };
 use actix_web::web::Data;
 use anyhow::Context;
+use lemmy_api_structs::{site::*, user::Register, APIError};
 use lemmy_db::{
   category::*,
   comment_view::*,
@@ -33,133 +30,15 @@ use lemmy_db::{
   post_view::*,
   site::*,
   site_view::*,
-  user::*,
   user_view::*,
   Crud,
   SearchType,
   SortType,
 };
-use lemmy_utils::{location_info, settings::Settings};
+use lemmy_utils::{location_info, settings::Settings, ConnectionId, LemmyError};
 use log::{debug, info};
-use serde::{Deserialize, Serialize};
 use std::str::FromStr;
 
-#[derive(Serialize, Deserialize)]
-pub struct ListCategories {}
-
-#[derive(Serialize, Deserialize)]
-pub struct ListCategoriesResponse {
-  categories: Vec<Category>,
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct Search {
-  q: String,
-  type_: String,
-  community_id: Option<i32>,
-  sort: String,
-  page: Option<i64>,
-  limit: Option<i64>,
-  auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct SearchResponse {
-  pub type_: String,
-  pub comments: Vec<CommentView>,
-  pub posts: Vec<PostView>,
-  pub communities: Vec<CommunityView>,
-  pub users: Vec<UserView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetModlog {
-  mod_user_id: Option<i32>,
-  community_id: Option<i32>,
-  page: Option<i64>,
-  limit: Option<i64>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetModlogResponse {
-  removed_posts: Vec<ModRemovePostView>,
-  locked_posts: Vec<ModLockPostView>,
-  stickied_posts: Vec<ModStickyPostView>,
-  removed_comments: Vec<ModRemoveCommentView>,
-  removed_communities: Vec<ModRemoveCommunityView>,
-  banned_from_community: Vec<ModBanFromCommunityView>,
-  banned: Vec<ModBanView>,
-  added_to_community: Vec<ModAddCommunityView>,
-  added: Vec<ModAddView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct CreateSite {
-  pub name: String,
-  pub description: Option<String>,
-  pub icon: Option<String>,
-  pub banner: Option<String>,
-  pub enable_downvotes: bool,
-  pub open_registration: bool,
-  pub enable_nsfw: bool,
-  pub auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct EditSite {
-  name: String,
-  description: Option<String>,
-  icon: Option<String>,
-  banner: Option<String>,
-  enable_downvotes: bool,
-  open_registration: bool,
-  enable_nsfw: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetSite {
-  auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct SiteResponse {
-  site: SiteView,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetSiteResponse {
-  site: Option<SiteView>,
-  admins: Vec<UserView>,
-  banned: Vec<UserView>,
-  pub online: usize,
-  version: String,
-  my_user: Option<User_>,
-  federated_instances: Vec<String>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct TransferSite {
-  user_id: i32,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetSiteConfig {
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetSiteConfigResponse {
-  config_hjson: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct SaveSiteConfig {
-  config_hjson: String,
-  auth: String,
-}
-
 #[async_trait::async_trait(?Send)]
 impl Perform for ListCategories {
   type Response = ListCategoriesResponse;
index 32a9d2b82ac2f0e2735cac286888ab00c462c62d..a40f296e85b42e094cfed8cf98b1f840ace0943f 100644 (file)
@@ -1,13 +1,5 @@
 use crate::{
-  api::{
-    check_slurs,
-    claims::Claims,
-    get_user_from_jwt,
-    get_user_from_jwt_opt,
-    is_admin,
-    APIError,
-    Perform,
-  },
+  api::{check_slurs, claims::Claims, get_user_from_jwt, get_user_from_jwt_opt, is_admin, Perform},
   apub::ApubObjectType,
   blocking,
   captcha_espeak_wav_base64,
@@ -15,15 +7,14 @@ use crate::{
     messages::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage},
     UserOperation,
   },
-  ConnectionId,
   LemmyContext,
-  LemmyError,
 };
 use actix_web::web::Data;
 use anyhow::Context;
 use bcrypt::verify;
 use captcha::{gen, Difficulty};
 use chrono::Duration;
+use lemmy_api_structs::{user::*, APIError};
 use lemmy_db::{
   comment::*,
   comment_view::*,
@@ -60,242 +51,13 @@ use lemmy_utils::{
   remove_slurs,
   send_email,
   settings::Settings,
+  ConnectionId,
   EndpointType,
+  LemmyError,
 };
 use log::error;
-use serde::{Deserialize, Serialize};
 use std::str::FromStr;
 
-#[derive(Serialize, Deserialize, Debug)]
-pub struct Login {
-  username_or_email: String,
-  password: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct Register {
-  pub username: String,
-  pub email: Option<String>,
-  pub password: String,
-  pub password_verify: String,
-  pub admin: bool,
-  pub show_nsfw: bool,
-  pub captcha_uuid: Option<String>,
-  pub captcha_answer: Option<String>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetCaptcha {}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetCaptchaResponse {
-  ok: Option<CaptchaResponse>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct CaptchaResponse {
-  png: String,         // A Base64 encoded png
-  wav: Option<String>, // A Base64 encoded wav audio
-  uuid: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct SaveUserSettings {
-  show_nsfw: bool,
-  theme: String,
-  default_sort_type: i16,
-  default_listing_type: i16,
-  lang: String,
-  avatar: Option<String>,
-  banner: Option<String>,
-  preferred_username: Option<String>,
-  email: Option<String>,
-  bio: Option<String>,
-  matrix_user_id: Option<String>,
-  new_password: Option<String>,
-  new_password_verify: Option<String>,
-  old_password: Option<String>,
-  show_avatars: bool,
-  send_notifications_to_email: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct LoginResponse {
-  pub jwt: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetUserDetails {
-  user_id: Option<i32>,
-  username: Option<String>,
-  sort: String,
-  page: Option<i64>,
-  limit: Option<i64>,
-  community_id: Option<i32>,
-  saved_only: bool,
-  auth: Option<String>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetUserDetailsResponse {
-  user: UserView,
-  follows: Vec<CommunityFollowerView>,
-  moderates: Vec<CommunityModeratorView>,
-  comments: Vec<CommentView>,
-  posts: Vec<PostView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetRepliesResponse {
-  replies: Vec<ReplyView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetUserMentionsResponse {
-  mentions: Vec<UserMentionView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct MarkAllAsRead {
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct AddAdmin {
-  user_id: i32,
-  added: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddAdminResponse {
-  admins: Vec<UserView>,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct BanUser {
-  user_id: i32,
-  ban: bool,
-  remove_data: Option<bool>,
-  reason: Option<String>,
-  expires: Option<i64>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct BanUserResponse {
-  user: UserView,
-  banned: bool,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetReplies {
-  sort: String,
-  page: Option<i64>,
-  limit: Option<i64>,
-  unread_only: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetUserMentions {
-  sort: String,
-  page: Option<i64>,
-  limit: Option<i64>,
-  unread_only: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct MarkUserMentionAsRead {
-  user_mention_id: i32,
-  read: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct UserMentionResponse {
-  mention: UserMentionView,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct DeleteAccount {
-  password: String,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct PasswordReset {
-  email: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct PasswordResetResponse {}
-
-#[derive(Serialize, Deserialize)]
-pub struct PasswordChange {
-  token: String,
-  password: String,
-  password_verify: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct CreatePrivateMessage {
-  content: String,
-  pub recipient_id: i32,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct EditPrivateMessage {
-  edit_id: i32,
-  content: String,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct DeletePrivateMessage {
-  edit_id: i32,
-  deleted: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct MarkPrivateMessageAsRead {
-  edit_id: i32,
-  read: bool,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize)]
-pub struct GetPrivateMessages {
-  unread_only: bool,
-  page: Option<i64>,
-  limit: Option<i64>,
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct PrivateMessagesResponse {
-  messages: Vec<PrivateMessageView>,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct PrivateMessageResponse {
-  pub message: PrivateMessageView,
-}
-
-#[derive(Serialize, Deserialize, Debug)]
-pub struct UserJoin {
-  auth: String,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct UserJoinResponse {
-  pub user_id: i32,
-}
-
 #[async_trait::async_trait(?Send)]
 impl Perform for Login {
   type Response = LoginResponse;
index b4d6c4d2baa0c908fb4ed942620e1028af6ca33a..0ba8f8735710e5a5cecd9dc9d2d6a1957e9dbbf9 100644 (file)
@@ -1,14 +1,13 @@
 use crate::{
   apub::{activity_queue::send_activity, community::do_announce, insert_activity},
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   base::{Extends, ExtendsExt},
   object::AsObject,
 };
 use lemmy_db::{community::Community, user::User_};
-use lemmy_utils::{get_apub_protocol_string, settings::Settings};
+use lemmy_utils::{get_apub_protocol_string, settings::Settings, LemmyError};
 use serde::{export::fmt::Debug, Serialize};
 use url::{ParseError, Url};
 use uuid::Uuid;
index bc5faaa3931ce97e87162e872d72119f74146a9a..008846bf357bb5ada84bfe73088fdf63d1ce5b2a 100644 (file)
@@ -1,7 +1,4 @@
-use crate::{
-  apub::{check_is_apub_id_valid, extensions::signatures::sign, ActorType},
-  LemmyError,
-};
+use crate::apub::{check_is_apub_id_valid, extensions::signatures::sign, ActorType};
 use activitystreams::{
   base::{Extends, ExtendsExt},
   object::AsObject,
@@ -17,7 +14,7 @@ use background_jobs::{
   QueueHandle,
   WorkerConfig,
 };
-use lemmy_utils::{location_info, settings::Settings};
+use lemmy_utils::{location_info, settings::Settings, LemmyError};
 use log::warn;
 use serde::{Deserialize, Serialize};
 use std::{future::Future, pin::Pin};
index 988904e9738c1eb8e4cbc785a5a35dc77c4b9656..8c416369f446c5df0ecf4f5e1dc26615f1866f8f 100644 (file)
@@ -20,7 +20,6 @@ use crate::{
   blocking,
   DbPool,
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{
@@ -54,6 +53,7 @@ use lemmy_utils::{
   location_info,
   remove_slurs,
   scrape_text_for_mentions,
+  LemmyError,
   MentionData,
 };
 use log::debug;
index 67baa7860cee8efac128e6b9b378f3c5d35b899f..8d9b4dc1c8a344029b585940cbf2e3dd7f496340 100644 (file)
@@ -18,7 +18,6 @@ use crate::{
   blocking,
   DbPool,
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{
@@ -48,7 +47,7 @@ use lemmy_db::{
   post::Post,
   user::User_,
 };
-use lemmy_utils::{convert_datetime, get_apub_protocol_string, location_info};
+use lemmy_utils::{convert_datetime, get_apub_protocol_string, location_info, LemmyError};
 use serde::Deserialize;
 use url::Url;
 
index 3099a273eaca63aeaecd71f35fb1877d8ff6577b..766b3d796559988f4235f4728b1222da6681dba0 100644 (file)
@@ -1,8 +1,8 @@
-use crate::LemmyError;
 use activitystreams::unparsed::UnparsedMutExt;
 use activitystreams_ext::UnparsedExtension;
 use diesel::PgConnection;
 use lemmy_db::{category::Category, Crud};
+use lemmy_utils::LemmyError;
 use serde::{Deserialize, Serialize};
 
 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
index cb9697775382d76cf62d7d2646a19ecfef6af8aa..4a261c17e1335cbea63659e0d8f8ce5de7d982c7 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{apub::ActorType, LemmyError};
+use crate::apub::ActorType;
 use activitystreams::unparsed::UnparsedMutExt;
 use activitystreams_ext::UnparsedExtension;
 use actix_web::{client::ClientRequest, HttpRequest};
@@ -7,7 +7,7 @@ use http_signature_normalization_actix::{
   digest::{DigestClient, SignExt},
   Config,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 use log::debug;
 use openssl::{
   hash::MessageDigest,
index 0fcb115037b3de65bd9e7dcd19a74b3495934ec7..d45165777833c2601b93b2000dd1631c1051026e 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  api::site::SearchResponse,
   apub::{
     check_is_apub_id_valid,
     ActorType,
@@ -12,12 +11,12 @@ use crate::{
   blocking,
   request::{retry, RecvError},
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{base::BaseExt, collection::OrderedCollection, object::Note, prelude::*};
 use anyhow::{anyhow, Context};
 use chrono::NaiveDateTime;
 use diesel::result::Error::NotFound;
+use lemmy_api_structs::site::SearchResponse;
 use lemmy_db::{
   comment::{Comment, CommentForm},
   comment_view::CommentView,
@@ -32,7 +31,7 @@ use lemmy_db::{
   Joinable,
   SearchType,
 };
-use lemmy_utils::{get_apub_protocol_string, location_info};
+use lemmy_utils::{get_apub_protocol_string, location_info, LemmyError};
 use log::debug;
 use reqwest::Client;
 use serde::Deserialize;
index e0fb8065dfc29f06bc6e3bb4ebc036da982ebbcd..47607a05de078b71552c832122fc6474a2d90be9 100644 (file)
@@ -12,7 +12,6 @@ use crate::{
     shared_inbox::{get_community_id_from_activity, receive_unhandled_activity},
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::*,
@@ -21,7 +20,7 @@ use activitystreams::{
 };
 use actix_web::HttpResponse;
 use anyhow::Context;
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 
 pub async fn receive_announce(
   activity: AnyBase,
index a7d7d5750f849088acb347a02c2b7cc449930ce9..a391520476e34701f55e21c6bd5702b8a77cba54 100644 (file)
@@ -1,8 +1,5 @@
 use crate::{
-  api::{
-    comment::{send_local_notifs, CommentResponse},
-    post::PostResponse,
-  },
+  api::comment::send_local_notifs,
   apub::{
     inbox::shared_inbox::{
       announce_if_community_is_local,
@@ -19,18 +16,18 @@ use crate::{
     UserOperation,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{activity::Create, base::AnyBase, object::Note, prelude::*};
 use actix_web::HttpResponse;
 use anyhow::Context;
+use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
 use lemmy_db::{
   comment::{Comment, CommentForm},
   comment_view::CommentView,
   post::{Post, PostForm},
   post_view::PostView,
 };
-use lemmy_utils::{location_info, scrape_text_for_mentions};
+use lemmy_utils::{location_info, scrape_text_for_mentions, LemmyError};
 
 pub async fn receive_create(
   activity: AnyBase,
index 65180ca43ef12e466dd6b4ceb8010009aa957c33..70bf376160e8715531dbe193f5c92f740e5d3fe7 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
   apub::{
     fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
@@ -18,11 +17,15 @@ use crate::{
     UserOperation,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{activity::Delete, base::AnyBase, object::Note, prelude::*};
 use actix_web::HttpResponse;
 use anyhow::Context;
+use lemmy_api_structs::{
+  comment::CommentResponse,
+  community::CommunityResponse,
+  post::PostResponse,
+};
 use lemmy_db::{
   comment::{Comment, CommentForm},
   comment_view::CommentView,
@@ -33,7 +36,7 @@ use lemmy_db::{
   post_view::PostView,
   Crud,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 
 pub async fn receive_delete(
   activity: AnyBase,
index 441e36f1a3eb7a6f052db5ecf47563b562cb2261..599389b18dfe7ffaab8e25a76bc467caec911a36 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  api::{comment::CommentResponse, post::PostResponse},
   apub::{
     fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
@@ -16,11 +15,11 @@ use crate::{
     UserOperation,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
 use actix_web::HttpResponse;
 use anyhow::Context;
+use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
 use lemmy_db::{
   comment::{CommentForm, CommentLike, CommentLikeForm},
   comment_view::CommentView,
@@ -28,7 +27,7 @@ use lemmy_db::{
   post_view::PostView,
   Likeable,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 
 pub async fn receive_dislike(
   activity: AnyBase,
index 67aefaa08c048f2f2af6f8db0cfbd68ed4a8a872..2cb95521e7b7dca72ae6005bbf7fd42113975b48 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  api::{comment::CommentResponse, post::PostResponse},
   apub::{
     fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
@@ -16,11 +15,11 @@ use crate::{
     UserOperation,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{activity::Like, base::AnyBase, object::Note, prelude::*};
 use actix_web::HttpResponse;
 use anyhow::Context;
+use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
 use lemmy_db::{
   comment::{CommentForm, CommentLike, CommentLikeForm},
   comment_view::CommentView,
@@ -28,7 +27,7 @@ use lemmy_db::{
   post_view::PostView,
   Likeable,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 
 pub async fn receive_like(
   activity: AnyBase,
index f0e98be2b162a565ef8c91b77471227fad7068ad..846842d4e6314b6ec0fff4fc2ff87e07bb3cb3bf 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
   apub::{
     fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
@@ -19,11 +18,15 @@ use crate::{
     UserOperation,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{activity::Remove, base::AnyBase, object::Note, prelude::*};
 use actix_web::HttpResponse;
 use anyhow::{anyhow, Context};
+use lemmy_api_structs::{
+  comment::CommentResponse,
+  community::CommunityResponse,
+  post::PostResponse,
+};
 use lemmy_db::{
   comment::{Comment, CommentForm},
   comment_view::CommentView,
@@ -34,7 +37,7 @@ use lemmy_db::{
   post_view::PostView,
   Crud,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 
 pub async fn receive_remove(
   activity: AnyBase,
index 9bf9e96ad10427670fa932328fbc3d95391cf43a..0b695d32eeb12792312256e511504e6a4860e1bc 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
   apub::{
     fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
@@ -18,7 +17,6 @@ use crate::{
     UserOperation,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::*,
@@ -28,6 +26,11 @@ use activitystreams::{
 };
 use actix_web::HttpResponse;
 use anyhow::{anyhow, Context};
+use lemmy_api_structs::{
+  comment::CommentResponse,
+  community::CommunityResponse,
+  post::PostResponse,
+};
 use lemmy_db::{
   comment::{Comment, CommentForm, CommentLike},
   comment_view::CommentView,
@@ -39,7 +42,7 @@ use lemmy_db::{
   Crud,
   Likeable,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 
 pub async fn receive_undo(
   activity: AnyBase,
index d5d01235005c903a348d0ae30c38cfaf535f5167..eb1b67f1d25c25c931a22e727a3db264cd13c729 100644 (file)
@@ -1,8 +1,5 @@
 use crate::{
-  api::{
-    comment::{send_local_notifs, CommentResponse},
-    post::PostResponse,
-  },
+  api::comment::send_local_notifs,
   apub::{
     fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
     inbox::shared_inbox::{
@@ -20,11 +17,11 @@ use crate::{
     UserOperation,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{activity::Update, base::AnyBase, object::Note, prelude::*};
 use actix_web::HttpResponse;
 use anyhow::Context;
+use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
 use lemmy_db::{
   comment::{Comment, CommentForm},
   comment_view::CommentView,
@@ -32,7 +29,7 @@ use lemmy_db::{
   post_view::PostView,
   Crud,
 };
-use lemmy_utils::{location_info, scrape_text_for_mentions};
+use lemmy_utils::{location_info, scrape_text_for_mentions, LemmyError};
 
 pub async fn receive_update(
   activity: AnyBase,
index 929b851135ee1e94e2473f14a2e4bcab8f10db46..0631f93913b72b2e80c6bd93469b334e484dc882 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
   },
   blocking,
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{ActorAndObject, Follow, Undo},
@@ -22,7 +21,7 @@ use lemmy_db::{
   user::User_,
   Followable,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 use log::debug;
 use serde::{Deserialize, Serialize};
 use std::fmt::Debug;
index 0f8cc8ed883138d101c6cd8e0336ad61c2bb86f6..da79510823174c8b1b433e527d2b853a5b129267 100644 (file)
@@ -21,7 +21,6 @@ use crate::{
     insert_activity,
   },
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{ActorAndObject, ActorAndObjectRef},
@@ -32,7 +31,7 @@ use activitystreams::{
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::Context;
 use lemmy_db::user::User_;
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 use log::debug;
 use serde::{Deserialize, Serialize};
 use std::fmt::Debug;
index ddb97109c45d50fdd7da3b001f3fd8ab24b801ca..7ea95833e8c20b44d070756de87e5a1936dd9f3e 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  api::user::PrivateMessageResponse,
   apub::{
     check_is_apub_id_valid,
     extensions::signatures::verify,
@@ -10,7 +9,6 @@ use crate::{
   blocking,
   websocket::{messages::SendUserRoomMessage, UserOperation},
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{Accept, ActorAndObject, Create, Delete, Undo, Update},
@@ -20,6 +18,7 @@ use activitystreams::{
 };
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::Context;
+use lemmy_api_structs::user::PrivateMessageResponse;
 use lemmy_db::{
   community::{CommunityFollower, CommunityFollowerForm},
   naive_now,
@@ -29,7 +28,7 @@ use lemmy_db::{
   Crud,
   Followable,
 };
-use lemmy_utils::location_info;
+use lemmy_utils::{location_info, LemmyError};
 use log::debug;
 use serde::{Deserialize, Serialize};
 use std::fmt::Debug;
index c545a5fd04a3318d9629d1b53d645bbb9452acde..b3b161c7db0aee5f477cdfd9fa4f67a4028b6973 100644 (file)
@@ -20,7 +20,6 @@ use crate::{
   routes::webfinger::WebFingerResponse,
   DbPool,
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::Follow,
@@ -40,6 +39,7 @@ use lemmy_utils::{
   get_apub_protocol_string,
   location_info,
   settings::Settings,
+  LemmyError,
   MentionData,
 };
 use log::debug;
index 606c4752197472ae11176c3a46fb653e07472e92..a54b8f6a357617e78ecabd79eb5f5ac61eb1c7b9 100644 (file)
@@ -18,7 +18,6 @@ use crate::{
   blocking,
   DbPool,
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{
@@ -44,7 +43,7 @@ use lemmy_db::{
   user::User_,
   Crud,
 };
-use lemmy_utils::{convert_datetime, location_info, remove_slurs};
+use lemmy_utils::{convert_datetime, location_info, remove_slurs, LemmyError};
 use serde::Deserialize;
 use url::Url;
 
index 1b3472e328fbd941a52e91d8e113ecf962a21b0d..5563aef361b46db79e435d6ea69be35610d403bd 100644 (file)
@@ -15,7 +15,6 @@ use crate::{
   blocking,
   DbPool,
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{
@@ -34,7 +33,7 @@ use lemmy_db::{
   user::User_,
   Crud,
 };
-use lemmy_utils::{convert_datetime, location_info};
+use lemmy_utils::{convert_datetime, location_info, LemmyError};
 use url::Url;
 
 #[async_trait::async_trait(?Send)]
index a61813c1858be96d0c950eb6da04d22ff1365f8d..5522a34137ab6b56dd5cdf95d32676b9ec25bcec 100644 (file)
@@ -15,7 +15,6 @@ use crate::{
   blocking,
   DbPool,
   LemmyContext,
-  LemmyError,
 };
 use activitystreams::{
   activity::{
@@ -34,7 +33,7 @@ use lemmy_db::{
   naive_now,
   user::{UserForm, User_},
 };
-use lemmy_utils::{convert_datetime, location_info};
+use lemmy_utils::{convert_datetime, location_info, LemmyError};
 use serde::Deserialize;
 use url::Url;
 
index d5139441d9975f7a3deeda5abe3f16400af01fc2..e59aa88c796495e18e763d5fb9b31849c5f50fa0 100644 (file)
@@ -1,5 +1,4 @@
 // This is for db migrations that require code
-use crate::LemmyError;
 use diesel::{
   sql_types::{Nullable, Text},
   *,
@@ -19,6 +18,7 @@ use lemmy_utils::{
   make_apub_endpoint,
   settings::Settings,
   EndpointType,
+  LemmyError,
 };
 use log::info;
 
index 79182be90bad22ef601f47ec7e7b2c6113bdbf2b..380dc445494b9e985d8b657f07596e3ee4e58279 100644 (file)
@@ -24,20 +24,19 @@ pub extern crate strum;
 pub mod api;
 pub mod apub;
 pub mod code_migrations;
-pub mod rate_limit;
 pub mod request;
 pub mod routes;
 pub mod version;
 pub mod websocket;
 
-use crate::request::{retry, RecvError};
-
-use crate::websocket::chat_server::ChatServer;
+use crate::{
+  request::{retry, RecvError},
+  websocket::chat_server::ChatServer,
+};
 use actix::Addr;
-use actix_web::dev::ConnectionInfo;
 use anyhow::anyhow;
 use background_jobs::QueueHandle;
-use lemmy_utils::{get_apub_protocol_string, settings::Settings};
+use lemmy_utils::{get_apub_protocol_string, settings::Settings, LemmyError};
 use log::error;
 use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
 use reqwest::Client;
@@ -45,33 +44,6 @@ use serde::Deserialize;
 use std::process::Command;
 
 pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
-pub type ConnectionId = usize;
-pub type PostId = i32;
-pub type CommunityId = i32;
-pub type UserId = i32;
-pub type IPAddr = String;
-
-#[derive(Debug)]
-pub struct LemmyError {
-  inner: anyhow::Error,
-}
-
-impl<T> From<T> for LemmyError
-where
-  T: Into<anyhow::Error>,
-{
-  fn from(t: T) -> Self {
-    LemmyError { inner: t.into() }
-  }
-}
-
-impl std::fmt::Display for LemmyError {
-  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
-    self.inner.fmt(f)
-  }
-}
-
-impl actix_web::error::ResponseError for LemmyError {}
 
 pub struct LemmyContext {
   pub pool: DbPool,
@@ -252,16 +224,6 @@ pub async fn is_image_content_type(client: &Client, test: &str) -> Result<(), Le
   }
 }
 
-pub fn get_ip(conn_info: &ConnectionInfo) -> String {
-  conn_info
-    .realip_remote_addr()
-    .unwrap_or("127.0.0.1:12345")
-    .split(':')
-    .next()
-    .unwrap_or("127.0.0.1")
-    .to_string()
-}
-
 pub async fn blocking<F, T>(pool: &DbPool, f: F) -> Result<T, LemmyError>
 where
   F: FnOnce(&diesel::PgConnection) -> T + Send + 'static,
index 30fcdaab38441149d4053831cb01f4110e905bbd..48549e4672c04b9d11f0e071b3f1d148e184ac20 100644 (file)
@@ -18,17 +18,16 @@ use diesel::{
   PgConnection,
 };
 use lemmy_db::get_database_url_from_env;
+use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
 use lemmy_server::{
   apub::activity_queue::create_activity_queue,
   blocking,
   code_migrations::run_advanced_migrations,
-  rate_limit::{rate_limiter::RateLimiter, RateLimit},
   routes::*,
   websocket::chat_server::ChatServer,
   LemmyContext,
-  LemmyError,
 };
-use lemmy_utils::{settings::Settings, CACHE_CONTROL_REGEX};
+use lemmy_utils::{settings::Settings, LemmyError, CACHE_CONTROL_REGEX};
 use reqwest::Client;
 use std::sync::Arc;
 use tokio::sync::Mutex;
index 490609e7dc0be31954e5fd961e79e12579119f4e..137848f2a695809eca9b162e6476817689bf099f 100644 (file)
@@ -1,5 +1,5 @@
-use crate::LemmyError;
 use anyhow::anyhow;
+use lemmy_utils::LemmyError;
 use std::future::Future;
 use thiserror::Error;
 
index f2ee38d259e8f978c37227c2b5d09ab9eaae354c..6a715f47294145340cd6a2804c5ffd6b832c15cd 100644 (file)
@@ -1,9 +1,7 @@
-use crate::{
-  api::{comment::*, community::*, post::*, site::*, user::*, Perform},
-  rate_limit::RateLimit,
-  LemmyContext,
-};
+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;
 
 pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
index 890a458f9d7d22e4e6e34a399a6a4dbbbdf31c0a..9bfe4cb6f34c0ffe4522d512d8320a43e466bea2 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{api::claims::Claims, blocking, LemmyContext, LemmyError};
+use crate::{api::claims::Claims, blocking, LemmyContext};
 use actix_web::{error::ErrorBadRequest, *};
 use anyhow::anyhow;
 use chrono::{DateTime, NaiveDateTime, Utc};
@@ -13,7 +13,7 @@ use lemmy_db::{
   ListingType,
   SortType,
 };
-use lemmy_utils::{markdown_to_html, settings::Settings};
+use lemmy_utils::{markdown_to_html, settings::Settings, LemmyError};
 use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder};
 use serde::Deserialize;
 use std::str::FromStr;
index 766aff6ee15699422cc2d95b94b11271689cf907..2e5aa9b3ba63817ab89c648b566f2c5157a62e87 100644 (file)
@@ -1,7 +1,7 @@
-use crate::rate_limit::RateLimit;
 use actix::clock::Duration;
 use actix_web::{body::BodyStream, http::StatusCode, *};
 use awc::Client;
+use lemmy_rate_limit::RateLimit;
 use lemmy_utils::settings::Settings;
 use serde::{Deserialize, Serialize};
 
index 1c81bc5446c0daeb28f616a51bac1f45b6b6cf0d..1390b21ec6ab1c20b1e90b94f6b7a51c4ded28ed 100644 (file)
@@ -1,8 +1,8 @@
-use crate::{blocking, version, LemmyContext, LemmyError};
+use crate::{blocking, version, LemmyContext};
 use actix_web::{body::Body, error::ErrorBadRequest, *};
 use anyhow::anyhow;
 use lemmy_db::site_view::SiteView;
-use lemmy_utils::{get_apub_protocol_string, settings::Settings};
+use lemmy_utils::{get_apub_protocol_string, settings::Settings, LemmyError};
 use serde::{Deserialize, Serialize};
 use url::Url;
 
index 57bea713d1682b6cfafdb1f8e9daa673607af874..22861434c6a90dc77436929769a618eebc40d1a3 100644 (file)
@@ -1,8 +1,13 @@
-use crate::{blocking, LemmyContext, LemmyError};
+use crate::{blocking, LemmyContext};
 use actix_web::{error::ErrorBadRequest, web::Query, *};
 use anyhow::anyhow;
 use lemmy_db::{community::Community, user::User_};
-use lemmy_utils::{settings::Settings, WEBFINGER_COMMUNITY_REGEX, WEBFINGER_USER_REGEX};
+use lemmy_utils::{
+  settings::Settings,
+  LemmyError,
+  WEBFINGER_COMMUNITY_REGEX,
+  WEBFINGER_USER_REGEX,
+};
 use serde::{Deserialize, Serialize};
 
 #[derive(Deserialize)]
index 954b39b22f81fa60c12601d5fe60a9c6acbf925e..465974c00f8789dab8d038bf81bc697474f9729f 100644 (file)
@@ -1,5 +1,4 @@
 use crate::{
-  get_ip,
   websocket::{
     chat_server::ChatServer,
     messages::{Connect, Disconnect, StandardMessage, WSMessage},
@@ -9,6 +8,7 @@ use crate::{
 use actix::prelude::*;
 use actix_web::*;
 use actix_web_actors::ws;
+use lemmy_utils::get_ip;
 use log::{debug, error, info};
 use std::time::{Duration, Instant};
 
index 92633c06c45bfa2757027cc1744c1b623f032cdc..cb73b4644e8b58f8e7e3ae694b8487c32f95bb7b 100644 (file)
@@ -1,18 +1,10 @@
 use crate::{
-  api::{comment::*, community::*, post::*, site::*, user::*, APIError},
-  rate_limit::RateLimit,
   websocket::{
     handlers::{do_user_operation, to_json_string, Args},
     messages::*,
     UserOperation,
   },
-  CommunityId,
-  ConnectionId,
-  IPAddr,
   LemmyContext,
-  LemmyError,
-  PostId,
-  UserId,
 };
 use actix::prelude::*;
 use anyhow::Context as acontext;
@@ -21,7 +13,9 @@ use diesel::{
   r2d2::{ConnectionManager, Pool},
   PgConnection,
 };
-use lemmy_utils::location_info;
+use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*, APIError};
+use lemmy_rate_limit::RateLimit;
+use lemmy_utils::{location_info, CommunityId, ConnectionId, IPAddr, LemmyError, PostId, UserId};
 use rand::rngs::ThreadRng;
 use reqwest::Client;
 use serde::Serialize;
index 6d195ab037984c0e60f23ed17f2576bea1d63cdc..a65e88bb552a9c2e3337952060b3baa81fecc1a2 100644 (file)
@@ -1,19 +1,17 @@
 use crate::{
   api::Perform,
-  rate_limit::RateLimit,
   websocket::{
     chat_server::{ChatServer, SessionInfo},
     messages::*,
     UserOperation,
   },
-  ConnectionId,
-  IPAddr,
   LemmyContext,
-  LemmyError,
 };
 use actix::{Actor, Context, Handler, ResponseFuture};
 use actix_web::web;
 use lemmy_db::naive_now;
+use lemmy_rate_limit::RateLimit;
+use lemmy_utils::{ConnectionId, IPAddr, LemmyError};
 use log::{error, info};
 use rand::Rng;
 use serde::{Deserialize, Serialize};
index 1289017c6510e30d653afbb5254aa686afa7bd11..2a0e5fde1e6f8b256a9207e76d327c205548c5df 100644 (file)
@@ -1,13 +1,7 @@
-use crate::{
-  api::{comment::CommentResponse, post::PostResponse},
-  websocket::UserOperation,
-  CommunityId,
-  ConnectionId,
-  IPAddr,
-  PostId,
-  UserId,
-};
+use crate::websocket::UserOperation;
 use actix::{prelude::*, Recipient};
+use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
+use lemmy_utils::{CommunityId, ConnectionId, IPAddr, PostId, UserId};
 use serde::{Deserialize, Serialize};
 
 /// Chat server sends this messages to session