mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-27 13:21:32 +00:00
Merge branch 'actix-2.0' into dev
This commit is contained in:
commit
f3dbedb5c5
12 changed files with 448 additions and 554 deletions
4
docker/dev/Dockerfile
vendored
4
docker/dev/Dockerfile
vendored
|
@ -10,7 +10,7 @@ RUN yarn install --pure-lockfile
|
|||
COPY ui /app/ui
|
||||
RUN yarn build
|
||||
|
||||
FROM ekidd/rust-musl-builder:1.38.0-openssl11 as rust
|
||||
FROM ekidd/rust-musl-builder:1.40.0-openssl11 as rust
|
||||
|
||||
# Cache deps
|
||||
WORKDIR /app
|
||||
|
@ -33,7 +33,7 @@ RUN cargo build --frozen --release
|
|||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
||||
|
||||
|
||||
FROM ekidd/rust-musl-builder:1.38.0-openssl11 as docs
|
||||
FROM ekidd/rust-musl-builder:1.40.0-openssl11 as docs
|
||||
WORKDIR /app
|
||||
COPY docs ./docs
|
||||
RUN sudo chown -R rust:rust .
|
||||
|
|
918
server/Cargo.lock
generated
vendored
918
server/Cargo.lock
generated
vendored
File diff suppressed because it is too large
Load diff
9
server/Cargo.toml
vendored
9
server/Cargo.toml
vendored
|
@ -14,10 +14,11 @@ chrono = { version = "0.4.7", features = ["serde"] }
|
|||
failure = "0.1.5"
|
||||
serde_json = { version = "1.0.40", features = ["preserve_order"]}
|
||||
serde = { version = "1.0.94", features = ["derive"] }
|
||||
actix = "0.8.3"
|
||||
actix-web = "1.0"
|
||||
actix-files = "0.1.3"
|
||||
actix-web-actors = "1.0"
|
||||
actix = "0.9.0"
|
||||
actix-web = "2.0.0"
|
||||
actix-files = "0.2.1"
|
||||
actix-web-actors = "2.0.0"
|
||||
actix-rt = "1.0.0"
|
||||
env_logger = "0.7.1"
|
||||
rand = "0.7.0"
|
||||
strum = "0.17.1"
|
||||
|
|
|
@ -84,7 +84,7 @@ pub struct CommunityQuery {
|
|||
community_name: String,
|
||||
}
|
||||
|
||||
pub fn get_apub_community(info: Path<CommunityQuery>) -> HttpResponse<Body> {
|
||||
pub async fn get_apub_community(info: Path<CommunityQuery>) -> HttpResponse<Body> {
|
||||
let connection = establish_connection();
|
||||
|
||||
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
|
||||
|
@ -96,7 +96,7 @@ pub fn get_apub_community(info: Path<CommunityQuery>) -> HttpResponse<Body> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_apub_community_followers(info: Path<CommunityQuery>) -> HttpResponse<Body> {
|
||||
pub async fn get_apub_community_followers(info: Path<CommunityQuery>) -> HttpResponse<Body> {
|
||||
let connection = establish_connection();
|
||||
|
||||
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
|
||||
|
|
|
@ -61,7 +61,7 @@ pub struct UserQuery {
|
|||
user_name: String,
|
||||
}
|
||||
|
||||
pub fn get_apub_user(info: Path<UserQuery>) -> HttpResponse<Body> {
|
||||
pub async fn get_apub_user(info: Path<UserQuery>) -> HttpResponse<Body> {
|
||||
let connection = establish_connection();
|
||||
|
||||
if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) {
|
||||
|
|
|
@ -6,12 +6,13 @@ use actix_web::*;
|
|||
use lemmy_server::db::establish_connection;
|
||||
use lemmy_server::routes::{federation, feeds, index, nodeinfo, webfinger, websocket};
|
||||
use lemmy_server::settings::Settings;
|
||||
use std::io;
|
||||
|
||||
embed_migrations!();
|
||||
|
||||
fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env_logger::init();
|
||||
let sys = actix::System::new("lemmy");
|
||||
|
||||
// Run the migrations from code
|
||||
let conn = establish_connection();
|
||||
|
@ -19,6 +20,11 @@ fn main() {
|
|||
|
||||
let settings = Settings::get();
|
||||
|
||||
println!(
|
||||
"Starting http server at {}:{}",
|
||||
settings.bind, settings.port
|
||||
);
|
||||
|
||||
// Create Http server with websocket support
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
|
@ -37,10 +43,7 @@ fn main() {
|
|||
settings.front_end_dir.to_owned() + "/documentation",
|
||||
))
|
||||
})
|
||||
.bind((settings.bind, settings.port))
|
||||
.unwrap()
|
||||
.start();
|
||||
|
||||
println!("Started http server at {}:{}", settings.bind, settings.port);
|
||||
let _ = sys.run();
|
||||
.bind((settings.bind, settings.port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
|||
.route("/feeds/all.xml", web::get().to(feeds::get_all_feed));
|
||||
}
|
||||
|
||||
fn get_all_feed(info: web::Query<Params>) -> HttpResponse<Body> {
|
||||
async fn get_all_feed(info: web::Query<Params>) -> HttpResponse<Body> {
|
||||
let sort_type = match get_sort_type(info) {
|
||||
Ok(sort_type) => sort_type,
|
||||
Err(_) => return HttpResponse::BadRequest().finish(),
|
||||
|
@ -53,7 +53,10 @@ fn get_all_feed(info: web::Query<Params>) -> HttpResponse<Body> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_feed(path: web::Path<(String, String)>, info: web::Query<Params>) -> HttpResponse<Body> {
|
||||
async fn get_feed(
|
||||
path: web::Path<(String, String)>,
|
||||
info: web::Query<Params>,
|
||||
) -> HttpResponse<Body> {
|
||||
let sort_type = match get_sort_type(info) {
|
||||
Ok(sort_type) => sort_type,
|
||||
Err(_) => return HttpResponse::BadRequest().finish(),
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
|||
.route("/password_change/{token}", web::get().to(index));
|
||||
}
|
||||
|
||||
fn index() -> Result<NamedFile, actix_web::error::Error> {
|
||||
async fn index() -> Result<NamedFile, actix_web::error::Error> {
|
||||
Ok(NamedFile::open(
|
||||
Settings::get().front_end_dir.to_owned() + "/index.html",
|
||||
)?)
|
||||
|
|
|
@ -13,7 +13,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
|||
.route("/.well-known/nodeinfo", web::get().to(node_info_well_known));
|
||||
}
|
||||
|
||||
pub fn node_info_well_known() -> HttpResponse<Body> {
|
||||
async fn node_info_well_known() -> HttpResponse<Body> {
|
||||
let json = json!({
|
||||
"links": {
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
|
@ -26,7 +26,7 @@ pub fn node_info_well_known() -> HttpResponse<Body> {
|
|||
.body(json.to_string())
|
||||
}
|
||||
|
||||
fn node_info() -> HttpResponse<Body> {
|
||||
async fn node_info() -> HttpResponse<Body> {
|
||||
let conn = establish_connection();
|
||||
let site_view = match SiteView::read(&conn) {
|
||||
Ok(site_view) => site_view,
|
||||
|
|
|
@ -37,7 +37,7 @@ lazy_static! {
|
|||
///
|
||||
/// You can also view the webfinger response that Mastodon sends:
|
||||
/// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town
|
||||
fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
|
||||
async fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
|
||||
let regex_parsed = WEBFINGER_COMMUNITY_REGEX
|
||||
.captures(&info.resource)
|
||||
.map(|c| c.get(1));
|
||||
|
|
|
@ -19,7 +19,7 @@ const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
|||
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
/// Entry point for our route
|
||||
fn chat_route(
|
||||
async fn chat_route(
|
||||
req: HttpRequest,
|
||||
stream: web::Payload,
|
||||
chat_server: web::Data<Addr<ChatServer>>,
|
||||
|
@ -80,7 +80,7 @@ impl Actor for WSSession {
|
|||
// something is wrong with chat server
|
||||
_ => ctx.stop(),
|
||||
}
|
||||
fut::ok(())
|
||||
actix::fut::ready(())
|
||||
})
|
||||
.wait(ctx);
|
||||
}
|
||||
|
@ -107,10 +107,17 @@ impl Handler<WSMessage> for WSSession {
|
|||
}
|
||||
|
||||
/// WebSocket message handler
|
||||
impl StreamHandler<ws::Message, ws::ProtocolError> for WSSession {
|
||||
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
||||
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WSSession {
|
||||
fn handle(&mut self, result: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
|
||||
// println!("WEBSOCKET MESSAGE: {:?} from id: {}", msg, self.id);
|
||||
match msg {
|
||||
let message = match result {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
match message {
|
||||
ws::Message::Ping(msg) => {
|
||||
self.hb = Instant::now();
|
||||
ctx.pong(&msg);
|
||||
|
@ -136,7 +143,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for WSSession {
|
|||
eprintln!("{}", &e);
|
||||
}
|
||||
}
|
||||
fut::ok(())
|
||||
actix::fut::ready(())
|
||||
})
|
||||
.wait(ctx);
|
||||
}
|
||||
|
@ -173,7 +180,7 @@ impl WSSession {
|
|||
return;
|
||||
}
|
||||
|
||||
ctx.ping("");
|
||||
ctx.ping(b"");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use crate::Settings;
|
|||
|
||||
/// Chat server sends this messages to session
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct WSMessage(pub String);
|
||||
|
||||
/// Message for chat server communications
|
||||
|
@ -35,6 +36,7 @@ pub struct Connect {
|
|||
|
||||
/// Session is disconnected
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct Disconnect {
|
||||
pub id: usize,
|
||||
pub ip: String,
|
||||
|
@ -42,6 +44,7 @@ pub struct Disconnect {
|
|||
|
||||
/// Send message to specific room
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct ClientMessage {
|
||||
/// Id of the client session
|
||||
pub id: usize,
|
||||
|
@ -51,7 +54,8 @@ pub struct ClientMessage {
|
|||
pub room: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Message)]
|
||||
#[rtype(String)]
|
||||
pub struct StandardMessage {
|
||||
/// Id of the client session
|
||||
pub id: usize,
|
||||
|
@ -59,10 +63,6 @@ pub struct StandardMessage {
|
|||
pub msg: String,
|
||||
}
|
||||
|
||||
impl actix::Message for StandardMessage {
|
||||
type Result = String;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RateLimitBucket {
|
||||
last_checked: SystemTime,
|
||||
|
|
Loading…
Reference in a new issue