Run 'cargo fmt' to format code (#489)
This commit is contained in:
committed by
Baptiste Gelez
parent
732f514da7
commit
b945d1f602
+48
-35
@@ -1,23 +1,10 @@
|
||||
#![warn(clippy::too_many_arguments)]
|
||||
use activitypub::{
|
||||
activity::{
|
||||
Announce,
|
||||
Create,
|
||||
Delete,
|
||||
Follow as FollowAct,
|
||||
Like,
|
||||
Undo,
|
||||
Update
|
||||
},
|
||||
object::Tombstone
|
||||
activity::{Announce, Create, Delete, Follow as FollowAct, Like, Undo, Update},
|
||||
object::Tombstone,
|
||||
};
|
||||
use failure::Error;
|
||||
use rocket::{
|
||||
data::*,
|
||||
http::Status,
|
||||
Outcome::*,
|
||||
Request,
|
||||
};
|
||||
use rocket::{data::*, http::Status, Outcome::*, Request};
|
||||
use rocket_contrib::json::*;
|
||||
use serde::Deserialize;
|
||||
use serde_json;
|
||||
@@ -26,15 +13,21 @@ use std::io::Read;
|
||||
|
||||
use plume_common::activity_pub::{
|
||||
inbox::{Deletable, FromActivity, InboxError, Notify},
|
||||
Id,request::Digest,
|
||||
request::Digest,
|
||||
Id,
|
||||
};
|
||||
use plume_models::{
|
||||
comments::Comment, follows::Follow, instance::Instance, likes, posts::Post, reshares::Reshare,
|
||||
users::User, search::Searcher, Connection,
|
||||
search::Searcher, users::User, Connection,
|
||||
};
|
||||
|
||||
pub trait Inbox {
|
||||
fn received(&self, conn: &Connection, searcher: &Searcher, act: serde_json::Value) -> Result<(), Error> {
|
||||
fn received(
|
||||
&self,
|
||||
conn: &Connection,
|
||||
searcher: &Searcher,
|
||||
act: serde_json::Value,
|
||||
) -> Result<(), Error> {
|
||||
let actor_id = Id::new(act["actor"].as_str().unwrap_or_else(|| {
|
||||
act["actor"]["id"]
|
||||
.as_str()
|
||||
@@ -66,7 +59,8 @@ pub trait Inbox {
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
&(conn, searcher),
|
||||
).ok();
|
||||
)
|
||||
.ok();
|
||||
Comment::delete_id(
|
||||
&act.delete_props
|
||||
.object_object::<Tombstone>()?
|
||||
@@ -74,12 +68,14 @@ pub trait Inbox {
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
).ok();
|
||||
)
|
||||
.ok();
|
||||
Ok(())
|
||||
}
|
||||
"Follow" => {
|
||||
Follow::from_activity(conn, serde_json::from_value(act.clone())?, actor_id)
|
||||
.and_then(|f| f.notify(conn)).expect("Inbox::received: follow from activity error");;
|
||||
.and_then(|f| f.notify(conn))
|
||||
.expect("Inbox::received: follow from activity error");;
|
||||
Ok(())
|
||||
}
|
||||
"Like" => {
|
||||
@@ -87,7 +83,8 @@ pub trait Inbox {
|
||||
conn,
|
||||
serde_json::from_value(act.clone())?,
|
||||
actor_id,
|
||||
).expect("Inbox::received: like from activity error");;
|
||||
)
|
||||
.expect("Inbox::received: like from activity error");;
|
||||
Ok(())
|
||||
}
|
||||
"Undo" => {
|
||||
@@ -102,7 +99,8 @@ pub trait Inbox {
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
).expect("Inbox::received: undo like fail");;
|
||||
)
|
||||
.expect("Inbox::received: undo like fail");;
|
||||
Ok(())
|
||||
}
|
||||
"Announce" => {
|
||||
@@ -113,7 +111,8 @@ pub trait Inbox {
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
).expect("Inbox::received: undo reshare fail");;
|
||||
)
|
||||
.expect("Inbox::received: undo reshare fail");;
|
||||
Ok(())
|
||||
}
|
||||
"Follow" => {
|
||||
@@ -124,21 +123,28 @@ pub trait Inbox {
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
).expect("Inbox::received: undo follow error");;
|
||||
)
|
||||
.expect("Inbox::received: undo follow error");;
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(InboxError::CantUndo)?,
|
||||
}
|
||||
} else {
|
||||
let link = act.undo_props.object.as_str().expect("Inbox::received: undo doesn't contain a type and isn't Link");
|
||||
let link =
|
||||
act.undo_props.object.as_str().expect(
|
||||
"Inbox::received: undo doesn't contain a type and isn't Link",
|
||||
);
|
||||
if let Ok(like) = likes::Like::find_by_ap_url(conn, link) {
|
||||
likes::Like::delete_id(&like.ap_url, actor_id.as_ref(), conn).expect("Inbox::received: delete Like error");
|
||||
likes::Like::delete_id(&like.ap_url, actor_id.as_ref(), conn)
|
||||
.expect("Inbox::received: delete Like error");
|
||||
Ok(())
|
||||
} else if let Ok(reshare) = Reshare::find_by_ap_url(conn, link) {
|
||||
Reshare::delete_id(&reshare.ap_url, actor_id.as_ref(), conn).expect("Inbox::received: delete Announce error");
|
||||
Reshare::delete_id(&reshare.ap_url, actor_id.as_ref(), conn)
|
||||
.expect("Inbox::received: delete Announce error");
|
||||
Ok(())
|
||||
} else if let Ok(follow) = Follow::find_by_ap_url(conn, link) {
|
||||
Follow::delete_id(&follow.ap_url, actor_id.as_ref(), conn).expect("Inbox::received: delete Follow error");
|
||||
Follow::delete_id(&follow.ap_url, actor_id.as_ref(), conn)
|
||||
.expect("Inbox::received: delete Follow error");
|
||||
Ok(())
|
||||
} else {
|
||||
Err(InboxError::NoType)?
|
||||
@@ -147,7 +153,8 @@ pub trait Inbox {
|
||||
}
|
||||
"Update" => {
|
||||
let act: Update = serde_json::from_value(act.clone())?;
|
||||
Post::handle_update(conn, &act.update_props.object_object()?, searcher).expect("Inbox::received: post update error");
|
||||
Post::handle_update(conn, &act.update_props.object_object()?, searcher)
|
||||
.expect("Inbox::received: post update error");
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(InboxError::InvalidType)?,
|
||||
@@ -169,19 +176,25 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
|
||||
type Owned = String;
|
||||
type Borrowed = str;
|
||||
|
||||
fn transform(r: &Request, d: Data) -> Transform<rocket::data::Outcome<Self::Owned, Self::Error>> {
|
||||
fn transform(
|
||||
r: &Request,
|
||||
d: Data,
|
||||
) -> Transform<rocket::data::Outcome<Self::Owned, Self::Error>> {
|
||||
let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT);
|
||||
let mut s = String::with_capacity(512);
|
||||
match d.open().take(size_limit).read_to_string(&mut s) {
|
||||
Ok(_) => Transform::Borrowed(Success(s)),
|
||||
Err(e) => Transform::Borrowed(Failure((Status::BadRequest, JsonError::Io(e))))
|
||||
Err(e) => Transform::Borrowed(Failure((Status::BadRequest, JsonError::Io(e)))),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_data(_: &Request, o: Transformed<'a, Self>) -> rocket::data::Outcome<Self, Self::Error> {
|
||||
fn from_data(
|
||||
_: &Request,
|
||||
o: Transformed<'a, Self>,
|
||||
) -> rocket::data::Outcome<Self, Self::Error> {
|
||||
let string = o.borrowed()?;
|
||||
match serde_json::from_str(&string) {
|
||||
Ok(v) => Success(SignedJson(Digest::from_body(&string),Json(v))),
|
||||
Ok(v) => Success(SignedJson(Digest::from_body(&string), Json(v))),
|
||||
Err(e) => {
|
||||
if e.is_data() {
|
||||
Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
|
||||
|
||||
Reference in New Issue
Block a user