Add a album auto-create command

This commit is contained in:
Marc Plano-Lesay 2024-12-03 16:32:05 +11:00
parent 998bfce68f
commit 0ac02c34c6
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
14 changed files with 323 additions and 2 deletions

View file

@ -0,0 +1,58 @@
use color_eyre::eyre::Result;
use log::info;
use crate::{
context::Context,
models::{album::Album, asset::Asset},
types::BulkIdsDto,
};
use super::action::Action;
pub struct AddAssetsToAlbum {
album: Album,
assets: Vec<Asset>,
}
pub struct AddAssetsToAlbumArgs {
pub album: Album,
pub assets: Vec<Asset>,
}
impl Action for AddAssetsToAlbum {
type Input = AddAssetsToAlbumArgs;
type Output = ();
fn new(input: Self::Input) -> Self {
Self {
album: input.album,
assets: input.assets,
}
}
fn describe(&self) -> String {
format!(
"Adding {} assets to album {}",
self.assets.len(),
self.album.name,
)
}
async fn execute(&self, ctx: &Context) -> Result<Self::Output> {
info!("{}", self.describe());
if !ctx.dry_run {
ctx.client
.add_assets_to_album(
&self.album.id,
None,
&BulkIdsDto {
ids: self.assets.iter().map(|asset| asset.id).collect(),
},
)
.await?;
}
Ok(())
}
}