Add a command to delete assets

This commit is contained in:
Marc Plano-Lesay 2024-11-05 14:27:37 +11:00
parent af5990796e
commit ebe22cfc10
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
6 changed files with 114 additions and 0 deletions

View file

@ -0,0 +1,58 @@
use crate::{
utils::assets::{fetch_all_assets, AssetQuery},
Client,
};
use color_eyre::eyre::Result;
use dialoguer::{theme::ColorfulTheme, Confirm};
use log::info;
use uuid::Uuid;
pub async fn delete_assets(
client: &Client,
offline: bool,
dry_run: bool,
no_confirm: bool,
) -> Result<()> {
let query = AssetQuery {
is_offline: if offline { Some(true) } else { None },
..Default::default()
};
let assets = fetch_all_assets(query, client).await?;
for asset in &assets {
info!(
"Deleting asset {} located at {}",
asset.id, asset.original_path
);
}
if !dry_run {
if !(no_confirm
|| Confirm::with_theme(&ColorfulTheme::default())
.with_prompt("Do you want to continue?")
.interact()?)
{
return Ok(());
}
let asset_ids: Result<Vec<_>, uuid::Error> = assets
.iter()
.map(|asset| Uuid::parse_str(&asset.id))
.collect();
client
.delete_assets(&crate::types::AssetBulkDeleteDto {
force: Some(true),
ids: asset_ids?,
})
.await?;
}
info!(
"Deleted {} assets{}",
assets.len(),
if dry_run { " (dry run)" } else { "" }
);
Ok(())
}

View file

@ -1,3 +1,4 @@
pub mod delete_assets;
pub mod list_assets;
pub mod missing_date_of_birth;
pub mod server_features;