mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-22 12:11:00 +00:00
actor: normalize unicode away for TagRelay
This commit is contained in:
parent
a6fb6cc9ec
commit
e207dda2fe
5 changed files with 22 additions and 4 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -237,6 +237,7 @@ dependencies = [
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
"axum-macros",
|
"axum-macros",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"deunicode",
|
||||||
"eventsource-stream",
|
"eventsource-stream",
|
||||||
"futures",
|
"futures",
|
||||||
"http",
|
"http",
|
||||||
|
@ -417,6 +418,12 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deunicode"
|
||||||
|
version = "1.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8c1bba4f227a4a53d12b653f50ca7bf10c9119ae2aba56aff9e0338b5c98f36a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.6"
|
version = "0.10.6"
|
||||||
|
|
|
@ -27,3 +27,4 @@ systemd = "0.10"
|
||||||
metrics = "0.20"
|
metrics = "0.20"
|
||||||
metrics-util = "0.14"
|
metrics-util = "0.14"
|
||||||
metrics-exporter-prometheus = "0.11"
|
metrics-exporter-prometheus = "0.11"
|
||||||
|
deunicode = "1.3"
|
||||||
|
|
10
src/actor.rs
10
src/actor.rs
|
@ -1,4 +1,5 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use deunicode::deunicode;
|
||||||
use sigh::{PublicKey, Key};
|
use sigh::{PublicKey, Key};
|
||||||
|
|
||||||
use crate::activitypub;
|
use crate::activitypub;
|
||||||
|
@ -9,6 +10,15 @@ pub enum ActorKind {
|
||||||
InstanceRelay(String),
|
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)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Actor {
|
pub struct Actor {
|
||||||
pub host: Arc<String>,
|
pub host: Arc<String>,
|
||||||
|
|
|
@ -97,7 +97,7 @@ async fn get_tag_actor(
|
||||||
track_request("GET", "actor", "tag");
|
track_request("GET", "actor", "tag");
|
||||||
let target = actor::Actor {
|
let target = actor::Actor {
|
||||||
host: state.hostname.clone(),
|
host: state.hostname.clone(),
|
||||||
kind: actor::ActorKind::TagRelay(tag.to_lowercase()),
|
kind: actor::ActorKind::from_tag(&tag),
|
||||||
};
|
};
|
||||||
target.as_activitypub(&state.pub_key)
|
target.as_activitypub(&state.pub_key)
|
||||||
.into_response()
|
.into_response()
|
||||||
|
@ -123,7 +123,7 @@ async fn post_tag_relay(
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let target = actor::Actor {
|
let target = actor::Actor {
|
||||||
host: state.hostname.clone(),
|
host: state.hostname.clone(),
|
||||||
kind: actor::ActorKind::TagRelay(tag.to_lowercase()),
|
kind: actor::ActorKind::from_tag(&tag),
|
||||||
};
|
};
|
||||||
post_relay(state, endpoint, target).await
|
post_relay(state, endpoint, target).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl Post<'_> {
|
||||||
vec![],
|
vec![],
|
||||||
Some(tags) =>
|
Some(tags) =>
|
||||||
tags.iter()
|
tags.iter()
|
||||||
.map(|tag| tag.name.to_lowercase())
|
.map(|tag| tag.name.to_string())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ impl Post<'_> {
|
||||||
.chain(
|
.chain(
|
||||||
self.tags()
|
self.tags()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(actor::ActorKind::TagRelay)
|
.map(|ref s| actor::ActorKind::from_tag(s))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue