1
0
Fork 0
esix-client/src-tauri/src/main.rs

56 lines
1.7 KiB
Rust
Raw Normal View History

2024-02-17 01:29:25 +00:00
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use r621::client::{Authentication, Client};
use tauri::State;
use tokio::sync::Mutex;
use std::sync::Arc;
use r621::prelude::Post;
#[tauri::command]
async fn get_posts(query: Option<String>, arcmut_esix_client: State<'_, Arc<Mutex<Client>>>) -> anyhow::Result<Vec<Post>, String> {
let mut esix_client = arcmut_esix_client.lock().await;
match esix_client.list_posts(None, query, None).await {
Ok(res) => {
return Ok(res);
}
Err(err) => {
eprintln!("{err}");
return Err(format!("{err}"));
}
}
}
2024-03-18 01:20:50 +00:00
#[tauri::command]
async fn get_post(post_id: u64, arcmut_esix_client: State<'_, Arc<Mutex<Client>>>) -> anyhow::Result<Post, String> {
let mut esix_client = arcmut_esix_client.lock().await;
match esix_client.get_post(post_id).await {
Ok(res) => {
return Ok(res);
}
Err(err) => {
eprintln!("{err}");
return Err(format!("{err}"));
}
}
}
2024-02-17 01:29:25 +00:00
#[tokio::main]
async fn main() {
let user_agent = "eSixClient/1.0 (by pixelhunter on e621)";
let auth = Authentication::Authorized {
username: "pixelhunter",
apikey: "P4pzvnfLSjhQdgCmMfZ8HwUy"
};
let esix_client = Client::new(auth, user_agent).expect("Could not create esix client");
let arcmut_esix_client = Arc::new(Mutex::new(esix_client));
tauri::Builder::default()
2024-03-18 01:20:50 +00:00
.invoke_handler(tauri::generate_handler![get_posts, get_post])
2024-02-17 01:29:25 +00:00
.manage(arcmut_esix_client.clone())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}