proper fix plus delete artist actually removes files
This commit is contained in:
@@ -840,13 +840,28 @@ async fn delete_artist(
|
|||||||
let id = path.into_inner();
|
let id = path.into_inner();
|
||||||
let conn = state.db.conn();
|
let conn = state.db.conn();
|
||||||
|
|
||||||
// Cascade: remove wanted items, tracks (DB only), albums, cache, then artist
|
// Get tracks before deleting so we can remove files from disk
|
||||||
|
let tracks = queries::tracks::get_by_artist(conn, id).await?;
|
||||||
|
let library_path = state.config.read().await.library_path.clone();
|
||||||
|
|
||||||
|
// Cascade: remove wanted items, tracks, albums, cache, then artist
|
||||||
queries::wanted::remove_by_artist(conn, id).await?;
|
queries::wanted::remove_by_artist(conn, id).await?;
|
||||||
queries::tracks::delete_by_artist(conn, id).await?;
|
queries::tracks::delete_by_artist(conn, id).await?;
|
||||||
queries::albums::delete_by_artist(conn, id).await?;
|
queries::albums::delete_by_artist(conn, id).await?;
|
||||||
let _ = queries::cache::purge_prefix(conn, &format!("artist_totals:{id}")).await;
|
let _ = queries::cache::purge_prefix(conn, &format!("artist_totals:{id}")).await;
|
||||||
queries::artists::delete(conn, id).await?;
|
queries::artists::delete(conn, id).await?;
|
||||||
|
|
||||||
|
// Delete files from disk and clean up empty directories
|
||||||
|
for track in &tracks {
|
||||||
|
let path = std::path::Path::new(&track.file_path);
|
||||||
|
if path.exists() {
|
||||||
|
let _ = std::fs::remove_file(path);
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
shanty_org::cleanup_empty_dirs(parent, &library_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(HttpResponse::NoContent().finish())
|
Ok(HttpResponse::NoContent().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user