Json
This commit is contained in:
parent
052251be03
commit
07d86cf9a1
@ -19,12 +19,18 @@ fn os_info() -> String {
|
|||||||
|
|
||||||
//TODO make this return a JS object
|
//TODO make this return a JS object
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn quote() -> String {
|
async fn quote() -> serde_json::Value {
|
||||||
let Ok(res) = reqwest::get("https://perl.is/random").await else { return "ERROR".to_string() };
|
let Ok(res) = reqwest::get("https://perl.is/random").await else { return serde_json::json!({"error": "ERROR".to_string()}) };
|
||||||
println!("Status: {}", res.status());
|
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]
|
#[tauri::command]
|
||||||
|
@ -14,7 +14,9 @@ async function os_info(elem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function get_quote(elem) {
|
async function get_quote(elem) {
|
||||||
elem.textContent = await invoke("quote", {});
|
const output = await invoke("quote", {});
|
||||||
|
console.log(output);
|
||||||
|
elem.textContent = output.response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user