From 18bb413011244b44d3ccdb2716e33af86ec61e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Sun, 24 May 2020 19:39:41 +0200 Subject: [PATCH] add async/.await until all our errors are the same: that our Connection is not Send-safe. --- src/routes/comments.rs | 2 +- src/routes/instance.rs | 12 ++++++++---- src/routes/posts.rs | 20 ++++++++++++-------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/routes/comments.rs b/src/routes/comments.rs index ce05abbc..88f553c4 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -178,7 +178,7 @@ pub fn delete( } #[get("/~/<_blog>/<_slug>/comment/")] -pub fn activity_pub( +pub async fn activity_pub( _blog: String, _slug: String, id: i32, diff --git a/src/routes/instance.rs b/src/routes/instance.rs index a4897cff..055ac123 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -387,17 +387,21 @@ fn ban( } #[post("/inbox", data = "")] -pub fn shared_inbox( +pub async fn shared_inbox( rockets: PlumeRocket, data: inbox::SignedJson, headers: Headers<'_>, ) -> Result> { - inbox::handle_incoming(rockets, data, headers) + inbox::handle_incoming(rockets, data, headers).await } #[get("/remote_interact?")] -pub fn interact(rockets: PlumeRocket, user: Option, target: String) -> Option { - if User::find_by_fqn(&rockets, &target).is_ok() { +pub async fn interact( + rockets: PlumeRocket, + user: Option, + target: String, +) -> Option { + if User::find_by_fqn(&rockets, &target).await.is_ok() { return Some(Redirect::to(uri!(super::user::details: name = target))); } diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 16329d9b..e3bc3426 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -33,7 +33,7 @@ use plume_models::{ }; #[get("/~//?", rank = 4)] -pub fn details( +pub async fn details( blog: String, slug: String, responding_to: Option, @@ -41,7 +41,7 @@ pub fn details( ) -> Result { let conn = &*rockets.conn; let user = rockets.user.clone(); - let blog = Blog::find_by_fqn(&rockets, &blog)?; + let blog = Blog::find_by_fqn(&rockets, &blog).await?; let post = Post::find_by_slug(&*conn, &slug, blog.id)?; if !(post.published || post @@ -99,14 +99,14 @@ pub fn details( } #[get("/~//", rank = 3)] -pub fn activity_details( +pub async fn activity_details( blog: String, slug: String, _ap: ApRequest, rockets: PlumeRocket, ) -> Result, Option> { let conn = &*rockets.conn; - let blog = Blog::find_by_fqn(&rockets, &blog).map_err(|_| None)?; + let blog = Blog::find_by_fqn(&rockets, &blog).await.map_err(|_| None)?; let post = Post::find_by_slug(&*conn, &slug, blog.id).map_err(|_| None)?; if post.published { Ok(ActivityStream::new( @@ -130,9 +130,9 @@ pub fn new_auth(blog: String, i18n: I18n) -> Flash { } #[get("/~//new", rank = 1)] -pub fn new(blog: String, cl: ContentLen, rockets: PlumeRocket) -> Result { +pub async fn new(blog: String, cl: ContentLen, rockets: PlumeRocket) -> Result { let conn = &*rockets.conn; - let b = Blog::find_by_fqn(&rockets, &blog)?; + let b = Blog::find_by_fqn(&rockets, &blog).await?; let user = rockets.user.clone().unwrap(); if !user.is_author_in(&*conn, &b)? { @@ -408,7 +408,9 @@ pub fn create( rockets: PlumeRocket, ) -> Result { let conn = &*rockets.conn; - let blog = Blog::find_by_fqn(&rockets, &blog_name).expect("post::create: blog error"); + let blog = Blog::find_by_fqn(&rockets, &blog_name) + .await + .expect("post::create: blog error"); let slug = form.title.to_string().to_kebab_case(); let user = rockets.user.clone().unwrap(); @@ -522,6 +524,7 @@ pub fn create( Mention::from_activity( &*conn, &Mention::build_activity(&rockets, &m) + .await .expect("post::create: mention build error"), post.id, true, @@ -564,7 +567,7 @@ pub fn create( } #[post("/~///delete")] -pub fn delete( +pub async fn delete( blog_name: String, slug: String, rockets: PlumeRocket, @@ -572,6 +575,7 @@ pub fn delete( ) -> Result, ErrorPage> { let user = rockets.user.clone().unwrap(); let post = Blog::find_by_fqn(&rockets, &blog_name) + .await .and_then(|blog| Post::find_by_slug(&*rockets.conn, &slug, blog.id)); if let Ok(post) = post {