This commit is contained in:
Greg Shuflin
2024-11-04 16:40:33 -08:00
parent 052251be03
commit 07d86cf9a1
2 changed files with 13 additions and 5 deletions

View File

@@ -19,12 +19,18 @@ fn os_info() -> String {
//TODO make this return a JS object
#[tauri::command]
async fn quote() -> String {
let Ok(res) = reqwest::get("https://perl.is/random").await else { return "ERROR".to_string() };
async fn quote() -> serde_json::Value {
let Ok(res) = reqwest::get("https://perl.is/random").await else { return serde_json::json!({"error": "ERROR".to_string()}) };
println!("Status: {}", res.status());
let Ok(text) = res.text().await else { return "TEXT ERROR".to_string() };
let Ok(text) = res.text().await else { return serde_json::json!({ "error": "TEXT ERROR".to_string() }) };
text
let value: serde_json::Value = serde_json::from_str(&text).unwrap();
let output = value.get("quote").and_then(|quote| quote.as_str()).unwrap();
serde_json::json!({
"response": output,
"code": 33
})
}
#[tauri::command]