Include description field (if it is under 150 chars)

This commit is contained in:
Felix Ableitner 2021-04-27 14:57:30 +02:00
parent 1751035334
commit d92de61d9c
2 changed files with 10 additions and 1 deletions

View file

@ -50,6 +50,7 @@ pub async fn crawl(
pub struct InstanceDetails {
pub domain: String,
pub name: String,
pub description: Option<String>,
pub version: String,
pub icon: Option<String>,
pub online_users: i32,
@ -99,7 +100,7 @@ async fn fetch_instance_details(domain: &str) -> Result<InstanceDetails, Error>
let node_info: NodeInfo = node_info.json().await?;
let site_info_v2 = site_info_v2.json::<GetSiteResponse>().await.ok();
let site_info_v3 = site_info_v3.json::<GetSiteResponse>().await.ok();
let site_info: GetSiteResponse = if let Some(site_info_v2) = site_info_v2 {
let mut site_info: GetSiteResponse = if let Some(site_info_v2) = site_info_v2 {
site_info_v2
} else if let Some(site_info_v3) = site_info_v3 {
site_info_v3
@ -107,6 +108,12 @@ async fn fetch_instance_details(domain: &str) -> Result<InstanceDetails, Error>
return Err(anyhow!("Failed to read site_info"));
};
if let Some(description) = &site_info.site_view.site.description {
if description.len() > 150 {
site_info.site_view.site.description = None;
}
}
let linked_instances = site_info
.federated_instances
.map(|f| f.linked)
@ -114,6 +121,7 @@ async fn fetch_instance_details(domain: &str) -> Result<InstanceDetails, Error>
Ok(InstanceDetails {
domain: domain.to_owned(),
name: site_info.site_view.site.name,
description: site_info.site_view.site.description,
version: node_info.software.version,
icon: site_info.site_view.site.icon,
online_users: site_info.online as i32,

View file

@ -23,4 +23,5 @@ pub struct SiteView {
pub struct Site {
pub name: String,
pub icon: Option<String>,
pub description: Option<String>,
}