mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-21 19:51:00 +00:00
Fix clippy warning
This commit is contained in:
parent
5f78fd131e
commit
d514c224ff
3 changed files with 32 additions and 32 deletions
26
src/actor.rs
26
src/actor.rs
|
@ -6,9 +6,9 @@ use crate::activitypub;
|
|||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum ActorKind {
|
||||
TagRelay(String),
|
||||
InstanceRelay(String),
|
||||
IngestRelay,
|
||||
Tag(String),
|
||||
Instance(String),
|
||||
Ingest,
|
||||
}
|
||||
|
||||
impl ActorKind {
|
||||
|
@ -16,7 +16,7 @@ impl ActorKind {
|
|||
let tag = deunicode(tag)
|
||||
.to_lowercase()
|
||||
.replace(char::is_whitespace, "");
|
||||
ActorKind::TagRelay(tag)
|
||||
ActorKind::Tag(tag)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,11 +29,11 @@ pub struct Actor {
|
|||
impl Actor {
|
||||
pub fn uri(&self) -> String {
|
||||
match &self.kind {
|
||||
ActorKind::TagRelay(tag) =>
|
||||
ActorKind::Tag(tag) =>
|
||||
format!("https://{}/tag/{}", self.host, tag),
|
||||
ActorKind::InstanceRelay(instance) =>
|
||||
ActorKind::Instance(instance) =>
|
||||
format!("https://{}/instance/{}", self.host, instance),
|
||||
ActorKind::IngestRelay => format!("https://{}/ingest", self.host),
|
||||
ActorKind::Ingest => format!("https://{}/ingest", self.host),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,11 +47,11 @@ impl Actor {
|
|||
actor_type: "Service".to_string(),
|
||||
id: self.uri(),
|
||||
name: Some(match &self.kind {
|
||||
ActorKind::TagRelay(tag) =>
|
||||
ActorKind::Tag(tag) =>
|
||||
format!("#{}", tag),
|
||||
ActorKind::InstanceRelay(instance) =>
|
||||
ActorKind::Instance(instance) =>
|
||||
instance.to_string(),
|
||||
ActorKind::IngestRelay =>
|
||||
ActorKind::Ingest =>
|
||||
self.host.to_string()
|
||||
}),
|
||||
icon: Some(activitypub::Media {
|
||||
|
@ -67,11 +67,11 @@ impl Actor {
|
|||
pem: pub_key.to_pem().unwrap(),
|
||||
},
|
||||
preferred_username: Some(match &self.kind {
|
||||
ActorKind::TagRelay(tag) =>
|
||||
ActorKind::Tag(tag) =>
|
||||
format!("tag-{}", tag),
|
||||
ActorKind::InstanceRelay(instance) =>
|
||||
ActorKind::Instance(instance) =>
|
||||
format!("instance-{}", instance),
|
||||
ActorKind::IngestRelay =>
|
||||
ActorKind::Ingest =>
|
||||
String::from(env!("CARGO_PKG_NAME")),
|
||||
}),
|
||||
}
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -64,16 +64,16 @@ async fn webfinger(
|
|||
if resource.starts_with("acct:tag-") {
|
||||
let off = "acct:tag-".len();
|
||||
let at = resource.find('@');
|
||||
(actor::ActorKind::TagRelay(resource[off..at.unwrap_or(resource.len())].to_string()),
|
||||
(actor::ActorKind::Tag(resource[off..at.unwrap_or(resource.len())].to_string()),
|
||||
at.map_or_else(|| state.hostname.clone(), |at| Arc::new(resource[at + 1..].to_string())))
|
||||
} else if resource.starts_with("acct:instance-") {
|
||||
let off = "acct:instance-".len();
|
||||
let at = resource.find('@');
|
||||
(actor::ActorKind::InstanceRelay(resource[off..at.unwrap_or(resource.len())].to_string()),
|
||||
(actor::ActorKind::Instance(resource[off..at.unwrap_or(resource.len())].to_string()),
|
||||
at.map_or_else(|| state.hostname.clone(), |at| Arc::new(resource[at + 1..].to_string())))
|
||||
} else if resource.starts_with("acct:ingest") {
|
||||
let at = resource.find('@');
|
||||
(actor::ActorKind::IngestRelay, at.map_or_else(|| state.hostname.clone(), |at| Arc::new(resource[at + 1..].to_string())))
|
||||
(actor::ActorKind::Ingest, at.map_or_else(|| state.hostname.clone(), |at| Arc::new(resource[at + 1..].to_string())))
|
||||
} else {
|
||||
track_request("GET", "webfinger", "not_found");
|
||||
return StatusCode::NOT_FOUND.into_response();
|
||||
|
@ -116,7 +116,7 @@ async fn get_instance_actor(
|
|||
track_request("GET", "actor", "instance");
|
||||
let target = actor::Actor {
|
||||
host: state.hostname.clone(),
|
||||
kind: actor::ActorKind::InstanceRelay(instance.to_lowercase()),
|
||||
kind: actor::ActorKind::Instance(instance.to_lowercase()),
|
||||
};
|
||||
target.as_activitypub(&state.pub_key)
|
||||
.into_response()
|
||||
|
@ -128,7 +128,7 @@ async fn get_ingest_actor(
|
|||
track_request("GET", "actor", "ingest");
|
||||
let target = actor::Actor {
|
||||
host: state.hostname.clone(),
|
||||
kind: actor::ActorKind::IngestRelay,
|
||||
kind: actor::ActorKind::Ingest,
|
||||
};
|
||||
target.as_activitypub(&state.pub_key)
|
||||
.into_response()
|
||||
|
@ -153,7 +153,7 @@ async fn post_instance_relay(
|
|||
) -> Response {
|
||||
let target = actor::Actor {
|
||||
host: state.hostname.clone(),
|
||||
kind: actor::ActorKind::InstanceRelay(instance.to_lowercase()),
|
||||
kind: actor::ActorKind::Instance(instance.to_lowercase()),
|
||||
};
|
||||
post_relay(state, endpoint, target).await
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ async fn post_ingest_relay(
|
|||
) -> Response{
|
||||
let target = actor::Actor {
|
||||
host: state.hostname.clone(),
|
||||
kind: actor::ActorKind::IngestRelay,
|
||||
kind: actor::ActorKind::Ingest,
|
||||
};
|
||||
post_relay(state, endpoint, target).await
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ async fn post_relay(
|
|||
).into_response()
|
||||
}
|
||||
}
|
||||
} else if let actor::ActorKind::IngestRelay = target.kind {
|
||||
} else if let actor::ActorKind::Ingest = target.kind {
|
||||
match state.ingest_tx.send(endpoint.payload.to_string()).await {
|
||||
Ok(()) => {
|
||||
track_request("POST", "relay", "ingest");
|
||||
|
|
22
src/relay.rs
22
src/relay.rs
|
@ -40,7 +40,7 @@ impl Post<'_> {
|
|||
fn relay_target_kinds(&self) -> impl Iterator<Item = actor::ActorKind> {
|
||||
self.host()
|
||||
.into_iter()
|
||||
.map(actor::ActorKind::InstanceRelay)
|
||||
.map(actor::ActorKind::Instance)
|
||||
.chain(
|
||||
self.tags()
|
||||
.into_iter()
|
||||
|
@ -259,8 +259,8 @@ mod test {
|
|||
}]),
|
||||
};
|
||||
let mut kinds = post.relay_target_kinds();
|
||||
assert_eq!(kinds.next(), Some(ActorKind::InstanceRelay("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::TagRelay("foo".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Instance("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Tag("foo".to_string())));
|
||||
assert_eq!(kinds.next(), None);
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ mod test {
|
|||
}]),
|
||||
};
|
||||
let mut kinds = post.relay_target_kinds();
|
||||
assert_eq!(kinds.next(), Some(ActorKind::InstanceRelay("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Instance("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), None);
|
||||
}
|
||||
|
||||
|
@ -288,8 +288,8 @@ mod test {
|
|||
}]),
|
||||
};
|
||||
let mut kinds = post.relay_target_kinds();
|
||||
assert_eq!(kinds.next(), Some(ActorKind::InstanceRelay("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::TagRelay("23".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Instance("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Tag("23".to_string())));
|
||||
assert_eq!(kinds.next(), None);
|
||||
}
|
||||
|
||||
|
@ -303,9 +303,9 @@ mod test {
|
|||
}]),
|
||||
};
|
||||
let mut kinds = post.relay_target_kinds();
|
||||
assert_eq!(kinds.next(), Some(ActorKind::InstanceRelay("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::TagRelay("dd1302".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::TagRelay("dd".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Instance("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Tag("dd1302".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Tag("dd".to_string())));
|
||||
assert_eq!(kinds.next(), None);
|
||||
}
|
||||
|
||||
|
@ -319,8 +319,8 @@ mod test {
|
|||
}]),
|
||||
};
|
||||
let mut kinds = post.relay_target_kinds();
|
||||
assert_eq!(kinds.next(), Some(ActorKind::InstanceRelay("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::TagRelay("sukoteitusiyuhuorudoronguhea".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Instance("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::Tag("sukoteitusiyuhuorudoronguhea".to_string())));
|
||||
assert_eq!(kinds.next(), None);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue