gourami

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

commit c7e43431e43d1e4500bac22420a270ecdc404ee8
parent 64c643f96501f0ef52092b19e51386ceb4cc81e3
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 29 Apr 2020 16:50:07 -0500

--amend

Diffstat:
Msrc/db/note.rs | 13++++---------
Msrc/lib.rs | 4++--
2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/db/note.rs b/src/db/note.rs @@ -14,7 +14,6 @@ pub struct Note { // rename RenderedNote pub id: i32, pub user_id: i32, pub in_reply_to: Option<i32>, - #[serde(deserialize_with="render_content")] pub content: String, pub created_time: String, pub neighborhood: bool, @@ -28,17 +27,14 @@ pub struct Note { // rename RenderedNote /// We want to render it so that it is rendered in HTML /// This basically just means escaping characters and adding /// automatic URL parsing -fn render_content<'de, D>(deserializer: D) -> Result<String, D::Error> -where D: Deserializer<'de> { - let s: &str = Deserialize::deserialize(deserializer)?; - return Ok(parse_note_text(s)); -} +/// /// Run on both write to db and read from db, for redundancy /// Prevents malicious content from being rendered /// See the mastodon page for inspiration: https://docs.joinmastodon.org/spec/activitypub/ /// This is currently very aggressive -- maybe we could loosen it a bit /// We probably want to allow microformats and some accessibiltiy tags +/// Dont allow a so we cant have sneaky urls -- I'll do all the url parsing on my end. fn remove_unnacceptable_html(input_text: &str) -> String { let ok_tags = hashset!["br", "p", "span"]; let html_clean = ammonia::Builder::default() @@ -50,10 +46,10 @@ fn remove_unnacceptable_html(input_text: &str) -> String { #[derive(Insertable, Clone, Debug)] #[table_name = "notes"] -pub struct NoteInput { +pub struct NoteInput<'a> { //pub id: i32, //unsigned? pub user_id: i32, - pub content: String, // TODO make slice + pub content: &'a str, pub in_reply_to: Option<i32>, pub neighborhood: bool, } @@ -109,7 +105,6 @@ pub fn parse_note_text(text: &str) -> String { let replace_str = "<a href=\"/user/$2\">$0</a>"; let people_parsed = person_regex.replace_all(&notes_parsed, &replace_str as &str).to_string(); // TODO get mentions too - println!("{}", people_parsed); return people_parsed; } diff --git a/src/lib.rs b/src/lib.rs @@ -144,7 +144,7 @@ fn new_note(auth_user: User, note_input: &str, neighborhood: bool,) -> Result<() let new_note = NoteInput{ user_id: auth_user.id, in_reply_to: reply, - content: parsed_note_text, + content: &parsed_note_text, neighborhood: neighborhood }; insert_into(notes::notes).values(new_note).execute(conn)?; @@ -343,7 +343,7 @@ pub struct UserNote { username: String, } -// thread. hm +// TODO merge this with the other get notes function fn get_single_note(note_id: i32) -> Option<Vec<UserNote>> { use db::schema::notes::dsl as n; use db::schema::users::dsl as u;