mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: Tyler Longwell <tlongwell@block.xyz> Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
use crate::client::BuzzClient;
|
|
use crate::error::CliError;
|
|
|
|
pub async fn dispatch(cmd: crate::UploadCmd, client: &BuzzClient) -> Result<(), CliError> {
|
|
match cmd {
|
|
crate::UploadCmd::File { file } => {
|
|
let desc = client.upload_file(&file).await?;
|
|
println!(
|
|
"{}",
|
|
serde_json::to_string_pretty(&desc).map_err(|e| CliError::Other(e.to_string()))?
|
|
);
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|
|
|
|
pub async fn dispatch_media(cmd: crate::MediaCmd, client: &BuzzClient) -> Result<(), CliError> {
|
|
match cmd {
|
|
crate::MediaCmd::Get { input, output } => {
|
|
let bytes = client.download_media(&input).await?;
|
|
match output.as_deref() {
|
|
Some(path) if path != "-" => {
|
|
std::fs::write(path, &bytes)
|
|
.map_err(|e| CliError::Other(format!("could not write {path}: {e}")))?;
|
|
}
|
|
_ => {
|
|
use std::io::Write;
|
|
std::io::stdout()
|
|
.write_all(&bytes)
|
|
.map_err(|e| CliError::Other(format!("could not write stdout: {e}")))?;
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|