actor: normalize unicode away for TagRelay

This commit is contained in:
Astro 2023-03-03 02:19:48 +01:00
parent a6fb6cc9ec
commit e207dda2fe
5 changed files with 22 additions and 4 deletions

7
Cargo.lock generated
View file

@ -237,6 +237,7 @@ dependencies = [
"axum-extra",
"axum-macros",
"chrono",
"deunicode",
"eventsource-stream",
"futures",
"http",
@ -417,6 +418,12 @@ dependencies = [
"syn",
]
[[package]]
name = "deunicode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c1bba4f227a4a53d12b653f50ca7bf10c9119ae2aba56aff9e0338b5c98f36a"
[[package]]
name = "digest"
version = "0.10.6"

View file

@ -27,3 +27,4 @@ systemd = "0.10"
metrics = "0.20"
metrics-util = "0.14"
metrics-exporter-prometheus = "0.11"
deunicode = "1.3"

View file

@ -1,4 +1,5 @@
use std::sync::Arc;
use deunicode::deunicode;
use sigh::{PublicKey, Key};
use crate::activitypub;
@ -9,6 +10,15 @@ pub enum ActorKind {
InstanceRelay(String),
}
impl ActorKind {
pub fn from_tag(tag: &str) -> Self {
let tag = deunicode(tag)
.to_lowercase()
.replace(char::is_whitespace, "");
ActorKind::TagRelay(tag)
}
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Actor {
pub host: Arc<String>,

View file

@ -97,7 +97,7 @@ async fn get_tag_actor(
track_request("GET", "actor", "tag");
let target = actor::Actor {
host: state.hostname.clone(),
kind: actor::ActorKind::TagRelay(tag.to_lowercase()),
kind: actor::ActorKind::from_tag(&tag),
};
target.as_activitypub(&state.pub_key)
.into_response()
@ -123,7 +123,7 @@ async fn post_tag_relay(
) -> Response {
let target = actor::Actor {
host: state.hostname.clone(),
kind: actor::ActorKind::TagRelay(tag.to_lowercase()),
kind: actor::ActorKind::from_tag(&tag),
};
post_relay(state, endpoint, target).await
}

View file

@ -30,7 +30,7 @@ impl Post<'_> {
vec![],
Some(tags) =>
tags.iter()
.map(|tag| tag.name.to_lowercase())
.map(|tag| tag.name.to_string())
.collect()
}
}
@ -42,7 +42,7 @@ impl Post<'_> {
.chain(
self.tags()
.into_iter()
.map(actor::ActorKind::TagRelay)
.map(|ref s| actor::ActorKind::from_tag(s))
)
}