mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-11-25 11:01:11 +00:00
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]]
|
||||
name = "ap-relay"
|
||||
version = "0.3.31"
|
||||
version = "0.3.32"
|
||||
dependencies = [
|
||||
"activitystreams",
|
||||
"activitystreams-ext",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "ap-relay"
|
||||
description = "A simple activitypub relay"
|
||||
version = "0.3.31"
|
||||
version = "0.3.32"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license = "AGPL-3.0"
|
||||
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())
|
||||
}
|
||||
|
||||
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> {
|
||||
self.connected_actor_ids
|
||||
.iter()
|
||||
|
@ -273,6 +281,10 @@ impl Db {
|
|||
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> {
|
||||
self.unblock(move |inner| {
|
||||
let vec = serde_json::to_vec(&info)?;
|
||||
|
|
|
@ -52,22 +52,17 @@ impl QueryInstance {
|
|||
.fetch_json::<Instance>(instance_uri.as_str())
|
||||
.await?;
|
||||
|
||||
let description = if instance.description.is_empty() {
|
||||
instance.short_description.unwrap_or_default()
|
||||
} else {
|
||||
instance.description
|
||||
};
|
||||
let description = instance.short_description.unwrap_or(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? {
|
||||
contact.avatar = state.config.generate_url(UrlKind::Media(uuid));
|
||||
uuid
|
||||
} else {
|
||||
let uuid = state.media.store_url(contact.avatar.clone()).await?;
|
||||
contact.avatar = state.config.generate_url(UrlKind::Media(uuid));
|
||||
uuid
|
||||
state.media.store_url(contact.avatar).await?
|
||||
};
|
||||
|
||||
let avatar = state.config.generate_url(UrlKind::Media(uuid));
|
||||
|
||||
state.job_server.queue(CacheMedia::new(uuid)).await?;
|
||||
|
||||
state
|
||||
|
@ -77,7 +72,7 @@ impl QueryInstance {
|
|||
contact.username,
|
||||
contact.display_name,
|
||||
contact.url,
|
||||
contact.avatar,
|
||||
avatar,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
@ -87,7 +82,7 @@ impl QueryInstance {
|
|||
state
|
||||
.node_cache
|
||||
.set_instance(
|
||||
self.actor_id.clone(),
|
||||
self.actor_id,
|
||||
instance.title,
|
||||
description,
|
||||
instance.version,
|
||||
|
|
|
@ -31,6 +31,15 @@ enum Command {
|
|||
|
||||
#[command(description = "Disallow a domain to connect to the relay (for RESTRICTED_MODE)")]
|
||||
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) {
|
||||
|
@ -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())
|
||||
.await?;
|
||||
}
|
||||
Command::Block { domain } => {
|
||||
if db.add_blocks(vec![domain.clone()]).await.is_ok() {
|
||||
bot.send_message(msg.chat.id, format!("{} has been blocked", domain))
|
||||
.await?;
|
||||
Command::Block { domain } if db.add_blocks(vec![domain.clone()]).await.is_ok() => {
|
||||
bot.send_message(msg.chat.id, format!("{} has been blocked", domain))
|
||||
.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 } => {
|
||||
if db.remove_blocks(vec![domain.clone()]).await.is_ok() {
|
||||
bot.send_message(msg.chat.id, format!("{} has been unblocked", domain))
|
||||
.await?;
|
||||
Command::ListBlocks => {
|
||||
if let Ok(blocks) = db.blocks().await {
|
||||
bot.send_message(msg.chat.id, blocks.join("\n")).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::ListConnected => {
|
||||
if let Ok(connected) = db.connected_ids().await {
|
||||
bot.send_message(msg.chat.id, connected.join("\n")).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?;
|
||||
}
|
||||
_ => {
|
||||
bot.send_message(msg.chat.id, "Internal server error")
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue