Merge branch 'delete-empty-albums' into 'main'
Add an option to delete only empty albums See merge request kernald/immich-tools!28
This commit is contained in:
		
						commit
						18194dd964
					
				
					 3 changed files with 10 additions and 4 deletions
				
			
		| 
						 | 
					@ -87,7 +87,11 @@ pub(crate) enum AlbumsCommands {
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    /// Delete all albums
 | 
					    /// Delete all albums
 | 
				
			||||||
    #[serde(rename = "delete")]
 | 
					    #[serde(rename = "delete")]
 | 
				
			||||||
    Delete {},
 | 
					    Delete {
 | 
				
			||||||
 | 
					        /// Delete only empty albums
 | 
				
			||||||
 | 
					        #[arg(short, long, action)]
 | 
				
			||||||
 | 
					        empty: bool,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    /// List all albums
 | 
					    /// List all albums
 | 
				
			||||||
    #[serde(rename = "list")]
 | 
					    #[serde(rename = "list")]
 | 
				
			||||||
    List {},
 | 
					    List {},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,8 +10,10 @@ use crate::{
 | 
				
			||||||
use color_eyre::eyre::Result;
 | 
					use color_eyre::eyre::Result;
 | 
				
			||||||
use log::info;
 | 
					use log::info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub async fn delete_albums(ctx: Context) -> Result<()> {
 | 
					pub async fn delete_albums(ctx: Context, empty: bool) -> Result<()> {
 | 
				
			||||||
    let albums = FetchAllAlbums::new(()).execute(&ctx).await?;
 | 
					    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? {
 | 
					    if let ConfirmResult::Positive = Confirm::new(None).execute(&ctx).await? {
 | 
				
			||||||
        for album in &albums {
 | 
					        for album in &albums {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,7 +83,7 @@ async fn main() -> Result<()> {
 | 
				
			||||||
            AlbumsCommands::AutoCreate {
 | 
					            AlbumsCommands::AutoCreate {
 | 
				
			||||||
                album_name_separator,
 | 
					                album_name_separator,
 | 
				
			||||||
            } => auto_create_albums(ctx, album_name_separator.to_string()).await,
 | 
					            } => auto_create_albums(ctx, album_name_separator.to_string()).await,
 | 
				
			||||||
            AlbumsCommands::Delete {} => delete_albums(ctx).await,
 | 
					            AlbumsCommands::Delete { empty } => delete_albums(ctx, *empty).await,
 | 
				
			||||||
            AlbumsCommands::List {} => list_albums(ctx).await,
 | 
					            AlbumsCommands::List {} => list_albums(ctx).await,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        Commands::Assets { assets_command } => match assets_command {
 | 
					        Commands::Assets { assets_command } => match assets_command {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue