Make various functions async
This commit is contained in:
parent
d8c84e2541
commit
4361f48b98
8 changed files with 24 additions and 16 deletions
1
server/Cargo.lock
generated
vendored
1
server/Cargo.lock
generated
vendored
|
@ -1298,6 +1298,7 @@ dependencies = [
|
||||||
"activitypub 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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 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-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 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)",
|
"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)",
|
"bcrypt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
1
server/Cargo.toml
vendored
1
server/Cargo.toml
vendored
|
@ -18,6 +18,7 @@ actix = "0.9.0"
|
||||||
actix-web = "2.0.0"
|
actix-web = "2.0.0"
|
||||||
actix-files = "0.2.1"
|
actix-files = "0.2.1"
|
||||||
actix-web-actors = "2.0.0"
|
actix-web-actors = "2.0.0"
|
||||||
|
actix-rt = "1.0.0"
|
||||||
env_logger = "0.7.1"
|
env_logger = "0.7.1"
|
||||||
rand = "0.7.0"
|
rand = "0.7.0"
|
||||||
strum = "0.17.1"
|
strum = "0.17.1"
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub struct CommunityQuery {
|
||||||
community_name: String,
|
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();
|
let connection = establish_connection();
|
||||||
|
|
||||||
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
|
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();
|
let connection = establish_connection();
|
||||||
|
|
||||||
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
|
if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub struct UserQuery {
|
||||||
user_name: String,
|
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();
|
let connection = establish_connection();
|
||||||
|
|
||||||
if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) {
|
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::db::establish_connection;
|
||||||
use lemmy_server::routes::{federation, feeds, index, nodeinfo, webfinger, websocket};
|
use lemmy_server::routes::{federation, feeds, index, nodeinfo, webfinger, websocket};
|
||||||
use lemmy_server::settings::Settings;
|
use lemmy_server::settings::Settings;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
embed_migrations!();
|
embed_migrations!();
|
||||||
|
|
||||||
fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> io::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("lemmy");
|
|
||||||
|
|
||||||
// Run the migrations from code
|
// Run the migrations from code
|
||||||
let conn = establish_connection();
|
let conn = establish_connection();
|
||||||
|
@ -19,6 +20,11 @@ fn main() {
|
||||||
|
|
||||||
let settings = Settings::get();
|
let settings = Settings::get();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Starting http server at {}:{}",
|
||||||
|
settings.bind, settings.port
|
||||||
|
);
|
||||||
|
|
||||||
// Create Http server with websocket support
|
// Create Http server with websocket support
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -37,10 +43,7 @@ fn main() {
|
||||||
settings.front_end_dir.to_owned() + "/documentation",
|
settings.front_end_dir.to_owned() + "/documentation",
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.bind((settings.bind, settings.port))
|
.bind((settings.bind, settings.port))?
|
||||||
.unwrap()
|
.run()
|
||||||
.run();
|
.await
|
||||||
|
|
||||||
println!("Started http server at {}:{}", settings.bind, settings.port);
|
|
||||||
let _ = sys.run();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
.route("/feeds/all.xml", web::get().to(feeds::get_all_feed));
|
.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) {
|
let sort_type = match get_sort_type(info) {
|
||||||
Ok(sort_type) => sort_type,
|
Ok(sort_type) => sort_type,
|
||||||
Err(_) => return HttpResponse::BadRequest().finish(),
|
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) {
|
let sort_type = match get_sort_type(info) {
|
||||||
Ok(sort_type) => sort_type,
|
Ok(sort_type) => sort_type,
|
||||||
Err(_) => return HttpResponse::BadRequest().finish(),
|
Err(_) => return HttpResponse::BadRequest().finish(),
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
.route("/.well-known/nodeinfo", web::get().to(node_info_well_known));
|
.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!({
|
let json = json!({
|
||||||
"links": {
|
"links": {
|
||||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
"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())
|
.body(json.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn node_info() -> HttpResponse<Body> {
|
async fn node_info() -> HttpResponse<Body> {
|
||||||
let conn = establish_connection();
|
let conn = establish_connection();
|
||||||
let site_view = match SiteView::read(&conn) {
|
let site_view = match SiteView::read(&conn) {
|
||||||
Ok(site_view) => site_view,
|
Ok(site_view) => site_view,
|
||||||
|
|
|
@ -37,7 +37,7 @@ lazy_static! {
|
||||||
///
|
///
|
||||||
/// You can also view the webfinger response that Mastodon sends:
|
/// You can also view the webfinger response that Mastodon sends:
|
||||||
/// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town
|
/// 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
|
let regex_parsed = WEBFINGER_COMMUNITY_REGEX
|
||||||
.captures(&info.resource)
|
.captures(&info.resource)
|
||||||
.map(|c| c.get(1));
|
.map(|c| c.get(1));
|
||||||
|
|
Loading…
Reference in a new issue