Update src/lib.rs

This commit is contained in:
VC
2021-04-24 08:04:52 +00:00
parent 4ef58bda0a
commit fd9cc31848

View File

@@ -6,7 +6,6 @@ use std::{
fmt,
fs::{read_to_string, write},
error::Error,
sync::{Arc, Mutex},
};
// toml
@@ -356,7 +355,6 @@ pub async fn run(config: Config) {
for tweet in &feed {
debug!("Treating Tweet {} inside feed", tweet.id);
// determine if the tweet is part of a thread (response to self) or a standard response
debug!("Treating Tweet {} inside feed", tweet.id);
if let Some(r) = &tweet.in_reply_to_screen_name {
if &r.to_lowercase() != &config.twitter.username.to_lowercase() {
// we are responding not threading
@@ -376,32 +374,32 @@ pub async fn run(config: Config) {
let mut status_medias: Vec<String> = vec![];
// reupload the attachments if any
// reupload the attachments if any
if let Some(m) = &tweet.extended_entities {
let (tx, mut rx) = mpsc::channel(4);
for media in &m.media {
let local_tweet_media_path = match get_tweet_media(&media, &config.scootaloo.cache_path).await {
let local_tweet_media_path = match get_tweet_media(&media, &config.scootaloo.cache_path) {
Ok(m) => m,
Err(e) => {
warn!("Cannot get tweet media for {}: {}", &media.url, e);
println!("Cannot get tweet media for {}: {}", &media.url, e);
continue;
},
};
let mastodon_media_ids = match mastodon.media(Cow::from(String::from(&local_tweet_media_path))) {
Ok(m) => {
remove_file(&local_tweet_media_path).await.unwrap_or_else(|e|
warn!("Attachment {} has been uploaded but Im unable to remove the existing file: {}", &local_tweet_media_path, e)
remove_file(&local_tweet_media_path).unwrap_or_else(|e|
println!("Attachment for {} has been upload, but Im unable to remove the existing file: {}", &local_tweet_media_path, e)
);
m.id
},
Err(e) => {
error!("Attachment {} cannot be uploaded to Mastodon Instance: {}", &local_tweet_media_path, e);
println!("Cannot attach media {} to Mastodon Instance: {}", &local_tweet_media_path, e);
continue;
}
};
status_medias.push(mastodon_media_ids);
// last step, removing the reference to the media from with the toots text
status_text = status_text.replace(&media.url, "");
}