mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-22 13:44:05 +02:00
feat: move database logic to new structure
This commit is contained in:
parent
add822073e
commit
c60f173e29
10 changed files with 198 additions and 352 deletions
21
src-tauri/src/utils/favicon.rs
Normal file
21
src-tauri/src/utils/favicon.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue