1
0
Fork 0
forked from alemi/upub

fix: oops broke fetch uris, fixed

This commit is contained in:
əlemi 2024-04-15 22:20:33 +02:00
parent d5a83a5c7c
commit 2dabd308cc
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -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] #[component]
pub fn LoginBox( pub fn LoginBox(
rx: Signal<Option<String>>, rx: Signal<Option<String>>,
@ -199,19 +207,20 @@ pub fn ObjectPage() -> impl IntoView {
async move { async move {
let uid = format!("{URL_BASE}/objects/{oid}"); let uid = format!("{URL_BASE}/objects/{oid}");
match CTX.cache.actors.get(&uid) { match CTX.cache.actors.get(&uid) {
Some(x) => x.clone(), Some(x) => Some(x.clone()),
None => reqwest::get(uid) None => reqwest::get(uid)
.await .await
.unwrap() .ok()?
.json::<serde_json::Value>() .json::<serde_json::Value>()
.await .await
.unwrap(), .ok()
} }
} }
}); });
view! { view! {
{move || match object.get() { {move || match object.get() {
Some(o) => view!{ <Object object=o /> }.into_view(), Some(Some(o)) => view!{ <Object object=o /> }.into_view(),
Some(None) => view! { <p><code>loading failed</code></p> }.into_view(),
None => view! { <p> loading ... </p> }.into_view(), None => view! { <p> loading ... </p> }.into_view(),
}} }}
} }
@ -362,7 +371,7 @@ async fn fetch_activities_with_users(
out.push(x.set_actor(apb::Node::object(actor.clone()))) out.push(x.set_actor(apb::Node::object(actor.clone())))
} else { } else {
let mut req = reqwest::Client::new() 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() { if let Some(token) = token.get() {
req = req.header("Authorization", format!("Bearer {token}")); req = req.header("Authorization", format!("Bearer {token}"));