immich-tools/src/commands/delete_albums.rs

31 lines
801 B
Rust

use crate::{
actions::{
action::Action,
confirm::{Confirm, ConfirmResult},
delete_album::DeleteAlbum,
fetch_all_albums::FetchAllAlbums,
},
context::Context,
};
use color_eyre::eyre::Result;
use log::info;
pub async fn delete_albums(ctx: Context, empty: bool) -> Result<()> {
let mut albums = FetchAllAlbums::new(()).execute(&ctx).await?;
albums.retain(|album| !empty || album.assets_count == 0);
if let ConfirmResult::Positive = Confirm::new(None).execute(&ctx).await? {
for album in &albums {
DeleteAlbum::new(album.clone()).execute(&ctx).await?;
}
info!(
"Deleted {} albums{}",
albums.len(),
if ctx.dry_run { " (dry run)" } else { "" }
);
}
Ok(())
}