diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-10 16:32:36 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-10 16:32:36 -0800 |
commit | cd67cbbb2827c161aa6e99c93fe57f5500cbb789 (patch) | |
tree | 74288ae72c0f7ad07cf1f77416b180ab9a4f65c0 /adenosine-pds/src/web.rs | |
parent | 5e149eef22d34e5a2b2081de3533dee3373d47f8 (diff) | |
download | adenosine-cd67cbbb2827c161aa6e99c93fe57f5500cbb789.tar.gz adenosine-cd67cbbb2827c161aa6e99c93fe57f5500cbb789.zip |
pds: more web view implementation
Diffstat (limited to 'adenosine-pds/src/web.rs')
-rw-r--r-- | adenosine-pds/src/web.rs | 59 |
1 files changed, 51 insertions, 8 deletions
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<serde_json::Value>, + pub profile: Profile, + pub feed: Vec<FeedItem>, } #[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<ThreadItem>, } #[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<String> { + 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<String> { + 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<String> { + 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("<MISSING>".to_string()) + } + } +} |