From 33e23eaba049e84d69629644e0accf3dde7182ba Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 2 Aug 2024 21:06:37 +0200 Subject: [PATCH] fix ordering panic --- src/route/album.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/route/album.rs b/src/route/album.rs index 02adc45..a385a26 100644 --- a/src/route/album.rs +++ b/src/route/album.rs @@ -26,11 +26,14 @@ pub async fn albums_route(artist_id: &str, lib: &State) -> FallibleApiRe } fn sort_by_tracknumber(a: &serde_json::Value, b: &serde_json::Value) -> Ordering { - a.get("tracknumber") - .unwrap() - .as_i64() - .unwrap() - .cmp(&b.get("tracknumber").unwrap().as_i64().unwrap()) + let order = (|| { + Some( + a.get("tracknumber")? + .as_i64()? + .cmp(&b.get("tracknumber")?.as_i64()?), + ) + })(); + order.unwrap_or(Ordering::Equal) } #[get("/album//cover")]