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(()) }