mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
Merge branch 'fix_attachment' into 'master'
Fix attachment See merge request veretcle/scootaloo!52
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -858,9 +858,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "megalodon"
|
||||
version = "0.3.3"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e7bc4427c44dc9c4b439da7bcd15a87b51e21340a12ef5a4f7eac90fc247886"
|
||||
checksum = "3b39bd378603a46216457c1c95c54f8dec37959a02c06a59cc33d00fc71a0ba0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"chrono",
|
||||
@@ -1343,7 +1343,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "scootaloo"
|
||||
version = "1.1.3"
|
||||
version = "1.1.4"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"clap",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "scootaloo"
|
||||
version = "1.1.3"
|
||||
version = "1.1.4"
|
||||
authors = ["VC <veretcle+framagit@mateu.be>"]
|
||||
edition = "2021"
|
||||
|
||||
@@ -17,7 +17,7 @@ rusqlite = "^0.27"
|
||||
isolang = "^2"
|
||||
tokio = { version = "^1", features = ["rt"]}
|
||||
futures = "^0.3"
|
||||
megalodon = "^0.3.3"
|
||||
megalodon = "^0.3.6"
|
||||
html-escape = "^0.2"
|
||||
reqwest = "^0.11"
|
||||
log = "^0.4"
|
||||
|
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