Fix loading front page.

This commit is contained in:
Syfaro 2020-10-14 11:33:29 -04:00
parent 41a993d0b1
commit 6baf256f09

View File

@ -48,7 +48,7 @@ enum WeasylResponse<T> {
} }
async fn load_frontpage(client: &reqwest::Client, api_key: &str) -> anyhow::Result<i32> { async fn load_frontpage(client: &reqwest::Client, api_key: &str) -> anyhow::Result<i32> {
let resp: WeasylResponse<Vec<WeasylFrontpageSubmission>> = client let resp: WeasylResponse<Vec<serde_json::Value>> = client
.get("https://www.weasyl.com/api/submissions/frontpage") .get("https://www.weasyl.com/api/submissions/frontpage")
.header("X-Weasyl-API-Key", api_key) .header("X-Weasyl-API-Key", api_key)
.send() .send()
@ -63,9 +63,13 @@ async fn load_frontpage(client: &reqwest::Client, api_key: &str) -> anyhow::Resu
} => return Err(anyhow::anyhow!(name)), } => 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( async fn load_submission(