mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 17:34:37 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ffbe98f838 | ||
![]() |
822f4044c6 | ||
![]() |
78924f6eeb | ||
![]() |
9c14636735 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2099,7 +2099,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scootaloo"
|
name = "scootaloo"
|
||||||
version = "0.8.1"
|
version = "0.8.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "scootaloo"
|
name = "scootaloo"
|
||||||
version = "0.8.1"
|
version = "0.8.2"
|
||||||
authors = ["VC <veretcle+framagit@mateu.be>"]
|
authors = ["VC <veretcle+framagit@mateu.be>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@@ -87,7 +87,7 @@ pub fn migrate_db(d: &str, s: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
match res {
|
match res {
|
||||||
Err(e) => match e.to_string().as_str() {
|
Err(e) => match e.to_string().as_str() {
|
||||||
"duplicate column name: twitter_screen_name" => Ok(()),
|
"duplicate column name: twitter_screen_name" => Ok(()),
|
||||||
_ => Err(Box::new(e)),
|
_ => Err(e.into()),
|
||||||
},
|
},
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
}
|
}
|
||||||
|
27
src/util.rs
27
src/util.rs
@@ -45,33 +45,16 @@ pub async fn generate_media_ids(
|
|||||||
let task = tokio::task::spawn(async move {
|
let task = tokio::task::spawn(async move {
|
||||||
info!("Start treating {}", media.media_url_https);
|
info!("Start treating {}", media.media_url_https);
|
||||||
// get the tweet embedded media
|
// get the tweet embedded media
|
||||||
let local_tweet_media_path = match get_tweet_media(&media, &cache_path).await {
|
let local_tweet_media_path = 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
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// upload media to Mastodon
|
// 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
|
// at this point, we can safely erase the original file
|
||||||
// it doesn’t matter if we can’t remove, cache_media fn is idempotent
|
// it doesn’t matter if we can’t remove, cache_media fn is idempotent
|
||||||
remove_file(&local_tweet_media_path).await.ok();
|
remove_file(&local_tweet_media_path).await.ok();
|
||||||
|
|
||||||
let mastodon_media = match mastodon_media {
|
Ok::<(usize, String), ScootalooError>((i, mastodon_media.id))
|
||||||
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))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tasks.push(task);
|
tasks.push(task);
|
||||||
@@ -81,7 +64,7 @@ pub async fn generate_media_ids(
|
|||||||
match task.await {
|
match task.await {
|
||||||
// insert the media at the right place
|
// insert the media at the right place
|
||||||
Ok(Ok((i, v))) => media_ids[i] = v,
|
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),
|
Err(e) => error!("Something went wrong when joining the main thread: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user