Get rid of remove_path_prefix, it's not useful

This commit is contained in:
Brian Picciano 2023-07-19 21:27:03 +02:00
parent 188ebaa30b
commit b81b59fc0a
4 changed files with 2 additions and 70 deletions

View File

@ -14,7 +14,6 @@ pub struct Settings {
#[serde(flatten)] #[serde(flatten)]
pub origin_descr: origin::Descr, pub origin_descr: origin::Descr,
pub remove_path_prefix: Option<String>,
pub add_path_prefix: Option<String>, pub add_path_prefix: Option<String>,
} }
@ -25,31 +24,6 @@ impl Settings {
Ok(h.finalize().encode_hex::<String>()) 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>( fn add_path_prefix<'path, 'prefix>(
path: borrow::Cow<'path, str>, path: borrow::Cow<'path, str>,
prefix: &'prefix str, prefix: &'prefix str,
@ -73,10 +47,6 @@ impl Settings {
pub fn process_path<'a>(&self, path: &'a str) -> borrow::Cow<'a, str> { pub fn process_path<'a>(&self, path: &'a str) -> borrow::Cow<'a, str> {
let mut path = borrow::Cow::Borrowed(path); 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 { if let Some(ref prefix) = self.add_path_prefix {
path = Self::add_path_prefix(path, prefix); path = Self::add_path_prefix(path, prefix);
} }
@ -90,26 +60,6 @@ mod tests {
use super::*; use super::*;
use std::borrow; 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] #[test]
fn add_path_prefix() { fn add_path_prefix() {
let assert_add = |want: &str, path: &str, prefix: &str| { let assert_add = |want: &str, path: &str, prefix: &str| {

View File

@ -181,7 +181,6 @@ mod tests {
url: "bar".to_string(), url: "bar".to_string(),
branch_name: "baz".to_string(), branch_name: "baz".to_string(),
}, },
remove_path_prefix: None,
add_path_prefix: None, add_path_prefix: None,
}; };
@ -205,7 +204,6 @@ mod tests {
url: "BAR".to_string(), url: "BAR".to_string(),
branch_name: "BAZ".to_string(), branch_name: "BAZ".to_string(),
}, },
remove_path_prefix: None,
add_path_prefix: None, add_path_prefix: None,
}; };

View File

@ -51,23 +51,13 @@ automatically updated too!</p>
<fieldset> <fieldset>
<legend>Advanced Settings</legend> <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> <p>
<label> <label>
Prefix to add to URL paths: Directory or sub-directory to serve files from:
<input name="domain_setting_add_path_prefix" <input name="domain_setting_add_path_prefix"
type="text" type="text"
placeholder="/foo/bar" placeholder="directory/sub-directory"
value="{{ data.settings.add_path_prefix }}" value="{{ data.settings.add_path_prefix }}"
required /> required />
</label> </label>

View File

@ -15,10 +15,6 @@ pub struct FlatDomainSettings {
domain_setting_origin_descr_proxy_url: Option<String>, domain_setting_origin_descr_proxy_url: Option<String>,
#[serde(default)]
#[serde_as(as = "NoneAsEmptyString")]
domain_setting_remove_path_prefix: Option<String>,
#[serde(default)] #[serde(default)]
#[serde_as(as = "NoneAsEmptyString")] #[serde_as(as = "NoneAsEmptyString")]
domain_setting_add_path_prefix: Option<String>, domain_setting_add_path_prefix: Option<String>,
@ -43,7 +39,6 @@ impl TryFrom<FlatDomainSettings> for domain::Settings {
Ok(Self { Ok(Self {
origin_descr, origin_descr,
remove_path_prefix: v.domain_setting_remove_path_prefix,
add_path_prefix: v.domain_setting_add_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; res.domain_setting_add_path_prefix = v.add_path_prefix;
Ok(res) Ok(res)