Merge branch 'list-albums' into 'main'
Add a command to list albums See merge request kernald/immich-tools!24
This commit is contained in:
commit
351c1357c8
5 changed files with 61 additions and 1 deletions
15
src/args.rs
15
src/args.rs
|
@ -36,6 +36,14 @@ pub(crate) struct Opts {
|
||||||
|
|
||||||
#[derive(Serialize, Subcommand)]
|
#[derive(Serialize, Subcommand)]
|
||||||
pub(crate) enum Commands {
|
pub(crate) enum Commands {
|
||||||
|
/// Albums related commands
|
||||||
|
#[serde(rename = "albums")]
|
||||||
|
Albums {
|
||||||
|
#[command(subcommand)]
|
||||||
|
#[serde(flatten)]
|
||||||
|
albums_command: AlbumsCommands,
|
||||||
|
},
|
||||||
|
|
||||||
/// Assets related commands
|
/// Assets related commands
|
||||||
#[serde(rename = "assets")]
|
#[serde(rename = "assets")]
|
||||||
Assets {
|
Assets {
|
||||||
|
@ -68,6 +76,13 @@ pub(crate) enum Commands {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Subcommand)]
|
||||||
|
pub(crate) enum AlbumsCommands {
|
||||||
|
/// List all albums
|
||||||
|
#[serde(rename = "list")]
|
||||||
|
List {},
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Subcommand)]
|
#[derive(Serialize, Subcommand)]
|
||||||
pub(crate) enum AssetsCommands {
|
pub(crate) enum AssetsCommands {
|
||||||
/// Delete all assets
|
/// Delete all assets
|
||||||
|
|
35
src/commands/list_albums.rs
Normal file
35
src/commands/list_albums.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
use crate::{
|
||||||
|
actions::{action::Action, fetch_all_albums::FetchAllAlbums},
|
||||||
|
context::Context,
|
||||||
|
};
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
|
use tabled::{settings::Style, Table, Tabled};
|
||||||
|
#[derive(Tabled)]
|
||||||
|
struct Album {
|
||||||
|
#[tabled(rename = "Name")]
|
||||||
|
name: String,
|
||||||
|
#[tabled(rename = "Assets count")]
|
||||||
|
assets_count: u32,
|
||||||
|
#[tabled(rename = "Updated at")]
|
||||||
|
updated_at: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn list_albums(ctx: Context) -> Result<()> {
|
||||||
|
let mut albums: Vec<_> = FetchAllAlbums::new(())
|
||||||
|
.execute(&ctx)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|album| Album {
|
||||||
|
name: album.name,
|
||||||
|
updated_at: album.updated_at,
|
||||||
|
assets_count: album.assets_count,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
albums.sort_by_key(|album| album.name.to_lowercase());
|
||||||
|
|
||||||
|
println!("{}", Table::new(albums).with(Style::rounded()),);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod delete_assets;
|
pub mod delete_assets;
|
||||||
|
pub mod list_albums;
|
||||||
pub mod list_assets;
|
pub mod list_assets;
|
||||||
pub mod missing_date_of_birth;
|
pub mod missing_date_of_birth;
|
||||||
pub mod scan_libraries;
|
pub mod scan_libraries;
|
||||||
|
|
|
@ -9,11 +9,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::args::Commands;
|
use crate::args::Commands;
|
||||||
use args::{AssetsCommands, LibrariesCommands, PeopleCommands, ServerCommands};
|
use args::{AlbumsCommands, AssetsCommands, LibrariesCommands, PeopleCommands, ServerCommands};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use color_eyre::eyre::{Result, WrapErr};
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
use color_eyre::Section;
|
use color_eyre::Section;
|
||||||
use commands::delete_assets::delete_assets;
|
use commands::delete_assets::delete_assets;
|
||||||
|
use commands::list_albums::list_albums;
|
||||||
use commands::list_assets::list_assets;
|
use commands::list_assets::list_assets;
|
||||||
use commands::missing_date_of_birth::missing_date_of_birth;
|
use commands::missing_date_of_birth::missing_date_of_birth;
|
||||||
use commands::scan_libraries::scan_libraries;
|
use commands::scan_libraries::scan_libraries;
|
||||||
|
@ -76,6 +77,9 @@ async fn main() -> Result<()> {
|
||||||
validate_client_connection(&ctx.client).await?;
|
validate_client_connection(&ctx.client).await?;
|
||||||
|
|
||||||
match &args.command {
|
match &args.command {
|
||||||
|
Commands::Albums { albums_command } => match albums_command {
|
||||||
|
AlbumsCommands::List {} => list_albums(ctx).await,
|
||||||
|
},
|
||||||
Commands::Assets { assets_command } => match assets_command {
|
Commands::Assets { assets_command } => match assets_command {
|
||||||
AssetsCommands::Delete { offline } => delete_assets(ctx, *offline).await,
|
AssetsCommands::Delete { offline } => delete_assets(ctx, *offline).await,
|
||||||
AssetsCommands::List { offline } => list_assets(ctx, *offline).await,
|
AssetsCommands::List { offline } => list_assets(ctx, *offline).await,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use chrono::{DateTime, NaiveDate, Utc};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::types::AlbumResponseDto;
|
use crate::types::AlbumResponseDto;
|
||||||
|
@ -6,6 +7,8 @@ use crate::types::AlbumResponseDto;
|
||||||
pub struct Album {
|
pub struct Album {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub updated_at: DateTime<Utc>,
|
||||||
|
pub assets_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AlbumResponseDto> for Album {
|
impl From<AlbumResponseDto> for Album {
|
||||||
|
@ -13,6 +16,8 @@ impl From<AlbumResponseDto> for Album {
|
||||||
Self {
|
Self {
|
||||||
id: Uuid::parse_str(&value.id).expect("Unable to parse an album's UUID"),
|
id: Uuid::parse_str(&value.id).expect("Unable to parse an album's UUID"),
|
||||||
name: value.album_name,
|
name: value.album_name,
|
||||||
|
updated_at: value.updated_at,
|
||||||
|
assets_count: value.asset_count as u32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue