asyncify plume-models: media upload is now async
including the use of tokio!
This commit is contained in:
parent
3472a58299
commit
87ce3a7b51
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2718,6 +2718,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"shrinkwraprs 0.3.0",
|
||||
"tantivy",
|
||||
"tokio 0.2.20",
|
||||
"url 2.1.1",
|
||||
"walkdir",
|
||||
"webfinger",
|
||||
|
@ -21,6 +21,7 @@ serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
tantivy = "0.10.1"
|
||||
tokio = "0.2"
|
||||
url = "2.1"
|
||||
walkdir = "2.2"
|
||||
webfinger = "0.5"
|
||||
|
@ -81,10 +81,10 @@ impl Follow {
|
||||
|
||||
/// from -> The one sending the follow request
|
||||
/// target -> The target of the request, responding with Accept
|
||||
pub fn accept_follow<A: Signer + IntoId + Clone, B: Clone + AsActor<T> + IntoId, T>(
|
||||
pub fn accept_follow<A: Signer + IntoId + Clone + Sync, B: Clone + AsActor<T> + IntoId, T>(
|
||||
conn: &Connection,
|
||||
from: &B,
|
||||
target: &A,
|
||||
target: &'static A,
|
||||
follow: FollowAct,
|
||||
from_id: i32,
|
||||
target_id: i32,
|
||||
|
@ -12,6 +12,7 @@ use plume_common::{
|
||||
};
|
||||
use reqwest;
|
||||
use std::{fs, path::Path};
|
||||
use tokio::prelude::*;
|
||||
|
||||
#[derive(Clone, Identifiable, Queryable)]
|
||||
pub struct Media {
|
||||
@ -197,7 +198,7 @@ impl Media {
|
||||
}
|
||||
|
||||
// TODO: merge with save_remote?
|
||||
pub fn from_activity(c: &PlumeRocket, image: &Image) -> Result<Media> {
|
||||
pub async fn from_activity(c: &PlumeRocket, image: &Image) -> Result<Media> {
|
||||
let conn = &*c.conn;
|
||||
let remote_url = image.object_props.url_string().ok()?;
|
||||
let ext = remote_url
|
||||
@ -211,11 +212,12 @@ impl Media {
|
||||
ext
|
||||
));
|
||||
|
||||
let mut dest = fs::File::create(path.clone()).ok()?;
|
||||
reqwest::get(remote_url.as_str())
|
||||
.ok()?
|
||||
.copy_to(&mut dest)
|
||||
.ok()?;
|
||||
let mut dest = tokio::fs::File::create(path.clone()).await?;
|
||||
let contents = reqwest::get(remote_url.as_str())
|
||||
.await?
|
||||
.bytes()
|
||||
.await?;
|
||||
dest.write_all(&contents).await?;
|
||||
|
||||
Media::insert(
|
||||
conn,
|
||||
|
@ -223,7 +223,7 @@ impl User {
|
||||
|
||||
fn fetch(url: &str) -> Result<CustomPerson> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
.build()?
|
||||
.get(url)
|
||||
.header(
|
||||
@ -358,7 +358,7 @@ impl User {
|
||||
}
|
||||
fn fetch_outbox_page<T: Activity>(&self, url: &str) -> Result<(Vec<T>, Option<String>)> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
.build()?
|
||||
.get(url)
|
||||
.header(
|
||||
@ -388,7 +388,7 @@ impl User {
|
||||
}
|
||||
pub fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
.build()?
|
||||
.get(&self.outbox_url[..])
|
||||
.header(
|
||||
@ -433,7 +433,7 @@ impl User {
|
||||
|
||||
pub fn fetch_followers_ids(&self) -> Result<Vec<String>> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
.build()?
|
||||
.get(&self.followers_endpoint[..])
|
||||
.header(
|
||||
|
Loading…
Reference in New Issue
Block a user