forked from alemi/upub
fix(uriproxy): use URL_SAFE base64 alphabet
This commit is contained in:
parent
f9e021a37a
commit
4a17c12b58
2 changed files with 6 additions and 6 deletions
|
@ -124,7 +124,7 @@ impl Context {
|
||||||
uriproxy::uri(self.base(), UriClass::Context, id)
|
uriproxy::uri(self.base(), UriClass::Context, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get bare id, which is uuid for local stuff and ~{uri|base64} for remote stuff
|
/// get bare id, which is uuid for local stuff and +{uri|base64} for remote stuff
|
||||||
pub fn id(&self, full_id: &str) -> String {
|
pub fn id(&self, full_id: &str) -> String {
|
||||||
if self.is_local(full_id) {
|
if self.is_local(full_id) {
|
||||||
uriproxy::decompose_id(full_id)
|
uriproxy::decompose_id(full_id)
|
||||||
|
|
|
@ -21,8 +21,8 @@ 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('~') { // ready-to-use base64-encoded id
|
if id.starts_with('+') { // ready-to-use base64-encoded id
|
||||||
if let Ok(bytes) = base64::prelude::BASE64_STANDARD.decode(id) {
|
if let Ok(bytes) = base64::prelude::BASE64_URL_SAFE.decode(id) {
|
||||||
if let Ok(uri) = std::str::from_utf8(&bytes) {
|
if let Ok(uri) = std::str::from_utf8(&bytes) {
|
||||||
return uri.to_string();
|
return uri.to_string();
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ pub fn decompose_id(full_id: &str) -> String {
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// encode with base64 remote url and prefix it with ~
|
/// encode with base64 remote url and prefix it with +
|
||||||
pub fn compact_id(uri: &str) -> String {
|
pub fn compact_id(uri: &str) -> String {
|
||||||
let encoded = base64::prelude::BASE64_STANDARD.encode(uri.as_bytes());
|
let encoded = base64::prelude::BASE64_URL_SAFE.encode(uri.as_bytes());
|
||||||
format!("~{encoded}")
|
format!("+{encoded}")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue