feat: respect CN API for getting background image

This commit is contained in:
Nikita Podvirnyi 2024-06-17 14:01:31 +02:00
parent d0f731d68f
commit b529f3e7da
No known key found for this signature in database
GPG key ID: 859D416E5142AFF3

View file

@ -32,7 +32,12 @@ pub fn get_background_info() -> anyhow::Result<Background> {
let uri = json["data"]["game_info_list"].as_array() let uri = json["data"]["game_info_list"].as_array()
.ok_or_else(|| anyhow::anyhow!("Failed to list games in the backgrounds API"))? .ok_or_else(|| anyhow::anyhow!("Failed to list games in the backgrounds API"))?
.iter() .iter()
.find(|game| game["game"]["biz"].as_str() == Some("hk4e_global")) .find(|game| {
match game["game"]["biz"].as_str() {
Some(biz) => biz.starts_with("hk4e_"),
_ => false
}
})
.ok_or_else(|| anyhow::anyhow!("Failed to find the game in the backgrounds API"))?["backgrounds"] .ok_or_else(|| anyhow::anyhow!("Failed to find the game in the backgrounds API"))?["backgrounds"]
.as_array() .as_array()
.and_then(|backgrounds| backgrounds.iter().next()) .and_then(|backgrounds| backgrounds.iter().next())