Make various functions async

pull/722/head
Felix 2020-01-11 13:30:45 +01:00
parent d8c84e2541
commit 4361f48b98
8 changed files with 24 additions and 16 deletions

1
server/Cargo.lock generated vendored
View File

@ -1298,6 +1298,7 @@ dependencies = [
"activitypub 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-files 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web-actors 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bcrypt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",

1
server/Cargo.toml vendored
View File

@ -18,6 +18,7 @@ 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"

View File

@ -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()) {

View File

@ -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) {

View File

@ -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()
.run();
println!("Started http server at {}:{}", settings.bind, settings.port);
let _ = sys.run();
.bind((settings.bind, settings.port))?
.run()
.await
}

View File

@ -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(),

View File

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

View File

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