Attempt to move websocket into workspace

This commit is contained in:
Felix Ableitner 2020-09-01 19:00:46 +02:00
parent 353e2e027a
commit 02e0363fd2
10 changed files with 84 additions and 14 deletions

26
server/Cargo.lock generated vendored
View file

@ -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"

2
server/Cargo.toml vendored
View file

@ -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"

View file

@ -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"

View file

@ -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<LemmyContext>,
websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError>;
}

23
server/lemmy_websocket/Cargo.toml vendored Normal file
View file

@ -0,0 +1,23 @@
[package]
name = "lemmy_websocket"
version = "0.1.0"
authors = ["Felix Ableitner <me@nutomic.com>"]
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"

View file

@ -1,5 +1,5 @@
use crate::{
websocket::{
{
handlers::{do_user_operation, to_json_string, Args},
messages::*,
UserOperation,

View file

@ -1,6 +1,6 @@
use crate::{
api::Perform,
websocket::{
{
chat_server::{ChatServer, SessionInfo},
messages::*,
UserOperation,

View file

@ -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;

View file

@ -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};

View file

@ -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<LemmyContext>,
websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError>;
}
pub(in crate::api) async fn is_mod_or_admin(
pool: &DbPool,
user_id: i32,