1
0
Fork 0
forked from alemi/upub

feat(web): individual views will request fetches

This commit is contained in:
əlemi 2024-04-18 05:00:44 +02:00
parent 96e3681bf7
commit 59ebee71a8
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 6 additions and 6 deletions

View file

@ -126,7 +126,7 @@ impl Uri {
/// - https://other.domain.net/unexpected/path/root /// - https://other.domain.net/unexpected/path/root
/// - +other.domain.net@users@root /// - +other.domain.net@users@root
/// - root /// - root
pub fn api(kind: &str, url: &str) -> String { pub fn api(kind: &str, url: &str, fetch: bool) -> String {
format!("{URL_BASE}/{kind}/{}", Self::short(url)) format!("{URL_BASE}/{kind}/{}{}", Self::short(url), if fetch { "?fetch=true" } else { "" })
} }
} }

View file

@ -41,7 +41,7 @@ pub fn UserPage() -> impl IntoView {
match CACHE.get(&Uri::full("users", &id)) { match CACHE.get(&Uri::full("users", &id)) {
Some(x) => Some(x.clone()), Some(x) => Some(x.clone()),
None => { None => {
let user : serde_json::Value = Http::fetch(&Uri::api("users", &id), auth).await.ok()?; let user : serde_json::Value = Http::fetch(&Uri::api("users", &id, true), auth).await.ok()?;
CACHE.put(Uri::full("users", &id), user.clone()); CACHE.put(Uri::full("users", &id), user.clone());
Some(user) Some(user)
}, },
@ -116,7 +116,7 @@ pub fn UserPage() -> impl IntoView {
}</blockquote> }</blockquote>
</div> </div>
</div> </div>
<TimelineFeed tl=Timeline::new(format!("{}/outbox/page", Uri::api("users", &id.clone()))) /> <TimelineFeed tl=Timeline::new(format!("{}/outbox/page", Uri::api("users", &id.clone(), false))) />
}.into_view() }.into_view()
}, },
}} }}
@ -134,7 +134,7 @@ pub fn ObjectPage() -> impl IntoView {
match CACHE.get(&Uri::full("objects", &oid)) { match CACHE.get(&Uri::full("objects", &oid)) {
Some(x) => Some(x.clone()), Some(x) => Some(x.clone()),
None => { None => {
let obj = Http::fetch::<serde_json::Value>(&Uri::api("objects", &oid), auth).await.ok()?; let obj = Http::fetch::<serde_json::Value>(&Uri::api("objects", &oid, true), auth).await.ok()?;
CACHE.put(Uri::full("objects", &oid), obj.clone()); CACHE.put(Uri::full("objects", &oid), obj.clone());
Some(obj) Some(obj)
} }

View file

@ -126,7 +126,7 @@ async fn process_activities(
} }
async fn fetch_and_update(kind: &'static str, id: String, auth: Signal<Option<String>>) { async fn fetch_and_update(kind: &'static str, id: String, auth: Signal<Option<String>>) {
match Http::fetch(&Uri::api(kind, &id), auth).await { match Http::fetch(&Uri::api(kind, &id, false), auth).await {
Ok(data) => CACHE.put(id, data), Ok(data) => CACHE.put(id, data),
Err(e) => console_warn(&format!("could not fetch '{id}': {e}")), Err(e) => console_warn(&format!("could not fetch '{id}': {e}")),
} }