2022-11-27 14:44:43 +00:00
|
|
|
#![cfg_attr(not(feature = "toml"), allow(dead_code))]
|
|
|
|
#![cfg_attr(not(feature = "toml"), allow(unused_imports))]
|
|
|
|
mod register;
|
2022-12-23 15:09:33 +00:00
|
|
|
use mastodon_async::{Result, StatusBuilder, Visibility};
|
2022-11-27 14:44:43 +00:00
|
|
|
|
2022-12-23 15:09:33 +00:00
|
|
|
#[cfg(feature = "toml")]
|
2022-12-30 14:59:39 +00:00
|
|
|
async fn run() -> Result<()> {
|
2022-12-26 17:19:51 +00:00
|
|
|
use register::bool_input;
|
2023-01-26 13:48:04 +00:00
|
|
|
femme::with_level(femme::LevelFilter::Info);
|
2022-12-23 15:09:33 +00:00
|
|
|
let mastodon = register::get_mastodon_data().await?;
|
2022-11-27 14:44:43 +00:00
|
|
|
let input = register::read_line("Enter the path to the photo you'd like to post: ")?;
|
2022-12-26 16:19:54 +00:00
|
|
|
let description = register::read_line("describe the media? ")?;
|
|
|
|
let description = if description.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(description)
|
|
|
|
};
|
2022-11-27 14:44:43 +00:00
|
|
|
|
2022-12-26 16:19:54 +00:00
|
|
|
let media = mastodon.media(input, description).await?;
|
2023-01-26 13:48:04 +00:00
|
|
|
let media = mastodon
|
|
|
|
.wait_for_processing(media, Default::default())
|
|
|
|
.await?;
|
|
|
|
println!("media upload available at: {}", media.url);
|
2022-12-23 15:09:33 +00:00
|
|
|
let status = StatusBuilder::new()
|
|
|
|
.status("Mastodon-async photo upload example/demo (automated post)")
|
|
|
|
.media_ids([media.id])
|
|
|
|
.visibility(Visibility::Private)
|
|
|
|
.build()?;
|
|
|
|
let status = mastodon.new_status(status).await?;
|
|
|
|
println!("successfully uploaded status. It has the ID {}.", status.id);
|
|
|
|
if bool_input("would you like to delete the post now? (Y/n) ", true)? {
|
|
|
|
mastodon.delete_status(&status.id).await?;
|
|
|
|
println!("ok. done.");
|
|
|
|
}
|
2022-11-27 14:44:43 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:59:39 +00:00
|
|
|
#[cfg(all(feature = "toml", feature = "mt"))]
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
run().await
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(all(feature = "toml", not(feature = "mt")))]
|
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
run().await
|
|
|
|
}
|
|
|
|
|
2022-11-27 14:44:43 +00:00
|
|
|
#[cfg(not(feature = "toml"))]
|
|
|
|
fn main() {
|
|
|
|
println!(
|
|
|
|
"examples require the `toml` feature, run this command for this example:\n\ncargo run \
|
|
|
|
--example upload_photo --features toml\n"
|
|
|
|
);
|
|
|
|
}
|