1
0
Fork 0
forked from alemi/upub

chore(web): leftovers

This commit is contained in:
əlemi 2024-05-21 15:28:48 +02:00
parent ff966a8a0e
commit e1ef98f763
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -120,7 +120,7 @@ impl Uri {
pub fn short(url: &str) -> String { pub fn short(url: &str) -> String {
if url.starts_with(URL_BASE) || url.starts_with('/') { if url.starts_with(URL_BASE) || url.starts_with('/') {
uriproxy::decompose_id(url) uriproxy::decompose_id(url)
} else if url.starts_with("https://") || url.starts_with("http") { } else if url.starts_with("https://") || url.starts_with("http://") {
uriproxy::compact_id(url) uriproxy::compact_id(url)
} else { } else {
url.to_string() url.to_string()
@ -128,26 +128,18 @@ impl Uri {
} }
/// convert url id to valid frontend view id: /// convert url id to valid frontend view id:
/// /web/users/test ///
/// /web/objects/+social.alemi.dev@objects@1204kasfkl
/// accepts: /// accepts:
/// - https://my.domain.net/users/root ///
/// - https://other.domain.net/unexpected/path/root
/// - +other.domain.net@users@root
/// - root
pub fn web(kind: UriClass, url: &str) -> String { pub fn web(kind: UriClass, url: &str) -> String {
let kind = kind.as_ref(); let kind = kind.as_ref();
format!("/web/{kind}/{}", Self::short(url)) format!("/web/{kind}/{}", Self::short(url))
} }
/// convert url id to valid backend api id /// convert url id to valid backend api id
/// https://feditest.alemi.dev/users/test ///
/// https://feditest.alemi.dev/users/+social.alemi.dev@users@alemi
/// accepts: /// accepts:
/// - https://my.domain.net/users/root ///
/// - https://other.domain.net/unexpected/path/root
/// - +other.domain.net@users@root
/// - root
pub fn api(kind: UriClass, url: &str, fetch: bool) -> String { pub fn api(kind: UriClass, url: &str, fetch: bool) -> String {
let kind = kind.as_ref(); let kind = kind.as_ref();
format!("{URL_BASE}/{kind}/{}{}", Self::short(url), if fetch { "?fetch=true" } else { "" }) format!("{URL_BASE}/{kind}/{}{}", Self::short(url), if fetch { "?fetch=true" } else { "" })