Update upload_photo example to wait for processing

This commit is contained in:
D. Scott Boggs 2023-01-26 08:48:04 -05:00 committed by Scott Boggs
parent 5f5bc8728c
commit 0cfe4d7db8
2 changed files with 10 additions and 2 deletions

View File

@ -54,7 +54,10 @@ pub async fn register() -> Result<Mastodon> {
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
pub fn read_line(message: impl AsRef<str>) -> Result<String> { pub fn read_line(message: impl AsRef<str>) -> Result<String> {
println!("{}", message.as_ref()); use std::io::Write;
print!("{}", message.as_ref());
io::stdout().flush()?;
let mut input = String::new(); let mut input = String::new();
io::stdin().read_line(&mut input)?; io::stdin().read_line(&mut input)?;
@ -63,6 +66,7 @@ pub fn read_line(message: impl AsRef<str>) -> Result<String> {
} }
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
#[allow(dead_code)]
pub fn bool_input(message: impl AsRef<str>, default: bool) -> Result<bool> { pub fn bool_input(message: impl AsRef<str>, default: bool) -> Result<bool> {
let input = read_line(message.as_ref())?; let input = read_line(message.as_ref())?;
if let Some(first_char) = input.chars().next() { if let Some(first_char) = input.chars().next() {

View File

@ -6,7 +6,7 @@ use mastodon_async::{Result, StatusBuilder, Visibility};
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
async fn run() -> Result<()> { async fn run() -> Result<()> {
use register::bool_input; use register::bool_input;
femme::with_level(femme::LevelFilter::Trace); femme::with_level(femme::LevelFilter::Info);
let mastodon = register::get_mastodon_data().await?; let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the path to the photo you'd like to post: ")?; let input = register::read_line("Enter the path to the photo you'd like to post: ")?;
let description = register::read_line("describe the media? ")?; 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.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() let status = StatusBuilder::new()
.status("Mastodon-async photo upload example/demo (automated post)") .status("Mastodon-async photo upload example/demo (automated post)")
.media_ids([media.id]) .media_ids([media.id])