mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 09:01:19 +02:00
fix: wait until media is uploaded
This commit is contained in:
20
src/util.rs
20
src/util.rs
@@ -6,6 +6,7 @@ use futures::{stream, stream::StreamExt};
|
||||
use log::{error, info, warn};
|
||||
use megalodon::{
|
||||
entities::UploadMedia::{AsyncAttachment, Attachment},
|
||||
error,
|
||||
mastodon::Mastodon,
|
||||
megalodon::Megalodon,
|
||||
};
|
||||
@@ -55,7 +56,7 @@ pub async fn generate_media_ids(
|
||||
|
||||
let id = match mastodon_media {
|
||||
Attachment(m) => m.id,
|
||||
AsyncAttachment(m) => m.id,
|
||||
AsyncAttachment(m) => wait_until_uploaded(&mastodon, &m.id).await?,
|
||||
};
|
||||
|
||||
Ok::<String, ScootalooError>(id)
|
||||
@@ -81,6 +82,23 @@ pub async fn generate_media_ids(
|
||||
(media_url, media_ids)
|
||||
}
|
||||
|
||||
/// Wait on uploaded medias when necessary
|
||||
async fn wait_until_uploaded(client: &Mastodon, id: &str) -> Result<String, error::Error> {
|
||||
loop {
|
||||
let res = client.get_media(id.to_string()).await;
|
||||
return match res {
|
||||
Ok(res) => Ok(res.json.id),
|
||||
Err(err) => match err {
|
||||
error::Error::OwnError(ref own_err) => match own_err.kind {
|
||||
error::Kind::HTTPPartialContentError => continue,
|
||||
_ => Err(err),
|
||||
},
|
||||
_ => Err(err),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Transforms the media into a base64 equivalent
|
||||
pub async fn base64_media(u: &str) -> Result<String, Box<dyn Error>> {
|
||||
let mut response = reqwest::get(u).await?;
|
||||
|
Reference in New Issue
Block a user