From 0cfe4d7db8ca4db8d44c1f71eb40e161800b11fa Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Thu, 26 Jan 2023 08:48:04 -0500 Subject: [PATCH] Update upload_photo example to wait for processing --- examples/register/mod.rs | 6 +++++- examples/upload_photo.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/register/mod.rs b/examples/register/mod.rs index eb86b7b..d4cb02e 100644 --- a/examples/register/mod.rs +++ b/examples/register/mod.rs @@ -54,7 +54,10 @@ pub async fn register() -> Result { #[cfg(feature = "toml")] pub fn read_line(message: impl AsRef) -> Result { - println!("{}", message.as_ref()); + use std::io::Write; + + print!("{}", message.as_ref()); + io::stdout().flush()?; let mut input = String::new(); io::stdin().read_line(&mut input)?; @@ -63,6 +66,7 @@ pub fn read_line(message: impl AsRef) -> Result { } #[cfg(feature = "toml")] +#[allow(dead_code)] pub fn bool_input(message: impl AsRef, default: bool) -> Result { let input = read_line(message.as_ref())?; if let Some(first_char) = input.chars().next() { diff --git a/examples/upload_photo.rs b/examples/upload_photo.rs index 4492945..d53a584 100644 --- a/examples/upload_photo.rs +++ b/examples/upload_photo.rs @@ -6,7 +6,7 @@ use mastodon_async::{Result, StatusBuilder, Visibility}; #[cfg(feature = "toml")] async fn run() -> Result<()> { use register::bool_input; - femme::with_level(femme::LevelFilter::Trace); + femme::with_level(femme::LevelFilter::Info); let mastodon = register::get_mastodon_data().await?; let input = register::read_line("Enter the path to the photo you'd like to post: ")?; let description = register::read_line("describe the media? ")?; @@ -17,6 +17,10 @@ async fn run() -> Result<()> { }; let media = mastodon.media(input, description).await?; + let media = mastodon + .wait_for_processing(media, Default::default()) + .await?; + println!("media upload available at: {}", media.url); let status = StatusBuilder::new() .status("Mastodon-async photo upload example/demo (automated post)") .media_ids([media.id])