Add a album auto-create command
This commit is contained in:
parent
998bfce68f
commit
0ac02c34c6
14 changed files with 323 additions and 2 deletions
42
src/actions/fetch_library_assets.rs
Normal file
42
src/actions/fetch_library_assets.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use color_eyre::eyre::Result;
|
||||
|
||||
use crate::{
|
||||
context::Context,
|
||||
models::{asset::Asset, library::Library},
|
||||
utils::assets::{fetch_all_assets, AssetQuery},
|
||||
};
|
||||
|
||||
use super::action::Action;
|
||||
|
||||
pub struct FetchLibraryAssets {
|
||||
library: Library,
|
||||
}
|
||||
|
||||
impl Action for FetchLibraryAssets {
|
||||
type Input = Library;
|
||||
type Output = Vec<Asset>;
|
||||
|
||||
fn new(input: Self::Input) -> Self {
|
||||
Self { library: input }
|
||||
}
|
||||
|
||||
fn describe(&self) -> String {
|
||||
// TODO: derive Display for Library and use this here
|
||||
format!("Fetching all assets for library {}", self.library.name)
|
||||
}
|
||||
|
||||
async fn execute(&self, ctx: &Context) -> Result<Self::Output> {
|
||||
let query = AssetQuery {
|
||||
library: Some(self.library.clone()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let assets: Vec<_> = fetch_all_assets(query, &ctx.client)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(Asset::from)
|
||||
.collect();
|
||||
|
||||
Ok(assets)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue