feat(rust): Add page metadata fetching command

This commit is contained in:
PandaDEV 2024-12-19 09:32:02 +10:00
parent 5943fc86fb
commit f105577608
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
2 changed files with 13 additions and 0 deletions

View file

@ -112,6 +112,7 @@ fn main() {
db::settings::save_setting, db::settings::save_setting,
db::settings::save_keybind, db::settings::save_keybind,
db::settings::get_keybind, db::settings::get_keybind,
utils::commands::fetch_page_meta,
]) ])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");

View file

@ -2,6 +2,7 @@ use active_win_pos_rs::get_active_window;
use base64::{engine::general_purpose::STANDARD, Engine}; use base64::{engine::general_purpose::STANDARD, Engine};
use image::codecs::png::PngEncoder; use image::codecs::png::PngEncoder;
use tauri::PhysicalPosition; use tauri::PhysicalPosition;
use meta_fetcher;
pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) { pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) {
if let Some(monitor) = window.available_monitors().unwrap().iter().find(|m| { if let Some(monitor) = window.available_monitors().unwrap().iter().find(|m| {
@ -95,3 +96,14 @@ pub fn detect_color(color: &str) -> bool {
false false
} }
#[tauri::command]
pub async fn fetch_page_meta(url: String) -> Result<(String, Option<String>), String> {
let metadata = meta_fetcher::fetch_metadata(&url)
.map_err(|e| format!("Failed to fetch metadata: {}", e))?;
Ok((
metadata.title.unwrap_or_else(|| "No title found".to_string()),
metadata.image
))
}