From 02e0363fd2bbc5028f7a7f35158b67ec4700b538 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 1 Sep 2020 19:00:46 +0200 Subject: [PATCH] Attempt to move websocket into workspace --- server/Cargo.lock | 26 +++++++++++++++++++ server/Cargo.toml | 2 ++ server/lemmy_api_structs/Cargo.toml | 3 +++ server/lemmy_api_structs/src/lib.rs | 14 ++++++++++ server/lemmy_websocket/Cargo.toml | 23 ++++++++++++++++ .../src}/chat_server.rs | 2 +- .../src}/handlers.rs | 2 +- .../mod.rs => lemmy_websocket/src/lib.rs} | 13 ++++++++++ .../src}/messages.rs | 2 +- server/src/api/mod.rs | 11 -------- 10 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 server/lemmy_websocket/Cargo.toml rename server/{src/websocket => lemmy_websocket/src}/chat_server.rs (99%) rename server/{src/websocket => lemmy_websocket/src}/handlers.rs (99%) rename server/{src/websocket/mod.rs => lemmy_websocket/src/lib.rs} (78%) rename server/{src/websocket => lemmy_websocket/src}/messages.rs (98%) diff --git a/server/Cargo.lock b/server/Cargo.lock index 305af342b..33e2d4367 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1798,7 +1798,10 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" name = "lemmy_api_structs" version = "0.1.0" dependencies = [ + "actix-web", + "async-trait", "lemmy_db", + "lemmy_utils", "serde 1.0.114", "thiserror", ] @@ -1868,6 +1871,7 @@ dependencies = [ "lemmy_db", "lemmy_rate_limit", "lemmy_utils", + "lemmy_websocket", "log", "openssl", "percent-encoding", @@ -1907,6 +1911,28 @@ dependencies = [ "url", ] +[[package]] +name = "lemmy_websocket" +version = "0.1.0" +dependencies = [ + "actix", + "actix-web", + "anyhow", + "chrono", + "diesel", + "lemmy_api_structs", + "lemmy_db", + "lemmy_rate_limit", + "lemmy_utils", + "log", + "rand 0.7.3", + "reqwest", + "serde 1.0.114", + "serde_json", + "strum", + "strum_macros", +] + [[package]] name = "lettre" version = "0.9.3" diff --git a/server/Cargo.toml b/server/Cargo.toml index 912d130d4..2cc3193d0 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -11,6 +11,7 @@ members = [ "lemmy_utils", "lemmy_db", "lemmy_api_structs", + "lemmy_websocket", ] [dependencies] @@ -18,6 +19,7 @@ lemmy_utils = { path = "./lemmy_utils" } lemmy_db = { path = "./lemmy_db" } lemmy_api_structs = { path = "./lemmy_api_structs" } lemmy_rate_limit = { path = "./lemmy_rate_limit" } +lemmy_websocket = { path = "./lemmy_websocket" } 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 index d1695eca6..00aa49d5b 100644 --- a/server/lemmy_api_structs/Cargo.toml +++ b/server/lemmy_api_structs/Cargo.toml @@ -6,5 +6,8 @@ edition = "2018" [dependencies] lemmy_db = { path = "../lemmy_db" } +lemmy_utils = { path = "../lemmy_utils" } serde = { version = "1.0.105", features = ["derive"] } thiserror = "1.0.20" +async-trait = "0.1.36" +actix-web = "3.0.0-alpha.3" diff --git a/server/lemmy_api_structs/src/lib.rs b/server/lemmy_api_structs/src/lib.rs index df5830409..1d1aaf0a2 100644 --- a/server/lemmy_api_structs/src/lib.rs +++ b/server/lemmy_api_structs/src/lib.rs @@ -1,5 +1,6 @@ pub extern crate serde; pub extern crate thiserror; +pub extern crate actix_web; pub mod comment; pub mod community; @@ -8,6 +9,8 @@ pub mod site; pub mod user; use thiserror::Error; +use actix_web::web::Data; +use lemmy_utils::{ConnectionId, LemmyError}; #[derive(Debug, Error)] #[error("{{\"error\":\"{message}\"}}")] @@ -22,3 +25,14 @@ impl APIError { } } } + +#[async_trait::async_trait(?Send)] +pub trait Perform { + type Response: serde::ser::Serialize + Send; + + async fn perform( + &self, + context: &Data, + websocket_id: Option, + ) -> Result; +} \ No newline at end of file diff --git a/server/lemmy_websocket/Cargo.toml b/server/lemmy_websocket/Cargo.toml new file mode 100644 index 000000000..ab5ea349c --- /dev/null +++ b/server/lemmy_websocket/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "lemmy_websocket" +version = "0.1.0" +authors = ["Felix Ableitner "] +edition = "2018" + +[dependencies] +lemmy_api_structs = { path = "../lemmy_api_structs" } +lemmy_rate_limit = { path = "../lemmy_rate_limit" } +lemmy_utils = { path = "../lemmy_utils" } +lemmy_db = { path = "../lemmy_db" } +log = "0.4.0" +actix = "0.10.0-alpha.2" +actix-web = { version = "3.0.0-alpha.3", features = ["rustls"] } +anyhow = "1.0.32" +diesel = "1.4.4" +rand = "0.7.3" +serde = { version = "1.0.105", features = ["derive"] } +serde_json = { version = "1.0.52", features = ["preserve_order"]} +chrono = { version = "0.4.7", features = ["serde"] } +reqwest = { version = "0.10", features = ["json"] } +strum = "0.18.0" +strum_macros = "0.18.0" diff --git a/server/src/websocket/chat_server.rs b/server/lemmy_websocket/src/chat_server.rs similarity index 99% rename from server/src/websocket/chat_server.rs rename to server/lemmy_websocket/src/chat_server.rs index cb73b4644..43eaeaf08 100644 --- a/server/src/websocket/chat_server.rs +++ b/server/lemmy_websocket/src/chat_server.rs @@ -1,5 +1,5 @@ use crate::{ - websocket::{ + { handlers::{do_user_operation, to_json_string, Args}, messages::*, UserOperation, diff --git a/server/src/websocket/handlers.rs b/server/lemmy_websocket/src/handlers.rs similarity index 99% rename from server/src/websocket/handlers.rs rename to server/lemmy_websocket/src/handlers.rs index a65e88bb5..13c5e276e 100644 --- a/server/src/websocket/handlers.rs +++ b/server/lemmy_websocket/src/handlers.rs @@ -1,6 +1,6 @@ use crate::{ api::Perform, - websocket::{ + { chat_server::{ChatServer, SessionInfo}, messages::*, UserOperation, diff --git a/server/src/websocket/mod.rs b/server/lemmy_websocket/src/lib.rs similarity index 78% rename from server/src/websocket/mod.rs rename to server/lemmy_websocket/src/lib.rs index b0441819e..5e4d56998 100644 --- a/server/src/websocket/mod.rs +++ b/server/lemmy_websocket/src/lib.rs @@ -1,3 +1,16 @@ +pub extern crate actix; +pub extern crate actix_web; +pub extern crate anyhow; +pub extern crate diesel; +pub extern crate rand; +pub extern crate serde; +pub extern crate serde_json; +pub extern crate chrono; +pub extern crate reqwest; +pub extern crate log; +#[macro_use] +pub extern crate strum_macros; + pub mod chat_server; pub mod handlers; pub mod messages; diff --git a/server/src/websocket/messages.rs b/server/lemmy_websocket/src/messages.rs similarity index 98% rename from server/src/websocket/messages.rs rename to server/lemmy_websocket/src/messages.rs index 2a0e5fde1..9c29c2e1c 100644 --- a/server/src/websocket/messages.rs +++ b/server/lemmy_websocket/src/messages.rs @@ -1,4 +1,4 @@ -use crate::websocket::UserOperation; +use crate::UserOperation; use actix::{prelude::*, Recipient}; use lemmy_api_structs::{comment::CommentResponse, post::PostResponse}; use lemmy_utils::{CommunityId, ConnectionId, IPAddr, PostId, UserId}; diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index 03a585f7f..3db2b0200 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -17,17 +17,6 @@ pub mod post; pub mod site; pub mod user; -#[async_trait::async_trait(?Send)] -pub trait Perform { - type Response: serde::ser::Serialize + Send; - - async fn perform( - &self, - context: &Data, - websocket_id: Option, - ) -> Result; -} - pub(in crate::api) async fn is_mod_or_admin( pool: &DbPool, user_id: i32,