cargo fmt

This commit is contained in:
Igor Galić 2020-02-18 09:27:12 +01:00
parent be8c67ee9a
commit e9c7259ffb
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
8 changed files with 37 additions and 28 deletions

View File

@ -95,7 +95,10 @@ impl<'a, 'r> FromRequestAsync<'a, 'r> for ApiToken {
return Outcome::Success(token);
}
} else {
return Outcome::Failure((Status::InternalServerError, TokenError::DbError));
return Outcome::Failure((
Status::InternalServerError,
TokenError::DbError,
));
}
}
} else {
@ -105,7 +108,6 @@ impl<'a, 'r> FromRequestAsync<'a, 'r> for ApiToken {
return Outcome::Failure((Status::BadRequest, TokenError::NoType));
}
Outcome::Forward(())
})
}

View File

@ -213,10 +213,7 @@ impl Media {
));
let mut dest = tokio::fs::File::create(path.clone()).await?;
let contents = reqwest::get(remote_url.as_str())
.await?
.bytes()
.await?;
let contents = reqwest::get(remote_url.as_str()).await?.bytes().await?;
dest.write_all(&contents).await?;
Media::insert(

View File

@ -23,13 +23,17 @@ mod module {
impl<'a, 'r> FromRequestAsync<'a, 'r> for PlumeRocket {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::FromRequestFuture<'a, Self, Self::Error> {
fn from_request(
request: &'a Request<'r>,
) -> request::FromRequestFuture<'a, Self, Self::Error> {
Box::pin(async move {
let conn = try_outcome!(DbConn::from_request(request).await);
let intl = try_outcome!(rocket_i18n::I18n::from_request(request).await);
let user = try_outcome!(users::User::from_request(request).await);
let worker = try_outcome!(request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>());
let searcher = try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
let worker =
try_outcome!(request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>());
let searcher =
try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded();
Outcome::Success(PlumeRocket {
conn,
@ -65,12 +69,16 @@ mod module {
impl<'a, 'r> FromRequestAsync<'a, 'r> for PlumeRocket {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::FromRequestFuture<'a, Self, Self::Error> {
fn from_request(
request: &'a Request<'r>,
) -> request::FromRequestFuture<'a, Self, Self::Error> {
Box::pin(async move {
let conn = try_outcome!(DbConn::from_request(request).await);
let user = try_outcome!(users::User::from_request(request).await);
let worker = try_outcome!(request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>());
let searcher = try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
let worker =
try_outcome!(request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>());
let searcher =
try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
Outcome::Success(PlumeRocket {
conn,
user: Some(user),

View File

@ -580,14 +580,11 @@ impl FromId<PlumeRocket> for Post {
}
});
let image = article
.object_props
.icon_object::<Image>()
.ok()
.unwrap();
let image = article.object_props.icon_object::<Image>().ok().unwrap();
let mut r = Runtime::new().unwrap();
let cover = Some(r.block_on(async {Media::from_activity(&c, &image).await.ok().unwrap().id}));
let cover =
Some(r.block_on(async { Media::from_activity(&c, &image).await.ok().unwrap().id }));
let title = article.object_props.name_string()?;
let post = Post::insert(
@ -710,7 +707,8 @@ impl FromId<PlumeRocket> for PostUpdate {
.ok()
.unwrap();
let mut r = Runtime::new().unwrap();
let cover = Some(r.block_on(async {Media::from_activity(&c, &image).await.ok().unwrap().id}));
let cover =
Some(r.block_on(async { Media::from_activity(&c, &image).await.ok().unwrap().id }));
Ok(PostUpdate {
ap_url: updated.object.object_props.id_string()?,

View File

@ -235,7 +235,8 @@ impl User {
.join(", "),
)?,
)
.send().await?;
.send()
.await?;
let text = &res.text().await?;
// without this workaround, publicKey is not correctly deserialized
let ap_sign = serde_json::from_str::<ApSignature>(text)?;
@ -371,7 +372,8 @@ impl User {
.join(", "),
)?,
)
.send().await?;
.send()
.await?;
let text = &res.text().await?;
let json: serde_json::Value = serde_json::from_str(text)?;
let items = json["items"]
@ -401,7 +403,8 @@ impl User {
.join(", "),
)?,
)
.send().await?;
.send()
.await?;
let text = &res.text().await?;
let json: serde_json::Value = serde_json::from_str(text)?;
if let Some(first) = json.get("first") {
@ -446,7 +449,8 @@ impl User {
.join(", "),
)?,
)
.send().await?;
.send()
.await?;
let text = &res.text().await?;
let json: serde_json::Value = serde_json::from_str(text)?;
Ok(json["items"]

View File

@ -32,15 +32,15 @@ impl<'r> Responder<'r> for ApiError {
Error::NotFound => Json(json!({
"error": "Not found"
}))
.respond_to(req),
.respond_to(req),
Error::Unauthorized => Json(json!({
"error": "You are not authorized to access this resource"
}))
.respond_to(req),
.respond_to(req),
_ => Json(json!({
"error": "Server error"
}))
.respond_to(req),
.respond_to(req),
}
}
}

View File

@ -6,8 +6,8 @@ use rocket_contrib::json::Json;
use rocket_i18n::I18n;
use scheduled_thread_pool::ScheduledThreadPool;
use serde_json;
use std::str::FromStr;
use std::path::PathBuf;
use std::str::FromStr;
use validator::{Validate, ValidationErrors};
use crate::inbox;

View File

@ -11,7 +11,7 @@ use std::{
use validator::{Validate, ValidationError, ValidationErrors};
use crate::routes::{
comments::NewCommentForm, errors::ErrorPage, Page, ContentLen, RemoteForm, RespondOrRedirect,
comments::NewCommentForm, errors::ErrorPage, ContentLen, Page, RemoteForm, RespondOrRedirect,
};
use crate::template_utils::{IntoContext, Ructe};
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest};