From d256834dd2ce0233de1037fe41e4fe92dfd22e91 Mon Sep 17 00:00:00 2001 From: NetworkCats Date: Fri, 6 Mar 2026 05:27:49 +0800 Subject: [PATCH] feat: link ASN to bgp.tools page --- src/handlers.rs | 10 +++++++--- templates/index.html | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 9747b09..3d36e33 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -37,6 +37,7 @@ struct IndexTemplate { site_domain: Arc, css_version: u64, asn: String, + asn_number: Option, org: String, country: String, city: String, @@ -182,10 +183,12 @@ fn wants_json(headers: &HeaderMap) -> bool { .is_some_and(|v| v.contains("application/json")) } +fn asn_number(info: &IpInfo) -> Option { + info.asn.as_ref().and_then(|a| a.autonomous_system_number) +} + fn format_asn(info: &IpInfo) -> String { - info.asn - .as_ref() - .and_then(|a| a.autonomous_system_number) + asn_number(info) .map(|n| format!("AS{n}")) .unwrap_or_default() } @@ -557,6 +560,7 @@ pub async fn root( site_domain: state.site_domain.clone(), css_version: static_assets::asset_version("style.css"), asn: format_asn(&info), + asn_number: asn_number(&info), org: format_org(&info).to_owned(), country: format_country(&info, locale).to_owned(), city: format_city(&info, locale).to_owned(), diff --git a/templates/index.html b/templates/index.html index 58eb10b..91014ae 100644 --- a/templates/index.html +++ b/templates/index.html @@ -39,7 +39,7 @@ {% if !asn.is_empty() %} {{ t_asn }} - {{ asn }} + {% if let Some(n) = asn_number %}{{ asn }}{% else %}{{ asn }}{% endif %} {% endif %} {% if !org.is_empty() %}