Merge branch 'generate_media_flow' into 'master'

Better media flow

See merge request veretcle/scootaloo!26
This commit is contained in:
VC
2022-11-14 13:41:07 +00:00
4 changed files with 8 additions and 25 deletions

2
Cargo.lock generated
View File

@@ -2099,7 +2099,7 @@ dependencies = [
[[package]]
name = "scootaloo"
version = "0.8.1"
version = "0.8.2"
dependencies = [
"chrono",
"clap",

View File

@@ -1,6 +1,6 @@
[package]
name = "scootaloo"
version = "0.8.1"
version = "0.8.2"
authors = ["VC <veretcle+framagit@mateu.be>"]
edition = "2021"

View File

@@ -87,7 +87,7 @@ pub fn migrate_db(d: &str, s: &str) -> Result<(), Box<dyn Error>> {
match res {
Err(e) => match e.to_string().as_str() {
"duplicate column name: twitter_screen_name" => Ok(()),
_ => Err(Box::new(e)),
_ => Err(e.into()),
},
_ => Ok(()),
}

View File

@@ -45,33 +45,16 @@ pub async fn generate_media_ids(
let task = tokio::task::spawn(async move {
info!("Start treating {}", media.media_url_https);
// get the tweet embedded media
let local_tweet_media_path = match get_tweet_media(&media, &cache_path).await {
Ok(l) => l,
Err(e) => {
return Err(ScootalooError::new(&format!(
"Cannot get tweet media for {}: {}",
&media.url, e
)))
}
};
let local_tweet_media_path = get_tweet_media(&media, &cache_path).await?;
// upload media to Mastodon
let mastodon_media = mastodon.media(Cow::from(local_tweet_media_path.to_owned()));
let mastodon_media =
mastodon.media(Cow::from(local_tweet_media_path.to_owned()))?;
// at this point, we can safely erase the original file
// it doesnt matter if we cant remove, cache_media fn is idempotent
remove_file(&local_tweet_media_path).await.ok();
let mastodon_media = match mastodon_media {
Ok(m) => m,
Err(e) => {
return Err(ScootalooError::new(&format!(
"Attachment {} cannot be uploaded to Mastodon Instance: {}",
&local_tweet_media_path, e
)))
}
};
Ok((i, mastodon_media.id))
Ok::<(usize, String), ScootalooError>((i, mastodon_media.id))
});
tasks.push(task);
@@ -81,7 +64,7 @@ pub async fn generate_media_ids(
match task.await {
// insert the media at the right place
Ok(Ok((i, v))) => media_ids[i] = v,
Ok(Err(e)) => warn!("{}", e),
Ok(Err(e)) => warn!("Cannot treat media: {}", e),
Err(e) => error!("Something went wrong when joining the main thread: {}", e),
}
}