diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index e4f15268..81c3d8fa 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -71,7 +71,8 @@ impl Blog { insert!(blogs, NewBlog, |inserted, conn| { let instance = inserted.get_instance(conn)?; if inserted.outbox_url.is_empty() { - inserted.outbox_url = instance.compute_box(BLOG_PREFIX, &inserted.actor_id, "outbox"); + inserted.outbox_url = + instance.compute_box(BLOG_PREFIX, &inserted.actor_id, r#"outbox"#); } if inserted.inbox_url.is_empty() { diff --git a/src/api/mod.rs b/src/api/mod.rs index 6e622e22..f13f5615 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -66,14 +66,14 @@ pub struct OAuthRequest { } #[get("/oauth2?")] -pub fn oauth( +pub async fn oauth( query: Form, rockets: PlumeRocket, ) -> Result, ApiError> { let conn = &*rockets.conn; let app = App::find_by_client_id(conn, &query.client_id)?; if app.client_secret == query.client_secret { - if let Outcome::Success(user) = User::find_by_fqn(&rockets, &query.username) { + if let Ok(user) = User::find_by_fqn(&rockets, &query.username).await { if user.auth(&query.password) { let token = ApiToken::insert( conn, diff --git a/src/api/posts.rs b/src/api/posts.rs index a290e31a..208847dd 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -98,7 +98,7 @@ pub fn list( } #[post("/posts", data = "")] -pub fn create( +pub async fn create( auth: Authorization, payload: Json, rockets: PlumeRocket, @@ -192,7 +192,7 @@ pub fn create( for m in mentions.into_iter() { Mention::from_activity( &*conn, - &Mention::build_activity(&rockets, &m)?, + &Mention::build_activity(&rockets, &m).await?, post.id, true, true, diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 0c08c536..0fb3d3bb 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -38,12 +38,12 @@ pub fn details(name: String, page: Option, rockets: PlumeRocket) -> Result } #[get("/~/", rank = 1)] -pub fn activity_details( +pub async fn activity_details( name: String, rockets: PlumeRocket, _ap: ApRequest, ) -> Option> { - let blog = Blog::find_by_fqn(&rockets, &name).ok()?; + let blog = Blog::find_by_fqn(&rockets, &name).await?.ok()?; Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?)) } @@ -93,7 +93,7 @@ pub fn create(form: LenientForm, rockets: PlumeRocket) -> RespondOr Ok(_) => ValidationErrors::new(), Err(e) => e, }; - if Blog::find_by_fqn(&rockets, &slug).is_ok() { + if Blog::find_by_fqn(&rockets, &slug).await.is_ok() { errors.add( "title", ValidationError { @@ -184,9 +184,9 @@ pub struct EditForm { } #[get("/~//edit")] -pub fn edit(name: String, rockets: PlumeRocket) -> Result { +pub async fn edit(name: String, rockets: PlumeRocket) -> Result { let conn = &*rockets.conn; - let blog = Blog::find_by_fqn(&rockets, &name)?; + let blog = Blog::find_by_fqn(&rockets, &name).await?; if rockets .user .clone() @@ -233,14 +233,16 @@ fn check_media(conn: &Connection, id: i32, user: &User) -> bool { } #[put("/~//edit", data = "
")] -pub fn update( +pub async fn update( name: String, form: LenientForm, rockets: PlumeRocket, ) -> RespondOrRedirect { let conn = &*rockets.conn; let intl = &rockets.intl.catalog; - let mut blog = Blog::find_by_fqn(&rockets, &name).expect("blog::update: blog not found"); + let mut blog = Blog::find_by_fqn(&rockets, &name) + .await + .expect("blog::update: blog not found"); if !rockets .user .clone() @@ -342,23 +344,26 @@ pub fn update( } #[get("/~//outbox")] -pub fn outbox(name: String, rockets: PlumeRocket) -> Option> { - let blog = Blog::find_by_fqn(&rockets, &name).ok()?; +pub async fn outbox( + name: String, + rockets: PlumeRocket, +) -> Option> { + let blog = Blog::find_by_fqn(&rockets, &name).await?.ok()?; Some(blog.outbox(&*rockets.conn).ok()?) } #[allow(unused_variables)] #[get("/~//outbox?")] -pub fn outbox_page( +pub async fn outbox_page( name: String, page: Page, rockets: PlumeRocket, ) -> Option> { - let blog = Blog::find_by_fqn(&rockets, &name).ok()?; + let blog = Blog::find_by_fqn(&rockets, &name).await?.ok()?; Some(blog.outbox_page(&*rockets.conn, page.limits()).ok()?) } #[get("/~//atom.xml")] -pub fn atom_feed(name: String, rockets: PlumeRocket) -> Option> { - let blog = Blog::find_by_fqn(&rockets, &name).ok()?; +pub async fn atom_feed(name: String, rockets: PlumeRocket) -> Option> { + let blog = Blog::find_by_fqn(&rockets, &name).await?.ok()?; let conn = &*rockets.conn; let entries = Post::get_recents_for_blog(&*conn, &blog, 15).ok()?; let uri = Instance::get_local() diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 134fb827..84658d40 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -162,7 +162,7 @@ pub fn new(blog: String, cl: ContentLen, rockets: PlumeRocket) -> Result//edit")] -pub fn edit( +pub async fn edit( blog: String, slug: String, cl: ContentLen, @@ -170,7 +170,7 @@ pub fn edit( ) -> Result { let conn = &*rockets.conn; let intl = &rockets.intl.catalog; - let b = Blog::find_by_fqn(&rockets, &blog)?; + let b = Blog::find_by_fqn(&rockets, &blog).await?; let post = Post::find_by_slug(&*conn, &slug, b.id)?; let user = rockets.user.clone().unwrap(); @@ -216,7 +216,7 @@ pub fn edit( } #[post("/~///edit", data = "")] -pub fn update( +pub async fn update( blog: String, slug: String, cl: ContentLen, @@ -224,7 +224,9 @@ pub fn update( rockets: PlumeRocket, ) -> RespondOrRedirect { let conn = &*rockets.conn; - let b = Blog::find_by_fqn(&rockets, &blog).expect("post::update: blog error"); + let b = Blog::find_by_fqn(&rockets, &blog) + .await + .expect("post::update: blog error"); let mut post = Post::find_by_slug(&*conn, &slug, b.id).expect("post::update: find by slug error"); let user = rockets.user.clone().unwrap(); @@ -302,11 +304,11 @@ pub fn update( if post.published { post.update_mentions( - &conn, mentions .into_iter() - .filter_map(|m| Mention::build_activity(&rockets, &m).ok()) + .filter_map(|m| Mention::build_activity(&rockets, &m).await.ok()) .collect(), + &conn, ) .expect("post::update: mentions error"); } @@ -321,7 +323,7 @@ pub fn update( .filter_map(|t| Tag::build_activity(t).ok()) .collect::>(); post.update_tags(&conn, tags) - .expect("post::update: tags error"); + .expect(r#"post::update: tags error"#); let hashtags = hashtags .into_iter() @@ -615,12 +617,13 @@ pub fn delete( } #[get("/~///remote_interact")] -pub fn remote_interact( +pub async fn remote_interact( rockets: PlumeRocket, blog_name: String, slug: String, ) -> Result { let target = Blog::find_by_fqn(&rockets, &blog_name) + .await .and_then(|blog| Post::find_by_slug(&rockets.conn, &slug, blog.id))?; Ok(render!(posts::remote_interact( &rockets.to_context(), @@ -633,17 +636,18 @@ pub fn remote_interact( } #[post("/~///remote_interact", data = "")] -pub fn remote_interact_post( +pub async fn remote_interact_post( rockets: PlumeRocket, blog_name: String, slug: String, remote: LenientForm, ) -> Result { let target = Blog::find_by_fqn(&rockets, &blog_name) + .await .and_then(|blog| Post::find_by_slug(&rockets.conn, &slug, blog.id))?; if let Some(uri) = User::fetch_remote_interact_uri(&remote.remote) - .ok() - .and_then(|uri| uri.replace("{uri}", format!("{}", target.ap_url)).ok()) + .await + .map(|uri| uri.replace("{uri}", format!("{}", target.ap_url)).ok()) { Ok(Redirect::to(uri).into()) } else {