From 5583029b0711b4c60711f2bda767e572ed8c4504 Mon Sep 17 00:00:00 2001 From: Bat Date: Thu, 26 Jul 2018 21:35:35 +0200 Subject: [PATCH] Update the WebFinger crate Fixes an issue with some Mastodon accounts --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- plume-common/src/activity_pub/request.rs | 5 +---- plume-models/Cargo.toml | 2 +- plume-models/src/blogs.rs | 11 +++++++---- plume-models/src/users.rs | 15 +++++++++------ src/routes/blogs.rs | 2 +- 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38ad4c9..9b58dc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1004,7 +1004,7 @@ dependencies = [ "serde_json 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", "validator 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "validator_derive 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webfinger 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "webfinger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "workerpool 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1052,7 +1052,7 @@ dependencies = [ "serde_derive 1.0.43 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "webfinger 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "webfinger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2003,7 +2003,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "webfinger" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "reqwest 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2286,7 +2286,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ed0f6789c8a85ca41bbc1c9d175422116a9869bd1cf31bb08e1493ecce60380" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum webfinger 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a3e10c73859f818558bbed7fc9bf69a939ebdfc86cba637c9e7eda4606088eae" +"checksum webfinger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34ffa5f00fedd30b71718a02b973df00a66e8059ad041bc597b455b22a2aba2" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/Cargo.toml b/Cargo.toml index 371879e..f76918f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ serde_derive = "1.0" serde_json = "1.0" validator = "0.7" validator_derive = "0.7" -webfinger = "0.2" +webfinger = "0.3" workerpool = "1.1" [dependencies.diesel] diff --git a/plume-common/src/activity_pub/request.rs b/plume-common/src/activity_pub/request.rs index 05e24cb..2e529c4 100644 --- a/plume-common/src/activity_pub/request.rs +++ b/plume-common/src/activity_pub/request.rs @@ -4,10 +4,7 @@ use reqwest::{ mime::Mime, header::{Accept, Date, Headers, UserAgent, qitem} }; -use std::{ - str::FromStr, - time::SystemTime -}; +use std::time::SystemTime; use activity_pub::ap_accept_header; use activity_pub::sign::Signer; diff --git a/plume-models/Cargo.toml b/plume-models/Cargo.toml index a6d44f4..8d79571 100644 --- a/plume-models/Cargo.toml +++ b/plume-models/Cargo.toml @@ -15,7 +15,7 @@ serde = "*" serde_derive = "1.0" serde_json = "1.0" url = "1.7" -webfinger = "0.2" +webfinger = "0.3" [dependencies.chrono] features = ["serde"] diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 7b1df68..be8f544 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -108,7 +108,7 @@ impl Blog { fn fetch_from_webfinger(conn: &PgConnection, acct: String) -> Option { match resolve(acct.clone(), *USE_HTTPS) { - Ok(wf) => wf.links.into_iter().find(|l| l.mime_type == Some(String::from("application/activity+json"))).and_then(|l| Blog::fetch_from_url(conn, l.href)), + Ok(wf) => wf.links.into_iter().find(|l| l.mime_type == Some(String::from("application/activity+json"))).and_then(|l| Blog::fetch_from_url(conn, l.href.expect("No href for AP WF link"))), Err(details) => { println!("{:?}", details); None @@ -221,17 +221,20 @@ impl Blog { Link { rel: String::from("http://webfinger.net/rel/profile-page"), mime_type: None, - href: self.ap_url.clone() + href: Some(self.ap_url.clone()), + template: None }, Link { rel: String::from("http://schemas.google.com/g/2010#updates-from"), mime_type: Some(String::from("application/atom+xml")), - href: self.get_instance(conn).compute_box(BLOG_PREFIX, self.actor_id.clone(), "feed.atom") + href: Some(self.get_instance(conn).compute_box(BLOG_PREFIX, self.actor_id.clone(), "feed.atom")), + template: None }, Link { rel: String::from("self"), mime_type: Some(String::from("application/activity+json")), - href: self.ap_url.clone() + href: Some(self.ap_url.clone()), + template: None } ] } diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index e95babc..33a61af 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -144,9 +144,9 @@ impl User { fn fetch_from_webfinger(conn: &PgConnection, acct: String) -> Option { match resolve(acct.clone(), *USE_HTTPS) { - Ok(wf) => wf.links.into_iter().find(|l| l.mime_type == Some(String::from("application/activity+json"))).and_then(|l| User::fetch_from_url(conn, l.href)), + Ok(wf) => wf.links.into_iter().find(|l| l.mime_type == Some(String::from("application/activity+json"))).and_then(|l| User::fetch_from_url(conn, l.href.expect("No href for AP WF link"))), Err(details) => { - println!("{:?}", details); + println!("WF Error: {:?}", details); None } } @@ -166,7 +166,7 @@ impl User { Some(User::from_activity(conn, json, Url::parse(url.as_ref()).unwrap().host_str().unwrap().to_string())) }, Err(e) => { - println!("{:?}", e); + println!("User fetch error: {:?}", e); None } } @@ -386,17 +386,20 @@ impl User { Link { rel: String::from("http://webfinger.net/rel/profile-page"), mime_type: None, - href: self.ap_url.clone() + href: Some(self.ap_url.clone()), + template: None }, Link { rel: String::from("http://schemas.google.com/g/2010#updates-from"), mime_type: Some(String::from("application/atom+xml")), - href: self.get_instance(conn).compute_box(USER_PREFIX, self.username.clone(), "feed.atom") + href: Some(self.get_instance(conn).compute_box(USER_PREFIX, self.username.clone(), "feed.atom")), + template: None }, Link { rel: String::from("self"), mime_type: Some(String::from("application/activity+json")), - href: self.ap_url.clone() + href: Some(self.ap_url.clone()), + template: None } ] } diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 662687f..528e0ae 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -38,7 +38,7 @@ fn paginated_details(name: String, conn: DbConn, user: Option, page: Page) "page": page.page, "n_pages": Page::total(articles.len() as i32) })) - }) + }) } #[get("/~/", rank = 3)]