24 lines
717 B
Rust
24 lines
717 B
Rust
pub async fn download_favicon(domain: &str) -> Option<Vec<u8>> {
|
|
let mut favicon_url = url::Url::parse(&format!("https://{}", domain)).ok()?;
|
|
favicon_url.set_path("/favicon.ico");
|
|
|
|
log::info!("Fetching favicon from: {}", favicon_url);
|
|
|
|
let response = reqwest::get(favicon_url).await.ok()?;
|
|
|
|
if !response.status().is_success() {
|
|
return None;
|
|
}
|
|
|
|
let favicon_data = response.bytes().await.ok()?.to_vec();
|
|
|
|
Some(favicon_data)
|
|
}
|
|
|
|
pub async fn download_favicons_for_sites(sites: Vec<String>) {
|
|
for site in sites {
|
|
if let Some(fav) = download_favicon(&site).await {
|
|
std::fs::write(std::path::Path::new("./favicon").join(site), fav).unwrap();
|
|
}
|
|
}
|
|
}
|