From 6baf256f09d44c7ac19dd1cdc956fbebae1ffedf Mon Sep 17 00:00:00 2001 From: Syfaro Date: Wed, 14 Oct 2020 11:33:29 -0400 Subject: [PATCH] Fix loading front page. --- src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9aca4ee..7e36b30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ enum WeasylResponse { } async fn load_frontpage(client: &reqwest::Client, api_key: &str) -> anyhow::Result { - let resp: WeasylResponse> = client + let resp: WeasylResponse> = client .get("https://www.weasyl.com/api/submissions/frontpage") .header("X-Weasyl-API-Key", api_key) .send() @@ -63,9 +63,13 @@ async fn load_frontpage(client: &reqwest::Client, api_key: &str) -> anyhow::Resu } => return Err(anyhow::anyhow!(name)), }; - let max = subs.into_iter().max_by_key(|sub| sub.id); + let max = subs + .into_iter() + .filter_map(|sub| sub.get("submitid").and_then(|id| id.as_i64())) + .max() + .unwrap_or_default(); - Ok(max.map(|sub| sub.id).unwrap_or_default()) + Ok(max as i32) } async fn load_submission(