1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
use adenosine::app_bsky;
use adenosine::com_atproto;
use adenosine::identifiers::{Did, Nsid, Tid};
use adenosine::repo::RepoCommit;
use askama::Template;
#[derive(Template)]
#[template(path = "error.html")]
pub struct ErrorView {
pub domain: String,
pub status_code: u16,
pub error_message: String,
}
#[derive(Template)]
#[template(path = "home.html")]
pub struct GenericHomeView {
pub domain: String,
}
#[derive(Template)]
#[template(path = "about.html")]
pub struct AboutView {
pub domain: String,
}
#[derive(Template)]
#[template(path = "account.html")]
pub struct AccountView {
pub domain: String,
pub did: Did,
pub profile: app_bsky::ProfileViewDetailed,
pub feed: Vec<app_bsky::FeedViewPost>,
}
#[derive(Template)]
#[template(path = "thread.html")]
pub struct ThreadView {
pub domain: String,
pub did: Did,
pub collection: Nsid,
pub tid: Tid,
pub post: app_bsky::ThreadViewPost,
}
#[derive(Template)]
#[template(path = "at_repo.html")]
pub struct RepoView {
pub domain: String,
pub did: Did,
pub commit: RepoCommit,
pub describe: com_atproto::repo::Describe,
}
#[derive(Template)]
#[template(path = "at_collection.html")]
pub struct CollectionView {
pub domain: String,
pub did: Did,
pub collection: Nsid,
pub records: Vec<serde_json::Value>,
}
#[derive(Template)]
#[template(path = "at_record.html")]
pub struct RecordView {
pub domain: String,
pub did: Did,
pub collection: Nsid,
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())
}
}
}
|