docs(web): documented web_uri and api_uri

This commit is contained in:
əlemi 2024-04-15 23:11:52 +02:00
parent 920ef598f5
commit 0d2c279f93
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -15,19 +15,31 @@ struct LoginForm {
password: String, password: String,
} }
/// convert url id to valid frontend view id
/// accepts:
/// - https://my.domain.net/users/root
/// - https://other.domain.net/unexpected/path/root
/// - +other.domain.net@users@root
/// - root
fn web_uri(kind: &str, url: &str) -> String { fn web_uri(kind: &str, url: &str) -> String {
if url.starts_with(URL_BASE) { if url.starts_with(URL_BASE) {
format!("/web/{kind}/{}", url.split('/').last().unwrap_or_default()) format!("/web/{kind}/{}", url.split('/').last().unwrap_or_default())
} else { } else {
format!("/web/{kind}/+{}", url.replace("https://", "").replace('/', "@")) format!("/web/{kind}/{}", url.replace("https://", "+").replace('/', "@"))
} }
} }
/// convert url id to valid backend api id
/// accepts:
/// - https://my.domain.net/users/root
/// - https://other.domain.net/unexpected/path/root
/// - +other.domain.net@users@root
/// - root
fn api_uri(kind: &str, url: &str) -> String { fn api_uri(kind: &str, url: &str) -> String {
if url.starts_with(URL_BASE) { if url.starts_with(URL_BASE) {
url.to_string() url.to_string()
} else { } else {
format!("{URL_BASE}/{kind}/+{}", url.replace("https://", "").replace('/', "@")) format!("{URL_BASE}/{kind}/{}", url.replace("https://", "+").replace('/', "@"))
} }
} }