Compare commits

..

2 commits

Author SHA1 Message Date
b6e48025fb
fix(uriproxy): better extractor 2024-05-20 08:45:59 +02:00
1a236589ed
fix(web): short uri helper logic 2024-05-20 08:45:41 +02:00
3 changed files with 10 additions and 5 deletions

View file

@ -39,8 +39,10 @@ pub fn uri(base: &str, entity: UriClass, id: &str) -> String {
/// decompose local id constructed by uri() fn
pub fn decompose_id(full_id: &str) -> String {
full_id // https://example.org/users/test/followers/page?offset=42
.split('/') // ['https:', '', 'example.org', 'users', 'test', 'followers', 'page?offset=42' ]
.nth(4) // 'test'
.replace("https://", "")
.replace("http://", "")
.split('/') // ['example.org', 'users', 'test', 'followers', 'page?offset=42' ]
.nth(2) // 'test'
.unwrap_or("")
.to_string()
}

View file

@ -118,10 +118,12 @@ impl Uri {
}
pub fn short(url: &str) -> String {
if url.starts_with(URL_BASE) {
if url.starts_with(URL_BASE) || url.starts_with('/') {
uriproxy::decompose_id(url)
} else {
} else if url.starts_with("https://") || url.starts_with("http") {
uriproxy::compact_id(url)
} else {
url.to_string()
}
}

View file

@ -28,7 +28,8 @@ pub fn UserPage(tl: Timeline) -> impl IntoView {
.cloned()
.unwrap_or_default();
let uid = uriproxy::uri(URL_BASE, uriproxy::UriClass::User, &id);
let actor = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), move |id| {
let _uid = uid.clone();
let actor = create_local_resource(move || _uid.clone(), move |id| {
async move {
match CACHE.get(&Uri::full(U::User, &id)) {
Some(x) => Some(x.clone()),