diff options
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/mod.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index 42e8754..c4a86b4 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -239,15 +239,16 @@ pub async fn homepage<D: Storage>( Host(host): Host, Query(query): Query<QueryParams>, State(db): State<D>, + session: Option<crate::Session> ) -> impl IntoResponse { - let user = None; // TODO authentication // This is stupid, but there is no other way. let hcard_url: url::Url = format!("https://{}/", host).parse().unwrap(); let feed_path = format!("https://{}/feeds/main", host); + let user = session.as_ref().map(|s| &s.0.me); match tokio::try_join!( - get_post_from_database(&db, &hcard_url.as_str(), None, user.as_ref()), - get_post_from_database(&db, &feed_path, query.after, user.as_ref()) + get_post_from_database(&db, &hcard_url.as_str(), None, user), + get_post_from_database(&db, &feed_path, query.after, user) ) { Ok(((hcard, _), (hfeed, cursor))) => { // Here, we know those operations can't really fail @@ -275,7 +276,7 @@ pub async fn homepage<D: Storage>( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: MainPage { feed: &hfeed, card: &hcard, @@ -316,7 +317,7 @@ pub async fn homepage<D: Storage>( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: ErrorPage { code: err.code(), msg: Some(err.msg().to_string()), @@ -335,16 +336,17 @@ pub async fn catchall<D: Storage>( State(db): State<D>, Host(host): Host, Query(query): Query<QueryParams>, + session: Option<crate::Session>, uri: Uri, ) -> impl IntoResponse { - let user: Option<url::Url> = None; // TODO authentication + let user: Option<&url::Url> = session.as_deref().map(|p| &p.me); // TODO authentication let host = url::Url::parse(&format!("https://{}/", host)).unwrap(); let path = host .clone() .join(uri.path()) .unwrap(); - match get_post_from_database(&db, path.as_str(), query.after, user.as_ref()).await { + match get_post_from_database(&db, path.as_str(), query.after, user).await { Ok((post, cursor)) => { let (blogname, channels) = tokio::join!( db.get_setting::<crate::database::settings::SiteName>(&host) @@ -363,7 +365,7 @@ pub async fn catchall<D: Storage>( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: match post.pointer("/type/0").and_then(|i| i.as_str()) { Some("h-entry") => Entry { post: &post }.to_string(), Some("h-feed") => Feed { feed: &post, cursor: cursor.as_deref() }.to_string(), @@ -393,7 +395,7 @@ pub async fn catchall<D: Storage>( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: ErrorPage { code: err.code(), msg: Some(err.msg().to_owned()), |