mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31:19 +02:00
refactor: better logic flow for uploading/deleting media
This commit is contained in:
28
src/util.rs
28
src/util.rs
@@ -56,22 +56,20 @@ pub async fn generate_media_ids(
|
||||
};
|
||||
|
||||
// upload media to Mastodon
|
||||
let mastodon_media =
|
||||
match mastodon.media(Cow::from(local_tweet_media_path.to_owned())) {
|
||||
Ok(l) => l,
|
||||
Err(e) => {
|
||||
remove_file(&local_tweet_media_path).await.unwrap();
|
||||
return Err(ScootalooError::new(&format!(
|
||||
"Attachment {} cannot be uploaded to Mastodon Instance: {}",
|
||||
&local_tweet_media_path, e
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
let mastodon_media = mastodon.media(Cow::from(local_tweet_media_path.to_owned()));
|
||||
// at this point, we can safely erase the original file
|
||||
if let Err(e) = remove_file(&local_tweet_media_path).await {
|
||||
ScootalooError::new(&format!("Attachment {} has been uploaded but I’m unable to remove the existing file: {}", &local_tweet_media_path, e));
|
||||
}
|
||||
// it doesn’t matter if we can’t 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))
|
||||
});
|
||||
|
Reference in New Issue
Block a user