mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-27 12:30:31 +00:00
Add a ApRequest request guard to accept multiple ActivityPub header on one route
This commit is contained in:
parent
3796aa48c2
commit
8e47219d82
1 changed files with 21 additions and 1 deletions
|
@ -2,9 +2,10 @@ use activitypub::{Activity, Actor, Object, Link};
|
|||
use array_tool::vec::Uniq;
|
||||
use reqwest::Client;
|
||||
use rocket::{
|
||||
Outcome,
|
||||
http::Status,
|
||||
response::{Response, Responder},
|
||||
request::Request
|
||||
request::{FromRequest, Request}
|
||||
};
|
||||
use serde_json;
|
||||
|
||||
|
@ -59,6 +60,25 @@ impl<'r, O: Object> Responder<'r> for ActivityStream<O> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ApRequest;
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
||||
type Error = ();
|
||||
|
||||
fn from_request(request: &'a Request<'r>) -> Outcome<Self, (Status, Self::Error), ()> {
|
||||
request.headers().get_one("Content-Type").map(|header| header.split(",").map(|ct| match ct {
|
||||
"application/ld+json; profile=\"w3.org/ns/activitystreams\"" |
|
||||
"application/ld+json;profile=\"w3.org/ns/activitystreams\"" |
|
||||
"application/activity+json" |
|
||||
"application/ld+json" => Outcome::Success(ApRequest),
|
||||
_ => Outcome::Forward(())
|
||||
}).fold(Outcome::Forward(()), |out, ct| if out.is_success() {
|
||||
out
|
||||
} else {
|
||||
ct
|
||||
})).unwrap_or(Outcome::Forward(()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn broadcast<A: Activity, S: sign::Signer, T: inbox::WithInbox + Actor>(sender: &S, act: A, to: Vec<T>) {
|
||||
let boxes = to.into_iter()
|
||||
.map(|u| u.get_shared_inbox_url().unwrap_or(u.get_inbox_url()))
|
||||
|
|
Loading…
Reference in a new issue