gourami

[UNMAINTAINED] Activitypub server in Rust
Log | Files | Refs | README | LICENSE

commit 3b9677179fbf2dab6f68ec684ee2ec62d77b9295
parent cc95daf6742f603fc9e9e8858441308676f67968
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 22 May 2020 09:47:27 -0500

Run cargo fmt

Diffstat:
Msrc/ap.rs | 26++++++++++++++++----------
Msrc/db/note.rs | 1-
Msrc/lib.rs | 4+++-
Msrc/routes.rs | 26++++++++++++++------------
4 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/src/ap.rs b/src/ap.rs @@ -91,8 +91,8 @@ pub struct ApNote { in_reply_to: Option<String>, } -use regex::Regex; use crate::db::note; +use regex::Regex; impl ApNote { fn get_remote_user_name(&self) -> Option<String> { @@ -103,10 +103,11 @@ impl ApNote { } } // TODO write unit tests - pub fn transform_incoming_content(&self) -> Result<(String, Option<i32>), Error>{ + pub fn transform_incoming_content(&self) -> Result<(String, Option<i32>), Error> { let attr_re = Regex::new(r"^(.+?)(💬)").unwrap(); let note_re = Regex::new(r"\B(📝|>>)(\d+)").unwrap(); - let new_content = attr_re.replace(&note::remove_unacceptable_html(&self.content), "") + let new_content = attr_re + .replace(&note::remove_unacceptable_html(&self.content), "") .replace(&format!("{}:", SERVER.domain), ""); let mut new_content = note_re.replace(&new_content, "").into_owned(); @@ -117,8 +118,11 @@ impl ApNote { let mut reply_id: Option<i32> = None; println!("{:?}", self.in_reply_to); if let Some(reply) = self.in_reply_to.clone() { - reply_id = n::notes.select(n::id) - .filter(n::remote_id.eq(reply)).first(conn).ok(); + reply_id = n::notes + .select(n::id) + .filter(n::remote_id.eq(reply)) + .first(conn) + .ok(); println!("{:?}", reply_id); if let Some(r) = reply_id { new_content = format!("📝{} {}", r, new_content); @@ -127,8 +131,6 @@ impl ApNote { // render html and stuff Ok((note::parse_note_text(&new_content), reply_id)) } - - } #[derive(Debug, Deserialize, Serialize)] @@ -425,10 +427,14 @@ pub fn new_note_to_ap_message(note: &Note, user: &User) -> Result<Value, Error> use crate::db::schema::notes::dsl as n; let in_reply_to_url = match reply { Some(id) => { - let reply_url: Option<String> = n::notes.select(n::remote_id).filter(n::id.eq(id)).first(conn).unwrap(); // ?? + let reply_url: Option<String> = n::notes + .select(n::remote_id) + .filter(n::id.eq(id)) + .first(conn) + .unwrap(); // ?? reply_url - }, - None => None + } + None => None, }; println!("{:?}", note); let res = json!({ diff --git a/src/db/note.rs b/src/db/note.rs @@ -40,7 +40,6 @@ impl Note { format!("{}:{}💬 {}", SERVER.domain, username, self.content) } - pub fn relative_timestamp(&self) -> String { // Maybe use some fancy library here let diff = Utc::now() diff --git a/src/lib.rs b/src/lib.rs @@ -256,7 +256,9 @@ pub fn new_note( notes::notes.order(notes::id.desc()).first(conn) })?; // add note url - diesel::update(notes::notes.filter(notes::id.eq(inserted_note.id))).set(notes::remote_id.eq(note::get_url(inserted_note.id))).execute(conn)?; + diesel::update(notes::notes.filter(notes::id.eq(inserted_note.id))) + .set(notes::remote_id.eq(note::get_url(inserted_note.id))) + .execute(conn)?; inserted_note.remote_id = Some(note::get_url(inserted_note.id)); // notify person u reply to if mentions.len() > 0 { diff --git a/src/routes.rs b/src/routes.rs @@ -44,21 +44,21 @@ pub async fn run_server() { // https://www.w3.org/TR/activitypub/#retrieving-objects // TODO content type // TODO get interop with mastodon working - .and( + .and( header::exact_ignore_case( "accept", r#"application/ld+json; profile="https://www.w3.org/ns/activitystreams""#, + ) + .or(header::exact_ignore_case( + "accept", + r#"application/ld+json"#, + )) + .or(header::exact_ignore_case( + "accept", + r#"profile="https://www.w3.org/ns/activitystreams""#, + )) + .or(header::exact_ignore_case("accept", "application/json")), ) - .or(header::exact_ignore_case( - "accept", - r#"application/ld+json"#, - )) - .or(header::exact_ignore_case( - "accept", - r#"profile="https://www.w3.org/ns/activitystreams""#, - )) - .or(header::exact_ignore_case("accept", "application/json")), - ) .map( |_| reply::json(&ap::server_actor_json()), // how do async work ); @@ -99,7 +99,9 @@ pub async fn run_server() { .and(path("notifications")) .map(render_notifications); - let server_info_page = session_filter().and(path("server_info")).map(server_info_page); + let server_info_page = session_filter() + .and(path("server_info")) + .map(server_info_page); // auth functions let register_page = path("register").and(query()).map(register_page);