mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31:19 +02:00
refactor: downloads/uploads every media from a tweet async way
This commit is contained in:
19
src/util.rs
19
src/util.rs
@@ -1,9 +1,15 @@
|
|||||||
use crate::{twitter::get_tweet_media, ScootalooError};
|
use crate::{twitter::get_tweet_media, ScootalooError};
|
||||||
use egg_mode::tweet::Tweet;
|
|
||||||
use elefren::prelude::*;
|
|
||||||
use log::{error, warn};
|
|
||||||
use reqwest::Url;
|
|
||||||
use std::{borrow::Cow, error::Error};
|
use std::{borrow::Cow, error::Error};
|
||||||
|
|
||||||
|
use egg_mode::tweet::Tweet;
|
||||||
|
|
||||||
|
use elefren::prelude::*;
|
||||||
|
|
||||||
|
use log::{error, info, warn};
|
||||||
|
|
||||||
|
use reqwest::Url;
|
||||||
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::{create_dir_all, remove_file, File},
|
fs::{create_dir_all, remove_file, File},
|
||||||
io::copy,
|
io::copy,
|
||||||
@@ -35,6 +41,10 @@ pub async fn generate_media_ids(
|
|||||||
let mastodon = mastodon.clone();
|
let mastodon = mastodon.clone();
|
||||||
|
|
||||||
let task = tokio::task::spawn(async move {
|
let task = tokio::task::spawn(async move {
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
info!("Start treating {}", media.media_url_https);
|
||||||
|
>>>>>>> 32f9605 (tamerelol)
|
||||||
// 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 = match get_tweet_media(&media, &cache_path).await {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
@@ -51,6 +61,7 @@ pub async fn generate_media_ids(
|
|||||||
match mastodon.media(Cow::from(local_tweet_media_path.to_owned())) {
|
match mastodon.media(Cow::from(local_tweet_media_path.to_owned())) {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
remove_file(&local_tweet_media_path).await.unwrap();
|
||||||
return Err(ScootalooError::new(&format!(
|
return Err(ScootalooError::new(&format!(
|
||||||
"Attachment {} cannot be uploaded to Mastodon Instance: {}",
|
"Attachment {} cannot be uploaded to Mastodon Instance: {}",
|
||||||
&local_tweet_media_path, e
|
&local_tweet_media_path, e
|
||||||
|
Reference in New Issue
Block a user