From 751d19f4f3f987d1e1bda2a148bc09cb50505c80 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Sat, 13 May 2023 14:53:12 +0200 Subject: [PATCH] Call readpicture when albumart doesnt return art --- src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d4dc452..43ac3bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -186,7 +186,19 @@ async fn post_queue_move(mut req: tide::Request<()>) -> tide::Result { async fn get_art(req: tide::Request<()>) -> tide::Result { let query: IndexQuery = req.query()?; let path = percent_decode_str(&query.path).decode_utf8_lossy(); - let resp = if let Ok(art) = mpd::connect()?.albumart(&path) { + + let mut mpd = mpd::Mpd::connect().await?; + + let resp = if let Ok(art) = mpd.albumart(&path).await { + let mime = infer::get(&art) + .map(|k| k.mime_type()) + .unwrap_or("application/octet-stream"); + + tide::Response::builder(tide::StatusCode::Ok) + .body(art) + .content_type(mime) + .header("cache-control", "max-age=3600") + } else if let Ok(art) = mpd.readpicture(&path).await { let mime = infer::get(&art) .map(|k| k.mime_type()) .unwrap_or("application/octet-stream"); @@ -198,6 +210,7 @@ async fn get_art(req: tide::Request<()>) -> tide::Result { } else { tide::Response::builder(tide::StatusCode::NotFound) }; + Ok(resp.into()) }