Add a album auto-create command
This commit is contained in:
parent
998bfce68f
commit
0ac02c34c6
14 changed files with 323 additions and 2 deletions
58
src/actions/add_assets_to_album.rs
Normal file
58
src/actions/add_assets_to_album.rs
Normal 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(())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue