feat: move database logic to new structure

This commit is contained in:
PandaDEV 2024-12-11 14:53:01 +10:00
parent add822073e
commit c60f173e29
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
10 changed files with 198 additions and 352 deletions

View file

@ -0,0 +1,21 @@
use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use image::ImageFormat;
use reqwest;
use url::Url;
pub async fn fetch_favicon_as_base64(url: Url) -> Result<Option<String>, Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let favicon_url = format!("https://favicone.com/{}", url.host_str().unwrap());
let response = client.get(&favicon_url).send().await?;
if response.status().is_success() {
let bytes = response.bytes().await?;
let img = image::load_from_memory(&bytes)?;
let mut png_bytes: Vec<u8> = Vec::new();
img.write_to(&mut std::io::Cursor::new(&mut png_bytes), ImageFormat::Png)?;
Ok(Some(STANDARD.encode(&png_bytes)))
} else {
Ok(None)
}
}