From 69a299495dd69fdca39739376529877c1a6bd6de Mon Sep 17 00:00:00 2001 From: blank X Date: Mon, 26 Oct 2020 18:28:39 +0700 Subject: [PATCH] speed and stuff --- src/commands/search.rs | 10 ++++------ src/commands/view.rs | 8 ++++---- src/structs.rs | 8 ++++---- src/utils.rs | 5 ----- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/commands/search.rs b/src/commands/search.rs index 3867b24..c9d36d0 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -20,12 +20,10 @@ pub async fn run(args: env::Args) { exit(1); } for result in search_info.result { - let text; - if result.title.english != "" { - text = result.title.english; - } else { - text = result.title.japanese; + let mut title = &result.title.english.unwrap_or_default(); + if title == "" { + title = &result.title.japanese.as_ref().unwrap(); } - println!("{}: {}", result.id, text); + println!("{}: {}", result.id, &title); } } diff --git a/src/commands/view.rs b/src/commands/view.rs index dbe8e10..93a3b62 100644 --- a/src/commands/view.rs +++ b/src/commands/view.rs @@ -21,11 +21,11 @@ pub async fn run(args: env::Args) { handles.push(tokio::spawn(async move { let sauce_info = utils::get_sauce_info(cloned_client, sauce).await.unwrap(); let mut text = format!("Sauce: {}\nTitle: ", sauce_info.id); - let english_title = sauce_info.title.english; - let japanese_title = sauce_info.title.japanese; - if english_title != "" { + let japanese_title = &sauce_info.title.japanese.unwrap_or_default(); + let english_title = &sauce_info.title.english.unwrap_or_default(); + if english_title.as_str() != "" { text.push_str(&english_title); - if japanese_title != "" { + if japanese_title.as_str() != "" { text.push_str(&format!("\nJapanese Title: {}", &japanese_title)); } } else { diff --git a/src/structs.rs b/src/structs.rs index e44fdd9..d001a00 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -2,9 +2,9 @@ use serde::Deserialize; #[derive(Deserialize, Debug)] pub struct GalleryTitleInfo { - pub english: String, - pub japanese: String, - pub pretty: String, + pub english: Option, + pub japanese: Option, + pub pretty: Option, } #[derive(Deserialize, Debug)] @@ -17,7 +17,7 @@ pub struct GalleryImageInfo { #[derive(Deserialize, Debug)] pub struct GalleryImagesInfo { pub pages: Vec, - pub cover: GalleryImageInfo, + pub cover: GalleryImageInfo, pub thumbnail: GalleryImageInfo } diff --git a/src/utils.rs b/src/utils.rs index 63c701b..1fa6f57 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,11 +13,6 @@ fn fix_gallery(body: &mut serde_json::Value) -> Result<(), serde_json::Error> { body["id"].as_str().unwrap().parse::().unwrap() ); } - for title in ["english", "japanese", "pretty"].iter() { - if body["title"][title].is_null() { - body["title"][title] = serde_json::json!("") - } - } Ok(()) }