From cd67cbbb2827c161aa6e99c93fe57f5500cbb789 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 10 Nov 2022 16:32:36 -0800 Subject: pds: more web view implementation --- adenosine-pds/src/web.rs | 59 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 8 deletions(-) (limited to 'adenosine-pds/src/web.rs') diff --git a/adenosine-pds/src/web.rs b/adenosine-pds/src/web.rs index e783b5a..5b9d6de 100644 --- a/adenosine-pds/src/web.rs +++ b/adenosine-pds/src/web.rs @@ -17,23 +17,22 @@ pub struct AboutView { } #[derive(Template)] -#[template(path = "profile.html")] -pub struct ProfileView { +#[template(path = "account.html")] +pub struct AccountView { pub domain: String, pub did: Did, - pub profile: serde_json::Value, - pub feed: Vec, + pub profile: Profile, + pub feed: Vec, } #[derive(Template)] -#[template(path = "post.html")] -pub struct PostView { +#[template(path = "thread.html")] +pub struct ThreadView { pub domain: String, pub did: Did, pub collection: Nsid, pub tid: Tid, - pub post_text: String, - pub post_created_at: String, + pub thread: Vec, } #[derive(Template)] @@ -63,3 +62,47 @@ pub struct RecordView { pub tid: Tid, pub record: serde_json::Value, } + +mod filters { + use crate::AtUri; + use std::str::FromStr; + + pub fn aturi_to_path(aturi: &str) -> ::askama::Result { + let aturi = AtUri::from_str(aturi).expect("aturi parse"); + if aturi.record.is_some() { + Ok(format!( + "/at/{}/{}/{}", + aturi.repository, + aturi.collection.unwrap(), + aturi.record.unwrap() + )) + } else if aturi.collection.is_some() { + Ok(format!( + "/at/{}/{}", + aturi.repository, + aturi.collection.unwrap() + )) + } else { + Ok(format!("/at/{}", aturi.repository)) + } + } + + pub fn aturi_to_thread_path(aturi: &str) -> ::askama::Result { + let aturi = AtUri::from_str(aturi).expect("aturi parse"); + Ok(format!( + "/u/{}/post/{}", + aturi.repository, + aturi.record.unwrap() + )) + } + + pub fn aturi_to_tid(aturi: &str) -> ::askama::Result { + let aturi = AtUri::from_str(aturi).expect("aturi parse"); + if aturi.record.is_some() { + Ok(aturi.record.unwrap()) + } else { + // TODO: raise an askama error here? + Ok("".to_string()) + } + } +} -- cgit v1.2.3