fix(uriproxy): if uri is ready just pass it thru

This commit is contained in:
əlemi 2024-05-20 07:42:58 +02:00
parent aca757a266
commit fa3f0f853a
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -21,6 +21,10 @@ impl AsRef<str> for UriClass {
/// unpack uri in id if valid, otherwise compose full uri with "{base}/{entity}/{id}" /// unpack uri in id if valid, otherwise compose full uri with "{base}/{entity}/{id}"
pub fn uri(base: &str, entity: UriClass, id: &str) -> String { pub fn uri(base: &str, entity: UriClass, id: &str) -> String {
if id.starts_with("https://") || id.starts_with("http://") {
return id.to_string();
}
if id.starts_with('+') { // ready-to-use base64-encoded id if id.starts_with('+') { // ready-to-use base64-encoded id
if let Ok(bytes) = base64::prelude::BASE64_URL_SAFE_NO_PAD.decode(id.replacen('+', "", 1)) { if let Ok(bytes) = base64::prelude::BASE64_URL_SAFE_NO_PAD.decode(id.replacen('+', "", 1)) {
if let Ok(uri) = std::str::from_utf8(&bytes) { if let Ok(uri) = std::str::from_utf8(&bytes) {
@ -28,6 +32,7 @@ pub fn uri(base: &str, entity: UriClass, id: &str) -> String {
} }
} }
} }
format!("{}/{}/{}", base, entity.as_ref(), id) format!("{}/{}/{}", base, entity.as_ref(), id)
} }