forked from mirrors/relay
Prefer short_description, add more telegram meta commands
This commit is contained in:
parent
1f87c0f913
commit
d7e9e58de2
5 changed files with 58 additions and 31 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -279,7 +279,7 @@ checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ap-relay"
|
name = "ap-relay"
|
||||||
version = "0.3.31"
|
version = "0.3.32"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitystreams",
|
"activitystreams",
|
||||||
"activitystreams-ext",
|
"activitystreams-ext",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ap-relay"
|
name = "ap-relay"
|
||||||
description = "A simple activitypub relay"
|
description = "A simple activitypub relay"
|
||||||
version = "0.3.31"
|
version = "0.3.32"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
12
src/db.rs
12
src/db.rs
|
@ -142,6 +142,14 @@ impl Inner {
|
||||||
.map(|s| String::from_utf8_lossy(&s).to_string())
|
.map(|s| String::from_utf8_lossy(&s).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn allowed(&self) -> impl DoubleEndedIterator<Item = String> {
|
||||||
|
self.allowed_domains
|
||||||
|
.iter()
|
||||||
|
.values()
|
||||||
|
.filter_map(|res| res.ok())
|
||||||
|
.map(|s| String::from_utf8_lossy(&s).to_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn connected(&self) -> impl DoubleEndedIterator<Item = IriString> {
|
fn connected(&self) -> impl DoubleEndedIterator<Item = IriString> {
|
||||||
self.connected_actor_ids
|
self.connected_actor_ids
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -273,6 +281,10 @@ impl Db {
|
||||||
self.unblock(|inner| Ok(inner.connected().collect())).await
|
self.unblock(|inner| Ok(inner.connected().collect())).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn allowed_domains(&self) -> Result<Vec<String>, Error> {
|
||||||
|
self.unblock(|inner| Ok(inner.allowed().collect())).await
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn save_info(&self, actor_id: IriString, info: Info) -> Result<(), Error> {
|
pub(crate) async fn save_info(&self, actor_id: IriString, info: Info) -> Result<(), Error> {
|
||||||
self.unblock(move |inner| {
|
self.unblock(move |inner| {
|
||||||
let vec = serde_json::to_vec(&info)?;
|
let vec = serde_json::to_vec(&info)?;
|
||||||
|
|
|
@ -52,22 +52,17 @@ impl QueryInstance {
|
||||||
.fetch_json::<Instance>(instance_uri.as_str())
|
.fetch_json::<Instance>(instance_uri.as_str())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let description = if instance.description.is_empty() {
|
let description = instance.short_description.unwrap_or(instance.description);
|
||||||
instance.short_description.unwrap_or_default()
|
|
||||||
} else {
|
|
||||||
instance.description
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(mut contact) = instance.contact {
|
if let Some(contact) = instance.contact {
|
||||||
let uuid = if let Some(uuid) = state.media.get_uuid(contact.avatar.clone()).await? {
|
let uuid = if let Some(uuid) = state.media.get_uuid(contact.avatar.clone()).await? {
|
||||||
contact.avatar = state.config.generate_url(UrlKind::Media(uuid));
|
|
||||||
uuid
|
uuid
|
||||||
} else {
|
} else {
|
||||||
let uuid = state.media.store_url(contact.avatar.clone()).await?;
|
state.media.store_url(contact.avatar).await?
|
||||||
contact.avatar = state.config.generate_url(UrlKind::Media(uuid));
|
|
||||||
uuid
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let avatar = state.config.generate_url(UrlKind::Media(uuid));
|
||||||
|
|
||||||
state.job_server.queue(CacheMedia::new(uuid)).await?;
|
state.job_server.queue(CacheMedia::new(uuid)).await?;
|
||||||
|
|
||||||
state
|
state
|
||||||
|
@ -77,7 +72,7 @@ impl QueryInstance {
|
||||||
contact.username,
|
contact.username,
|
||||||
contact.display_name,
|
contact.display_name,
|
||||||
contact.url,
|
contact.url,
|
||||||
contact.avatar,
|
avatar,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +82,7 @@ impl QueryInstance {
|
||||||
state
|
state
|
||||||
.node_cache
|
.node_cache
|
||||||
.set_instance(
|
.set_instance(
|
||||||
self.actor_id.clone(),
|
self.actor_id,
|
||||||
instance.title,
|
instance.title,
|
||||||
description,
|
description,
|
||||||
instance.version,
|
instance.version,
|
||||||
|
|
|
@ -31,6 +31,15 @@ enum Command {
|
||||||
|
|
||||||
#[command(description = "Disallow a domain to connect to the relay (for RESTRICTED_MODE)")]
|
#[command(description = "Disallow a domain to connect to the relay (for RESTRICTED_MODE)")]
|
||||||
Disallow { domain: String },
|
Disallow { domain: String },
|
||||||
|
|
||||||
|
#[command(description = "List blocked domains")]
|
||||||
|
ListBlocks,
|
||||||
|
|
||||||
|
#[command(description = "List allowed domains")]
|
||||||
|
ListAllowed,
|
||||||
|
|
||||||
|
#[command(description = "List connected domains")]
|
||||||
|
ListConnected,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start(admin_handle: String, db: Db, token: &str) {
|
pub(crate) fn start(admin_handle: String, db: Db, token: &str) {
|
||||||
|
@ -79,29 +88,40 @@ async fn answer(bot: Bot, msg: Message, cmd: Command, db: Db) -> ResponseResult<
|
||||||
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Command::Block { domain } => {
|
Command::Block { domain } if db.add_blocks(vec![domain.clone()]).await.is_ok() => {
|
||||||
if db.add_blocks(vec![domain.clone()]).await.is_ok() {
|
bot.send_message(msg.chat.id, format!("{} has been blocked", domain))
|
||||||
bot.send_message(msg.chat.id, format!("{} has been blocked", domain))
|
.await?;
|
||||||
.await?;
|
}
|
||||||
|
Command::Unblock { domain } if db.remove_blocks(vec![domain.clone()]).await.is_ok() => {
|
||||||
|
bot.send_message(msg.chat.id, format!("{} has been unblocked", domain))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Command::Allow { domain } if db.add_allows(vec![domain.clone()]).await.is_ok() => {
|
||||||
|
bot.send_message(msg.chat.id, format!("{} has been allowed", domain))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Command::Disallow { domain } if db.remove_allows(vec![domain.clone()]).await.is_ok() => {
|
||||||
|
bot.send_message(msg.chat.id, format!("{} has been disallowed", domain))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Command::ListAllowed => {
|
||||||
|
if let Ok(allowed) = db.allowed_domains().await {
|
||||||
|
bot.send_message(msg.chat.id, allowed.join("\n")).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::Unblock { domain } => {
|
Command::ListBlocks => {
|
||||||
if db.remove_blocks(vec![domain.clone()]).await.is_ok() {
|
if let Ok(blocks) = db.blocks().await {
|
||||||
bot.send_message(msg.chat.id, format!("{} has been unblocked", domain))
|
bot.send_message(msg.chat.id, blocks.join("\n")).await?;
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::Allow { domain } => {
|
Command::ListConnected => {
|
||||||
if db.add_allows(vec![domain.clone()]).await.is_ok() {
|
if let Ok(connected) = db.connected_ids().await {
|
||||||
bot.send_message(msg.chat.id, format!("{} has been allowed", domain))
|
bot.send_message(msg.chat.id, connected.join("\n")).await?;
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::Disallow { domain } => {
|
_ => {
|
||||||
if db.remove_allows(vec![domain.clone()]).await.is_ok() {
|
bot.send_message(msg.chat.id, "Internal server error")
|
||||||
bot.send_message(msg.chat.id, format!("{} has been disallowed", domain))
|
.await?;
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue