fix: return response rather than parsing
so that deliveries work
This commit is contained in:
parent
855434ee12
commit
bb16a5b7d2
2 changed files with 11 additions and 13 deletions
|
@ -98,7 +98,7 @@ async fn worker(db: DatabaseConnection, domain: String, poll_interval: u64, mut
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = Fetcher::request::<()>(
|
if let Err(e) = Fetcher::request(
|
||||||
Method::POST, &delivery.target,
|
Method::POST, &delivery.target,
|
||||||
Some(&serde_json::to_string(&payload).unwrap()),
|
Some(&serde_json::to_string(&payload).unwrap()),
|
||||||
&delivery.actor, &key, &domain
|
&delivery.actor, &key, &domain
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::BTreeMap;
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use http_signature_normalization::Config;
|
use http_signature_normalization::Config;
|
||||||
use openssl::{hash::MessageDigest, pkey::{PKey, Private}, sign::Signer};
|
use openssl::{hash::MessageDigest, pkey::{PKey, Private}, sign::Signer};
|
||||||
use reqwest::{header::{CONTENT_TYPE, USER_AGENT}, Method};
|
use reqwest::{header::{CONTENT_TYPE, USER_AGENT}, Method, Response};
|
||||||
use sea_orm::{DatabaseConnection, EntityTrait, IntoActiveModel};
|
use sea_orm::{DatabaseConnection, EntityTrait, IntoActiveModel};
|
||||||
|
|
||||||
use crate::{model, VERSION};
|
use crate::{model, VERSION};
|
||||||
|
@ -22,14 +22,14 @@ impl Fetcher {
|
||||||
Fetcher { db, domain, key: PKey::private_key_from_pem(key.as_bytes()).unwrap() }
|
Fetcher { db, domain, key: PKey::private_key_from_pem(key.as_bytes()).unwrap() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn request<T: serde::de::DeserializeOwned>(
|
pub async fn request(
|
||||||
method: reqwest::Method,
|
method: reqwest::Method,
|
||||||
url: &str,
|
url: &str,
|
||||||
payload: Option<&str>,
|
payload: Option<&str>,
|
||||||
from: &str,
|
from: &str,
|
||||||
key: &PKey<Private>,
|
key: &PKey<Private>,
|
||||||
domain: &str,
|
domain: &str,
|
||||||
) -> reqwest::Result<T> {
|
) -> reqwest::Result<Response> {
|
||||||
let host = Context::server(url);
|
let host = Context::server(url);
|
||||||
let date = chrono::Utc::now().format("%a, %d %b %Y %H:%M:%S GMT").to_string(); // lmao @ "GMT"
|
let date = chrono::Utc::now().format("%a, %d %b %Y %H:%M:%S GMT").to_string(); // lmao @ "GMT"
|
||||||
let path = url.replace("https://", "").replace("http://", "").replace(&host, "");
|
let path = url.replace("https://", "").replace("http://", "").replace(&host, "");
|
||||||
|
@ -87,9 +87,7 @@ impl Fetcher {
|
||||||
.header("Signature", signature_header)
|
.header("Signature", signature_header)
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.error_for_status()?
|
.error_for_status()
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn user(&self, id: &str) -> crate::Result<model::user::Model> {
|
pub async fn user(&self, id: &str) -> crate::Result<model::user::Model> {
|
||||||
|
@ -97,9 +95,9 @@ impl Fetcher {
|
||||||
return Ok(x); // already in db, easy
|
return Ok(x); // already in db, easy
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = Self::request::<serde_json::Value>(
|
let user = Self::request(
|
||||||
Method::GET, id, None, &format!("https://{}", self.domain), &self.key, &self.domain,
|
Method::GET, id, None, &format!("https://{}", self.domain), &self.key, &self.domain,
|
||||||
).await?;
|
).await?.json::<serde_json::Value>().await?;
|
||||||
let user_model = model::user::Model::new(&user)?;
|
let user_model = model::user::Model::new(&user)?;
|
||||||
|
|
||||||
model::user::Entity::insert(user_model.clone().into_active_model())
|
model::user::Entity::insert(user_model.clone().into_active_model())
|
||||||
|
@ -113,9 +111,9 @@ impl Fetcher {
|
||||||
return Ok(x); // already in db, easy
|
return Ok(x); // already in db, easy
|
||||||
}
|
}
|
||||||
|
|
||||||
let activity = Self::request::<serde_json::Value>(
|
let activity = Self::request(
|
||||||
Method::GET, id, None, &format!("https://{}", self.domain), &self.key, &self.domain,
|
Method::GET, id, None, &format!("https://{}", self.domain), &self.key, &self.domain,
|
||||||
).await?;
|
).await?.json::<serde_json::Value>().await?;
|
||||||
let activity_model = model::activity::Model::new(&activity)?;
|
let activity_model = model::activity::Model::new(&activity)?;
|
||||||
|
|
||||||
model::activity::Entity::insert(activity_model.clone().into_active_model())
|
model::activity::Entity::insert(activity_model.clone().into_active_model())
|
||||||
|
@ -129,9 +127,9 @@ impl Fetcher {
|
||||||
return Ok(x); // already in db, easy
|
return Ok(x); // already in db, easy
|
||||||
}
|
}
|
||||||
|
|
||||||
let object = Self::request::<serde_json::Value>(
|
let object = Self::request(
|
||||||
Method::GET, id, None, &format!("https://{}", self.domain), &self.key, &self.domain,
|
Method::GET, id, None, &format!("https://{}", self.domain), &self.key, &self.domain,
|
||||||
).await?;
|
).await?.json::<serde_json::Value>().await?;
|
||||||
let object_model = model::object::Model::new(&object)?;
|
let object_model = model::object::Model::new(&object)?;
|
||||||
|
|
||||||
model::object::Entity::insert(object_model.clone().into_active_model())
|
model::object::Entity::insert(object_model.clone().into_active_model())
|
||||||
|
|
Loading…
Reference in a new issue