mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-24 21:11:00 +00:00
main: resolve webfinger with https uri
This commit is contained in:
parent
9cfcf60903
commit
f9a103de9a
2 changed files with 51 additions and 19 deletions
24
src/actor.rs
24
src/actor.rs
|
@ -26,6 +26,30 @@ pub struct Actor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Actor {
|
impl Actor {
|
||||||
|
pub fn from_uri(mut uri: &str) -> Option<Self> {
|
||||||
|
if ! uri.starts_with("https://") {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
uri = &uri[8..];
|
||||||
|
|
||||||
|
let parts = uri.split("/").collect::<Vec<_>>();
|
||||||
|
if parts.len() != 3 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let Ok(topic) = urlencoding::decode(parts[2]) else { return None; };
|
||||||
|
let kind = match parts[1] {
|
||||||
|
"tag" =>
|
||||||
|
ActorKind::TagRelay(topic.to_string()),
|
||||||
|
"instance" =>
|
||||||
|
ActorKind::InstanceRelay(topic.to_string()),
|
||||||
|
_ =>
|
||||||
|
return None,
|
||||||
|
};
|
||||||
|
let host = Arc::new(parts[0].to_string());
|
||||||
|
Some(Actor { host, kind })
|
||||||
|
}
|
||||||
|
|
||||||
pub fn uri(&self) -> String {
|
pub fn uri(&self) -> String {
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
ActorKind::TagRelay(tag) =>
|
ActorKind::TagRelay(tag) =>
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -28,6 +28,7 @@ mod activitypub;
|
||||||
mod actor_cache;
|
mod actor_cache;
|
||||||
mod endpoint;
|
mod endpoint;
|
||||||
|
|
||||||
|
use actor::Actor;
|
||||||
use state::State;
|
use state::State;
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ async fn webfinger(
|
||||||
return StatusCode::NOT_FOUND.into_response();
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
let target = if resource.starts_with("acct:") {
|
||||||
let (target_kind, target_host) =
|
let (target_kind, target_host) =
|
||||||
if resource.starts_with("acct:tag-") {
|
if resource.starts_with("acct:tag-") {
|
||||||
let off = "acct:tag-".len();
|
let off = "acct:tag-".len();
|
||||||
|
@ -61,11 +63,17 @@ async fn webfinger(
|
||||||
track_request("GET", "webfinger", "not_found");
|
track_request("GET", "webfinger", "not_found");
|
||||||
return StatusCode::NOT_FOUND.into_response();
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
};
|
};
|
||||||
track_request("GET", "webfinger", "found");
|
actor::Actor {
|
||||||
let target = actor::Actor {
|
|
||||||
host: target_host,
|
host: target_host,
|
||||||
kind: target_kind,
|
kind: target_kind,
|
||||||
|
}
|
||||||
|
} else if let Some(target) = Actor::from_uri(resource) {
|
||||||
|
target
|
||||||
|
} else {
|
||||||
|
track_request("GET", "webfinger", "not_found");
|
||||||
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
};
|
};
|
||||||
|
track_request("GET", "webfinger", "found");
|
||||||
Json(json!({
|
Json(json!({
|
||||||
"subject": &resource,
|
"subject": &resource,
|
||||||
"aliases": &[
|
"aliases": &[
|
||||||
|
|
Loading…
Reference in a new issue