Update to artist credit handling
This commit is contained in:
@@ -162,14 +162,38 @@ async fn add_album(
|
||||
if body.artist.is_none() && body.album.is_none() && body.mbid.is_none() {
|
||||
return Err(ApiError::BadRequest("provide artist+album or mbid".into()));
|
||||
}
|
||||
let summary = shanty_watch::add_album(
|
||||
|
||||
// Try adding with the given MBID first. If it fails (e.g., the MBID is a release-group,
|
||||
// not a release), resolve it to an actual release MBID and retry.
|
||||
let mut mbid = body.mbid.clone();
|
||||
let result = shanty_watch::add_album(
|
||||
state.db.conn(),
|
||||
body.artist.as_deref(),
|
||||
body.album.as_deref(),
|
||||
body.mbid.as_deref(),
|
||||
mbid.as_deref(),
|
||||
&state.mb_client,
|
||||
)
|
||||
.await?;
|
||||
.await;
|
||||
|
||||
let summary = match result {
|
||||
Ok(s) => s,
|
||||
Err(_) if mbid.is_some() => {
|
||||
// MBID might be a release-group — resolve to the first release
|
||||
let rg_mbid = mbid.as_deref().unwrap();
|
||||
let release_mbid = resolve_release_from_group(&state, rg_mbid).await?;
|
||||
mbid = Some(release_mbid);
|
||||
shanty_watch::add_album(
|
||||
state.db.conn(),
|
||||
body.artist.as_deref(),
|
||||
body.album.as_deref(),
|
||||
mbid.as_deref(),
|
||||
&state.mb_client,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||
"tracks_added": summary.tracks_added,
|
||||
"tracks_already_owned": summary.tracks_already_owned,
|
||||
|
||||
Reference in New Issue
Block a user