fix(web): show uncloaked urls

This commit is contained in:
əlemi 2024-07-16 01:31:10 +02:00
parent 7ae1d02c02
commit d0138c5fc0
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 10 additions and 1 deletions

1
Cargo.lock generated
View file

@ -4876,6 +4876,7 @@ name = "upub-web"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"apb", "apb",
"base64 0.22.1",
"chrono", "chrono",
"console_error_panic_hook", "console_error_panic_hook",
"cookie", "cookie",

View file

@ -14,6 +14,7 @@ repository = "https://git.alemi.dev/upub.git"
[dependencies] [dependencies]
lazy_static = "1.4" lazy_static = "1.4"
cookie = "0.18" cookie = "0.18"
base64 = "0.22"
tracing = "0.1" tracing = "0.1"
tracing-subscriber = "0.3" tracing-subscriber = "0.3"
tracing-subscriber-wasm = "0.1" tracing-subscriber-wasm = "0.1"

View file

@ -1,8 +1,14 @@
use leptos::*; use leptos::*;
use crate::{prelude::*, URL_SENSITIVE}; use crate::{prelude::*, URL_SENSITIVE};
use base64::prelude::*;
use apb::{field::OptionalString, Document, Object}; use apb::{field::OptionalString, Document, Object};
fn uncloak(txt: Option<&str>) -> Option<String> {
let decoded = BASE64_URL_SAFE.decode(txt?).ok()?;
Some(std::str::from_utf8(&decoded).ok()?.to_string())
}
#[component] #[component]
pub fn Attachment( pub fn Attachment(
object: serde_json::Value, object: serde_json::Value,
@ -12,6 +18,7 @@ pub fn Attachment(
let config = use_context::<Signal<crate::Config>>().expect("missing config context"); let config = use_context::<Signal<crate::Config>>().expect("missing config context");
let (expand, set_expand) = create_signal(false); let (expand, set_expand) = create_signal(false);
let href = object.url().id().str().unwrap_or_default(); let href = object.url().id().str().unwrap_or_default();
let uncloaked = uncloak(href.split('/').last()).unwrap_or_default();
let media_type = object.media_type() let media_type = object.media_type()
.unwrap_or("link") // TODO make it an Option rather than defaulting to link everywhere .unwrap_or("link") // TODO make it an Option rather than defaulting to link everywhere
.to_string(); .to_string();
@ -78,7 +85,7 @@ pub fn Attachment(
view! { view! {
<p class="mt-s mb-s"> <p class="mt-s mb-s">
<a title={href.clone()} href={href.clone()} rel="noreferrer nofollow" target="_blank"> <a title={href.clone()} href={href.clone()} rel="noreferrer nofollow" target="_blank">
{Uri::pretty(&href, 50)} {Uri::pretty(&uncloaked, 50)}
</a> </a>
</p> </p>
}.into_view(), }.into_view(),