diff --git a/Cargo.lock b/Cargo.lock index a4edbf5..718f5c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4876,6 +4876,7 @@ name = "upub-web" version = "0.1.0" dependencies = [ "apb", + "base64 0.22.1", "chrono", "console_error_panic_hook", "cookie", diff --git a/web/Cargo.toml b/web/Cargo.toml index e66905a..33c59a1 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -14,6 +14,7 @@ repository = "https://git.alemi.dev/upub.git" [dependencies] lazy_static = "1.4" cookie = "0.18" +base64 = "0.22" tracing = "0.1" tracing-subscriber = "0.3" tracing-subscriber-wasm = "0.1" diff --git a/web/src/objects/attachment.rs b/web/src/objects/attachment.rs index 4e8b915..bc159cc 100644 --- a/web/src/objects/attachment.rs +++ b/web/src/objects/attachment.rs @@ -1,8 +1,14 @@ use leptos::*; use crate::{prelude::*, URL_SENSITIVE}; +use base64::prelude::*; use apb::{field::OptionalString, Document, Object}; +fn uncloak(txt: Option<&str>) -> Option { + let decoded = BASE64_URL_SAFE.decode(txt?).ok()?; + Some(std::str::from_utf8(&decoded).ok()?.to_string()) +} + #[component] pub fn Attachment( object: serde_json::Value, @@ -12,6 +18,7 @@ pub fn Attachment( let config = use_context::>().expect("missing config context"); let (expand, set_expand) = create_signal(false); let href = object.url().id().str().unwrap_or_default(); + let uncloaked = uncloak(href.split('/').last()).unwrap_or_default(); let media_type = object.media_type() .unwrap_or("link") // TODO make it an Option rather than defaulting to link everywhere .to_string(); @@ -78,7 +85,7 @@ pub fn Attachment( view! {

- {Uri::pretty(&href, 50)} + {Uri::pretty(&uncloaked, 50)}

}.into_view(),