diff --git a/src/api/icons.rs b/src/api/icons.rs index 5653bb1..f1916c3 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -17,8 +17,6 @@ pub fn routes() -> Vec { routes![icon] } -const FALLBACK_ICON: &[u8; 344] = include_bytes!("../static/fallback-icon.png"); - const ALLOWED_CHARS: &str = "_-."; static CLIENT: Lazy = Lazy::new(|| { @@ -52,15 +50,15 @@ fn is_valid_domain(domain: &str) -> bool { } #[get("//icon.png")] -fn icon(domain: String) -> Cached>> { - let icon_type = ContentType::new("image", "x-icon"); - +fn icon(domain: String) -> Option>>> { if !is_valid_domain(&domain) { warn!("Invalid domain: {:#?}", domain); - return Cached::long(Content(icon_type, FALLBACK_ICON.to_vec())); + return None; } - Cached::long(Content(icon_type, get_icon(&domain))) + get_icon(&domain).map(|icon| { + Cached::long(Content(ContentType::new("image", "x-icon"), icon)) + }) } /// TODO: This is extracted from IpAddr::is_global, which is unstable: @@ -190,29 +188,29 @@ fn check_icon_domain_is_blacklisted(domain: &str) -> bool { is_blacklisted } -fn get_icon(domain: &str) -> Vec { +fn get_icon(domain: &str) -> Option> { let path = format!("{}/{}.png", CONFIG.icon_cache_folder(), domain); if let Some(icon) = get_cached_icon(&path) { - return icon; + return Some(icon); } if CONFIG.disable_icon_download() { - return FALLBACK_ICON.to_vec(); + return None; } - // Get the icon, or fallback in case of error + // Get the icon, or None in case of error match download_icon(&domain) { Ok(icon) => { save_icon(&path, &icon); - icon + Some(icon) } Err(e) => { error!("Error downloading icon: {:?}", e); let miss_indicator = path + ".miss"; let empty_icon = Vec::new(); save_icon(&miss_indicator, &empty_icon); - FALLBACK_ICON.to_vec() + None } } } @@ -220,7 +218,7 @@ fn get_icon(domain: &str) -> Vec { fn get_cached_icon(path: &str) -> Option> { // Check for expiration of negatively cached copy if icon_is_negcached(path) { - return Some(FALLBACK_ICON.to_vec()); + return None; } // Check for expiration of successfully cached copy diff --git a/src/static/fallback-icon.png b/src/static/fallback-icon.png deleted file mode 100644 index 7ba709f..0000000 Binary files a/src/static/fallback-icon.png and /dev/null differ