mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
Update src/lib.rs
This commit is contained in:
16
src/lib.rs
16
src/lib.rs
@@ -6,7 +6,6 @@ use std::{
|
|||||||
fmt,
|
fmt,
|
||||||
fs::{read_to_string, write},
|
fs::{read_to_string, write},
|
||||||
error::Error,
|
error::Error,
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// toml
|
// toml
|
||||||
@@ -356,7 +355,6 @@ pub async fn run(config: Config) {
|
|||||||
for tweet in &feed {
|
for tweet in &feed {
|
||||||
debug!("Treating Tweet {} inside feed", tweet.id);
|
debug!("Treating Tweet {} inside feed", tweet.id);
|
||||||
// determine if the tweet is part of a thread (response to self) or a standard response
|
// 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 let Some(r) = &tweet.in_reply_to_screen_name {
|
||||||
if &r.to_lowercase() != &config.twitter.username.to_lowercase() {
|
if &r.to_lowercase() != &config.twitter.username.to_lowercase() {
|
||||||
// we are responding not threading
|
// we are responding not threading
|
||||||
@@ -378,30 +376,30 @@ pub async fn run(config: Config) {
|
|||||||
|
|
||||||
// reupload the attachments if any
|
// reupload the attachments if any
|
||||||
if let Some(m) = &tweet.extended_entities {
|
if let Some(m) = &tweet.extended_entities {
|
||||||
let (tx, mut rx) = mpsc::channel(4);
|
|
||||||
|
|
||||||
for media in &m.media {
|
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,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Cannot get tweet media for {}: {}", &media.url, e);
|
println!("Cannot get tweet media for {}: {}", &media.url, e);
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mastodon_media_ids = match mastodon.media(Cow::from(String::from(&local_tweet_media_path))) {
|
let mastodon_media_ids = match mastodon.media(Cow::from(String::from(&local_tweet_media_path))) {
|
||||||
Ok(m) => {
|
Ok(m) => {
|
||||||
remove_file(&local_tweet_media_path).await.unwrap_or_else(|e|
|
remove_file(&local_tweet_media_path).unwrap_or_else(|e|
|
||||||
warn!("Attachment {} has been uploaded but I’m unable to remove the existing file: {}", &local_tweet_media_path, e)
|
println!("Attachment for {} has been upload, but I’m unable to remove the existing file: {}", &local_tweet_media_path, e)
|
||||||
);
|
);
|
||||||
m.id
|
m.id
|
||||||
},
|
},
|
||||||
Err(e) => {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
status_medias.push(mastodon_media_ids);
|
status_medias.push(mastodon_media_ids);
|
||||||
|
|
||||||
// last step, removing the reference to the media from with the toot’s text
|
// last step, removing the reference to the media from with the toot’s text
|
||||||
status_text = status_text.replace(&media.url, "");
|
status_text = status_text.replace(&media.url, "");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user