add async/.await until all our errors are the same:

that our Connection is not Send-safe.
This commit is contained in:
Mina Galić 2020-05-24 19:39:41 +02:00
parent d2881ee3f7
commit 18bb413011
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
3 changed files with 21 additions and 13 deletions

View File

@ -178,7 +178,7 @@ pub fn delete(
} }
#[get("/~/<_blog>/<_slug>/comment/<id>")] #[get("/~/<_blog>/<_slug>/comment/<id>")]
pub fn activity_pub( pub async fn activity_pub(
_blog: String, _blog: String,
_slug: String, _slug: String,
id: i32, id: i32,

View File

@ -387,17 +387,21 @@ fn ban(
} }
#[post("/inbox", data = "<data>")] #[post("/inbox", data = "<data>")]
pub fn shared_inbox( pub async fn shared_inbox(
rockets: PlumeRocket, rockets: PlumeRocket,
data: inbox::SignedJson<serde_json::Value>, data: inbox::SignedJson<serde_json::Value>,
headers: Headers<'_>, headers: Headers<'_>,
) -> Result<String, status::BadRequest<&'static str>> { ) -> Result<String, status::BadRequest<&'static str>> {
inbox::handle_incoming(rockets, data, headers) inbox::handle_incoming(rockets, data, headers).await
} }
#[get("/remote_interact?<target>")] #[get("/remote_interact?<target>")]
pub fn interact(rockets: PlumeRocket, user: Option<User>, target: String) -> Option<Redirect> { pub async fn interact(
if User::find_by_fqn(&rockets, &target).is_ok() { rockets: PlumeRocket,
user: Option<User>,
target: String,
) -> Option<Redirect> {
if User::find_by_fqn(&rockets, &target).await.is_ok() {
return Some(Redirect::to(uri!(super::user::details: name = target))); return Some(Redirect::to(uri!(super::user::details: name = target)));
} }

View File

@ -33,7 +33,7 @@ use plume_models::{
}; };
#[get("/~/<blog>/<slug>?<responding_to>", rank = 4)] #[get("/~/<blog>/<slug>?<responding_to>", rank = 4)]
pub fn details( pub async fn details(
blog: String, blog: String,
slug: String, slug: String,
responding_to: Option<i32>, responding_to: Option<i32>,
@ -41,7 +41,7 @@ pub fn details(
) -> Result<Ructe, ErrorPage> { ) -> Result<Ructe, ErrorPage> {
let conn = &*rockets.conn; let conn = &*rockets.conn;
let user = rockets.user.clone(); 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)?; let post = Post::find_by_slug(&*conn, &slug, blog.id)?;
if !(post.published if !(post.published
|| post || post
@ -99,14 +99,14 @@ pub fn details(
} }
#[get("/~/<blog>/<slug>", rank = 3)] #[get("/~/<blog>/<slug>", rank = 3)]
pub fn activity_details( pub async fn activity_details(
blog: String, blog: String,
slug: String, slug: String,
_ap: ApRequest, _ap: ApRequest,
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Result<ActivityStream<LicensedArticle>, Option<String>> { ) -> Result<ActivityStream<LicensedArticle>, Option<String>> {
let conn = &*rockets.conn; 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)?; let post = Post::find_by_slug(&*conn, &slug, blog.id).map_err(|_| None)?;
if post.published { if post.published {
Ok(ActivityStream::new( Ok(ActivityStream::new(
@ -130,9 +130,9 @@ pub fn new_auth(blog: String, i18n: I18n) -> Flash<Redirect> {
} }
#[get("/~/<blog>/new", rank = 1)] #[get("/~/<blog>/new", rank = 1)]
pub fn new(blog: String, cl: ContentLen, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> { pub async fn new(blog: String, cl: ContentLen, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
let conn = &*rockets.conn; 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(); let user = rockets.user.clone().unwrap();
if !user.is_author_in(&*conn, &b)? { if !user.is_author_in(&*conn, &b)? {
@ -408,7 +408,9 @@ pub fn create(
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Result<RespondOrRedirect, ErrorPage> { ) -> Result<RespondOrRedirect, ErrorPage> {
let conn = &*rockets.conn; 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 slug = form.title.to_string().to_kebab_case();
let user = rockets.user.clone().unwrap(); let user = rockets.user.clone().unwrap();
@ -522,6 +524,7 @@ pub fn create(
Mention::from_activity( Mention::from_activity(
&*conn, &*conn,
&Mention::build_activity(&rockets, &m) &Mention::build_activity(&rockets, &m)
.await
.expect("post::create: mention build error"), .expect("post::create: mention build error"),
post.id, post.id,
true, true,
@ -564,7 +567,7 @@ pub fn create(
} }
#[post("/~/<blog_name>/<slug>/delete")] #[post("/~/<blog_name>/<slug>/delete")]
pub fn delete( pub async fn delete(
blog_name: String, blog_name: String,
slug: String, slug: String,
rockets: PlumeRocket, rockets: PlumeRocket,
@ -572,6 +575,7 @@ pub fn delete(
) -> Result<Flash<Redirect>, ErrorPage> { ) -> Result<Flash<Redirect>, ErrorPage> {
let user = rockets.user.clone().unwrap(); let user = rockets.user.clone().unwrap();
let post = Blog::find_by_fqn(&rockets, &blog_name) let post = Blog::find_by_fqn(&rockets, &blog_name)
.await
.and_then(|blog| Post::find_by_slug(&*rockets.conn, &slug, blog.id)); .and_then(|blog| Post::find_by_slug(&*rockets.conn, &slug, blog.id));
if let Ok(post) = post { if let Ok(post) = post {