61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
use crate::{
|
|
context::Context,
|
|
utils::assets::{fetch_all_assets, AssetQuery},
|
|
};
|
|
use color_eyre::eyre::Result;
|
|
use tabled::{
|
|
settings::{
|
|
object::{Columns, Object, Rows},
|
|
Format, Style,
|
|
},
|
|
Table, Tabled,
|
|
};
|
|
|
|
#[derive(Tabled)]
|
|
struct Asset {
|
|
#[tabled(rename = "Path")]
|
|
original_file_path: String,
|
|
#[tabled(rename = "Is offline")]
|
|
is_offline: bool,
|
|
#[tabled(rename = "Camera")]
|
|
model: String,
|
|
}
|
|
|
|
pub async fn list_assets(ctx: Context, offline: bool) -> Result<()> {
|
|
let query = AssetQuery {
|
|
is_offline: if offline { Some(true) } else { None },
|
|
with_exif: true,
|
|
..Default::default()
|
|
};
|
|
|
|
let mut assets: Vec<_> = fetch_all_assets(query, &ctx.client)
|
|
.await?
|
|
.into_iter()
|
|
.map(|asset| Asset {
|
|
is_offline: asset.is_offline,
|
|
model: asset
|
|
.exif_info
|
|
.clone()
|
|
.and_then(|exif| exif.model)
|
|
.unwrap_or(String::from("(Unknown)")),
|
|
original_file_path: asset.original_path,
|
|
})
|
|
.collect();
|
|
|
|
assets.sort_by_key(|asset| asset.original_file_path.clone());
|
|
|
|
println!(
|
|
"{}",
|
|
Table::new(assets).with(Style::rounded()).modify(
|
|
Columns::single(1).not(Rows::first()),
|
|
Format::content(|s| {
|
|
match s {
|
|
"true" => "Yes".to_string(),
|
|
_ => "No".to_string(),
|
|
}
|
|
})
|
|
)
|
|
);
|
|
|
|
Ok(())
|
|
}
|