fix upload image of MastodonClient method in main & small fixes

This commit is contained in:
Denis-Cosmin Nutiu 2025-01-04 17:18:58 +02:00
parent 4050a96887
commit 72e2497f5e
3 changed files with 28 additions and 4 deletions

View file

@ -134,9 +134,14 @@ async fn main() -> Result<(), anyhow::Error> {
Ok(post) => {
// Step1: Upload image to Mastodon
let media_response = if post.image.is_some() {
Ok(mastodon_client
let response = mastodon_client
.upload_media_by_url(post.image.clone().unwrap().as_str())
.await?)
.await;
match response {
Ok(response) => Ok(response),
Err(err) => Err(anyhow!("failed to upload image: {err}")),
}
} else {
Err(anyhow!("No image exists on post."))
};

View file

@ -38,13 +38,13 @@ impl From<NewsPost> for PostStatusRequest {
if character_budget > 0 {
status.push_str(title.get(0..character_budget).unwrap_or(title.as_str()));
character_budget -= title.len() + 2;
status.push_str("\n")
status.push('\n')
}
// Push the summary
if character_budget > 0 {
status.push_str(summary.get(0..character_budget).unwrap_or(summary.as_str()));
status.push_str("\n")
status.push('\n')
}
// Push the link

View file

@ -46,5 +46,24 @@ things simple and due to its powerful features and flexibility[1].
The BlueSky bot reads data from Redis Streams and publishes it to BlueSky.
```shell
Social media posting bot.
Usage: bot --redis-connection-string <REDIS_CONNECTION_STRING> --redis-stream-name <REDIS_STREAM_NAME> --redis-consumer-group <REDIS_CONSUMER_GROUP> --redis-consumer-name <REDIS_CONSUMER_NAME> <COMMAND>
Commands:
bluesky Post on bluesky platform
mastodon Post on Mastodon, the FediVerse
help Print this message or the help of the given subcommand(s)
Options:
-r, --redis-connection-string <REDIS_CONNECTION_STRING> Redis host
-t, --redis-stream-name <REDIS_STREAM_NAME> Redis stream name
-c, --redis-consumer-group <REDIS_CONSUMER_GROUP> Redis consumer group name
-n, --redis-consumer-name <REDIS_CONSUMER_NAME> The current consumer name
-h, --help Print help
-V, --version Print version
```
[1] - https://redis.io/about/