Compare commits
2 Commits
main
...
epsilon-ph
Author | SHA1 | Date | |
---|---|---|---|
|
26867ca6be | ||
|
2b4e802914 |
@ -56,7 +56,6 @@ impl Instance {
|
|||||||
.clone()
|
.clone()
|
||||||
.ok_or(Error::NotFound)
|
.ok_or(Error::NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_local_uncached(conn: &Connection) -> Result<Instance> {
|
pub fn get_local_uncached(conn: &Connection) -> Result<Instance> {
|
||||||
instances::table
|
instances::table
|
||||||
.filter(instances::local.eq(true))
|
.filter(instances::local.eq(true))
|
||||||
|
@ -29,7 +29,6 @@ table! {
|
|||||||
is_owner -> Bool,
|
is_owner -> Bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
blogs (id) {
|
blogs (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -211,6 +211,13 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_first_local(conn: &Connection) -> Result<User> {
|
||||||
|
users::table
|
||||||
|
.filter(users::instance_id.eq(Instance::get_local()?.id))
|
||||||
|
.first(&*conn)
|
||||||
|
.map_err(|_| Error::NotFound)
|
||||||
|
}
|
||||||
|
|
||||||
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<User> {
|
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<User> {
|
||||||
let link = resolve(acct.to_owned(), true)?
|
let link = resolve(acct.to_owned(), true)?
|
||||||
.links
|
.links
|
||||||
@ -229,21 +236,28 @@ impl User {
|
|||||||
.ok_or(Error::Webfinger)
|
.ok_or(Error::Webfinger)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch(url: &str) -> Result<CustomPerson> {
|
fn fetch(url: &str, lu: User) -> Result<CustomPerson> {
|
||||||
|
let mut headers = plume_common::activity_pub::request::headers();
|
||||||
|
headers.insert(
|
||||||
|
ACCEPT,
|
||||||
|
HeaderValue::from_str(
|
||||||
|
&ap_accept_header()
|
||||||
|
.into_iter()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", "),
|
||||||
|
)?,
|
||||||
|
);
|
||||||
let mut res = ClientBuilder::new()
|
let mut res = ClientBuilder::new()
|
||||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||||
.build()?
|
.build()?
|
||||||
.get(url)
|
.get(url)
|
||||||
|
.headers(headers.clone())
|
||||||
.header(
|
.header(
|
||||||
ACCEPT,
|
"Signature",
|
||||||
HeaderValue::from_str(
|
plume_common::activity_pub::request::signature(&lu, &headers).expect(""),
|
||||||
&ap_accept_header()
|
|
||||||
.into_iter()
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", "),
|
|
||||||
)?,
|
|
||||||
)
|
)
|
||||||
.send()?;
|
.send()?;
|
||||||
|
|
||||||
let text = &res.text()?;
|
let text = &res.text()?;
|
||||||
// without this workaround, publicKey is not correctly deserialized
|
// without this workaround, publicKey is not correctly deserialized
|
||||||
let ap_sign = serde_json::from_str::<ApSignature>(text)?;
|
let ap_sign = serde_json::from_str::<ApSignature>(text)?;
|
||||||
@ -253,11 +267,12 @@ impl User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_from_url(c: &PlumeRocket, url: &str) -> Result<User> {
|
pub fn fetch_from_url(c: &PlumeRocket, url: &str) -> Result<User> {
|
||||||
User::fetch(url).and_then(|json| User::from_activity(c, json))
|
User::fetch(url, User::find_first_local(&*c.conn)?)
|
||||||
|
.and_then(|json| User::from_activity(c, json))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refetch(&self, conn: &Connection) -> Result<()> {
|
pub fn refetch(&self, conn: &Connection) -> Result<()> {
|
||||||
User::fetch(&self.ap_url.clone()).and_then(|json| {
|
User::fetch(&self.ap_url.clone(), User::find_first_local(conn)?).and_then(|json| {
|
||||||
let avatar = Media::save_remote(
|
let avatar = Media::save_remote(
|
||||||
conn,
|
conn,
|
||||||
json.object
|
json.object
|
||||||
|
Loading…
Reference in New Issue
Block a user