forked from alemi/upub
feat(web): pre-populate webfinger cache
when i put an actor in cache, put its pretty url in webfinger cache too
This commit is contained in:
parent
59e71418ea
commit
29e9901583
2 changed files with 15 additions and 4 deletions
|
@ -19,7 +19,11 @@ pub fn ActorHeader() -> impl IntoView {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
let user = std::sync::Arc::new(user);
|
let user = std::sync::Arc::new(user);
|
||||||
cache::OBJECTS.store(&Uri::full(U::Actor, &id), user.clone());
|
let uid = Uri::full(U::Actor, &id);
|
||||||
|
cache::OBJECTS.store(&uid, user.clone());
|
||||||
|
if let Some(url) = user.url().id().str() {
|
||||||
|
cache::WEBFINGER.store(&url, uid);
|
||||||
|
}
|
||||||
Ok(user)
|
Ok(user)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ pub mod thread;
|
||||||
|
|
||||||
use std::{collections::BTreeSet, pin::Pin, sync::Arc};
|
use std::{collections::BTreeSet, pin::Pin, sync::Arc};
|
||||||
|
|
||||||
use apb::{field::OptionalString, Activity, ActivityMut, Base, Object};
|
use apb::{field::OptionalString, Activity, ActivityMut, Actor, Base, Object};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -169,9 +169,16 @@ async fn process_activities(activities: Vec<serde_json::Value>, auth: Auth) -> V
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_and_update(kind: U, id: String, auth: Auth) {
|
async fn fetch_and_update(kind: U, id: String, auth: Auth) {
|
||||||
match Http::fetch(&Uri::api(kind, &id, false), auth).await {
|
match Http::fetch::<serde_json::Value>(&Uri::api(kind, &id, false), auth).await {
|
||||||
Ok(data) => { cache::OBJECTS.store(&id, Arc::new(data)); },
|
|
||||||
Err(e) => console_warn(&format!("could not fetch '{id}': {e}")),
|
Err(e) => console_warn(&format!("could not fetch '{id}': {e}")),
|
||||||
|
Ok(data) => {
|
||||||
|
if data.actor_type().is_ok() {
|
||||||
|
if let Some(url) = data.url().id().str() {
|
||||||
|
cache::WEBFINGER.store(&id, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cache::OBJECTS.store(&id, Arc::new(data));
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue