From 2dabd308cca9bf085edcfc9f0534fbe3678d0ca2 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 15 Apr 2024 22:20:33 +0200 Subject: [PATCH] fix: oops broke fetch uris, fixed --- web/src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/web/src/lib.rs b/web/src/lib.rs index 3a8cae4..6d3acc2 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -23,6 +23,14 @@ fn web_uri(kind: &str, url: &str) -> String { } } +fn api_uri(kind: &str, url: &str) -> String { + if url.starts_with(URL_BASE) { + url.to_string() + } else { + format!("{URL_BASE}/{kind}/+{}", url.replace("https://", "").replace('/', "@")) + } +} + #[component] pub fn LoginBox( rx: Signal>, @@ -199,19 +207,20 @@ pub fn ObjectPage() -> impl IntoView { async move { let uid = format!("{URL_BASE}/objects/{oid}"); match CTX.cache.actors.get(&uid) { - Some(x) => x.clone(), + Some(x) => Some(x.clone()), None => reqwest::get(uid) .await - .unwrap() + .ok()? .json::() .await - .unwrap(), + .ok() } } }); view! { {move || match object.get() { - Some(o) => view!{ }.into_view(), + Some(Some(o)) => view!{ }.into_view(), + Some(None) => view! {

loading failed

}.into_view(), None => view! {

loading ...

}.into_view(), }} } @@ -362,7 +371,7 @@ async fn fetch_activities_with_users( out.push(x.set_actor(apb::Node::object(actor.clone()))) } else { let mut req = reqwest::Client::new() - .get(format!("https://feditest.alemi.dev/users/+?id={uid}")); + .get(api_uri("users", &uid)); if let Some(token) = token.get() { req = req.header("Authorization", format!("Bearer {token}"));