immich-tools/src/actions/add_assets_to_album.rs

58 lines
1.2 KiB
Rust

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(())
}
}