Get rid of remove_path_prefix, it's not useful
This commit is contained in:
parent
188ebaa30b
commit
b81b59fc0a
@ -14,7 +14,6 @@ pub struct Settings {
|
||||
#[serde(flatten)]
|
||||
pub origin_descr: origin::Descr,
|
||||
|
||||
pub remove_path_prefix: Option<String>,
|
||||
pub add_path_prefix: Option<String>,
|
||||
}
|
||||
|
||||
@ -25,31 +24,6 @@ impl Settings {
|
||||
Ok(h.finalize().encode_hex::<String>())
|
||||
}
|
||||
|
||||
fn remove_path_prefix<'path, 'prefix>(
|
||||
path: borrow::Cow<'path, str>,
|
||||
prefix: &'prefix str,
|
||||
) -> borrow::Cow<'path, str> {
|
||||
if prefix.len() == 0 {
|
||||
return path;
|
||||
}
|
||||
|
||||
let mut prefix = prefix.trim_end_matches('/');
|
||||
prefix = prefix.trim_start_matches('/');
|
||||
|
||||
let mut stripped_path = path.trim_start_matches('/');
|
||||
|
||||
if !stripped_path.starts_with(prefix) {
|
||||
return path;
|
||||
}
|
||||
|
||||
stripped_path = stripped_path.strip_prefix(prefix).unwrap();
|
||||
if stripped_path.len() == 0 {
|
||||
return borrow::Cow::Borrowed("/");
|
||||
}
|
||||
|
||||
borrow::Cow::Owned(stripped_path.to_string())
|
||||
}
|
||||
|
||||
fn add_path_prefix<'path, 'prefix>(
|
||||
path: borrow::Cow<'path, str>,
|
||||
prefix: &'prefix str,
|
||||
@ -73,10 +47,6 @@ impl Settings {
|
||||
pub fn process_path<'a>(&self, path: &'a str) -> borrow::Cow<'a, str> {
|
||||
let mut path = borrow::Cow::Borrowed(path);
|
||||
|
||||
if let Some(ref prefix) = self.remove_path_prefix {
|
||||
path = Self::remove_path_prefix(path, prefix);
|
||||
}
|
||||
|
||||
if let Some(ref prefix) = self.add_path_prefix {
|
||||
path = Self::add_path_prefix(path, prefix);
|
||||
}
|
||||
@ -90,26 +60,6 @@ mod tests {
|
||||
use super::*;
|
||||
use std::borrow;
|
||||
|
||||
#[test]
|
||||
fn remove_path_prefix() {
|
||||
let assert_remove = |want: &str, path: &str, prefix: &str| {
|
||||
assert_eq!(
|
||||
want,
|
||||
Settings::remove_path_prefix(borrow::Cow::Borrowed(path), prefix).as_ref(),
|
||||
)
|
||||
};
|
||||
|
||||
assert_remove("/bar", "/foo/bar", "/foo");
|
||||
assert_remove("/foo/bar", "/foo/bar", "/baz");
|
||||
assert_remove("/bar", "/foo/bar", "/foo/");
|
||||
assert_remove("/bar", "/foo/bar", "/foo///");
|
||||
assert_remove("/", "/", "/");
|
||||
assert_remove("/", "/foo/bar/", "/foo/bar");
|
||||
assert_remove("/", "/foo/bar", "/foo/bar");
|
||||
assert_remove("/", "/foo/bar", "/foo/bar///");
|
||||
assert_remove("/bar", "/bar", "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_path_prefix() {
|
||||
let assert_add = |want: &str, path: &str, prefix: &str| {
|
||||
|
@ -181,7 +181,6 @@ mod tests {
|
||||
url: "bar".to_string(),
|
||||
branch_name: "baz".to_string(),
|
||||
},
|
||||
remove_path_prefix: None,
|
||||
add_path_prefix: None,
|
||||
};
|
||||
|
||||
@ -205,7 +204,6 @@ mod tests {
|
||||
url: "BAR".to_string(),
|
||||
branch_name: "BAZ".to_string(),
|
||||
},
|
||||
remove_path_prefix: None,
|
||||
add_path_prefix: None,
|
||||
};
|
||||
|
||||
|
@ -51,23 +51,13 @@ automatically updated too!</p>
|
||||
|
||||
<fieldset>
|
||||
<legend>Advanced Settings</legend>
|
||||
<p>
|
||||
<label>
|
||||
Prefix to remove from URL paths:
|
||||
<input name="domain_setting_remove_path_prefix"
|
||||
type="text"
|
||||
placeholder="/foo/bar"
|
||||
value="{{ data.settings.remove_path_prefix }}"
|
||||
required />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
Prefix to add to URL paths:
|
||||
Directory or sub-directory to serve files from:
|
||||
<input name="domain_setting_add_path_prefix"
|
||||
type="text"
|
||||
placeholder="/foo/bar"
|
||||
placeholder="directory/sub-directory"
|
||||
value="{{ data.settings.add_path_prefix }}"
|
||||
required />
|
||||
</label>
|
||||
|
@ -15,10 +15,6 @@ pub struct FlatDomainSettings {
|
||||
|
||||
domain_setting_origin_descr_proxy_url: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "NoneAsEmptyString")]
|
||||
domain_setting_remove_path_prefix: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "NoneAsEmptyString")]
|
||||
domain_setting_add_path_prefix: Option<String>,
|
||||
@ -43,7 +39,6 @@ impl TryFrom<FlatDomainSettings> for domain::Settings {
|
||||
|
||||
Ok(Self {
|
||||
origin_descr,
|
||||
remove_path_prefix: v.domain_setting_remove_path_prefix,
|
||||
add_path_prefix: v.domain_setting_add_path_prefix,
|
||||
})
|
||||
}
|
||||
@ -68,7 +63,6 @@ impl TryFrom<domain::Settings> for FlatDomainSettings {
|
||||
}
|
||||
}
|
||||
|
||||
res.domain_setting_remove_path_prefix = v.remove_path_prefix;
|
||||
res.domain_setting_add_path_prefix = v.add_path_prefix;
|
||||
|
||||
Ok(res)
|
||||
|
Loading…
Reference in New Issue
Block a user