55 lines
1.7 KiB
Rust
55 lines
1.7 KiB
Rust
// 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}"));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[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}"));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[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()
|
|
.invoke_handler(tauri::generate_handler![get_posts, get_post])
|
|
.manage(arcmut_esix_client.clone())
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|
|
|