mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-22 04:00:59 +00:00
fix *
This commit is contained in:
parent
3b609f5b49
commit
970f8e8d1b
2 changed files with 20 additions and 7 deletions
|
@ -204,7 +204,6 @@ async fn post_relay(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: Undo Follow
|
|
||||||
(StatusCode::BAD_REQUEST, "Not a recognized request").into_response()
|
(StatusCode::BAD_REQUEST, "Not a recognized request").into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
src/relay.rs
26
src/relay.rs
|
@ -10,14 +10,14 @@ use crate::{db::Database, send, actor};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Post<'a> {
|
struct Post<'a> {
|
||||||
// pub url: &'a str,
|
pub url: Option<&'a str>,
|
||||||
pub uri: &'a str,
|
pub uri: &'a str,
|
||||||
pub tags: Option<Vec<Tag<'a>>>,
|
pub tags: Option<Vec<Tag<'a>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post<'_> {
|
impl Post<'_> {
|
||||||
pub fn host(&self) -> Option<String> {
|
pub fn host(&self) -> Option<String> {
|
||||||
reqwest::Url::parse(&self.uri)
|
reqwest::Url::parse(self.url?)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|url| url.domain()
|
.and_then(|url| url.domain()
|
||||||
.map(|s| s.to_lowercase())
|
.map(|s| s.to_lowercase())
|
||||||
|
@ -78,10 +78,17 @@ pub fn spawn(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// tracing::trace!("post uri={:?} url={:?}", post.uri, post.url);
|
||||||
|
let post_url = match post.url {
|
||||||
|
Some(url) => url,
|
||||||
|
// skip reposts
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
// TODO: queue by target?
|
// TODO: queue by target?
|
||||||
let mut seen = HashSet::new();
|
let mut seen_actors = HashSet::new();
|
||||||
|
let mut seen_inboxes = HashSet::new();
|
||||||
for actor in post.relay_targets(hostname.clone()) {
|
for actor in post.relay_targets(hostname.clone()) {
|
||||||
if seen.contains(&actor) {
|
if seen_actors.contains(&actor) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,22 +99,29 @@ pub fn spawn(
|
||||||
"actor": &actor_id,
|
"actor": &actor_id,
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
"object": &post.uri,
|
"object": &post.uri,
|
||||||
"id": &post.uri,
|
"id": &post_url,
|
||||||
});
|
});
|
||||||
let body = Arc::new(
|
let body = Arc::new(
|
||||||
serde_json::to_vec(&body)
|
serde_json::to_vec(&body)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
);
|
);
|
||||||
for inbox in database.get_following_inboxes(&actor_id).await.unwrap() {
|
for inbox in database.get_following_inboxes(&actor_id).await.unwrap() {
|
||||||
|
if seen_inboxes.contains(&inbox) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
tracing::debug!("relay {} to {}", actor_id, inbox);
|
||||||
if let Err(e) = send::send_raw(
|
if let Err(e) = send::send_raw(
|
||||||
&client, &inbox,
|
&client, &inbox,
|
||||||
&actor.key_id(), &private_key, body.clone()
|
&actor.key_id(), &private_key, body.clone()
|
||||||
).await {
|
).await {
|
||||||
tracing::error!("relay::send {:?}", e);
|
tracing::error!("relay::send {:?}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seen_inboxes.insert(inbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
seen.insert(actor);
|
seen_actors.insert(actor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue