✨ Clean url with suffix
This commit is contained in:
@@ -98,20 +98,23 @@ impl Destination {
|
||||
.get("utf8")
|
||||
.and_then(|val| val.as_bool())
|
||||
.unwrap_or(false),
|
||||
with_slash: queries
|
||||
.get("slash")
|
||||
.and_then(|val| val.as_bool())
|
||||
.unwrap_or(false),
|
||||
browse: queries
|
||||
.get("browse")
|
||||
.and_then(|val| val.as_bool())
|
||||
.unwrap_or(false),
|
||||
with_slash: queries
|
||||
.get("slash")
|
||||
.and_then(|val| val.as_bool())
|
||||
.unwrap_or(false),
|
||||
index: queries
|
||||
.get("index")
|
||||
.and_then(|val| val.as_str().map(str::to_string)),
|
||||
fallback: queries
|
||||
.get("fallback")
|
||||
.and_then(|val| val.as_str().map(str::to_string)),
|
||||
suffix: queries
|
||||
.get("suffix")
|
||||
.and_then(|val| val.as_str().map(str::to_string)),
|
||||
})
|
||||
}
|
||||
_ => Err(()),
|
||||
|
@@ -20,7 +20,9 @@ pub fn scan_regions(basepath: String) -> io::Result<(Vec<config::Region>, u32)>
|
||||
}
|
||||
|
||||
pub fn load_region(file: DirEntry) -> Result<config::Region, String> {
|
||||
if file.path().extension().and_then(OsStr::to_str).unwrap() != "toml" {
|
||||
if file.metadata().map(|val| val.is_dir()).unwrap()
|
||||
|| file.path().extension().and_then(OsStr::to_str).unwrap() != "toml"
|
||||
{
|
||||
return Err("File entry wasn't toml file".to_string());
|
||||
}
|
||||
|
||||
|
@@ -97,10 +97,11 @@ pub async fn respond_hypertext(
|
||||
pub struct StaticResponderConfig {
|
||||
pub uri: String,
|
||||
pub utf8: bool,
|
||||
pub with_slash: bool,
|
||||
pub browse: bool,
|
||||
pub with_slash: bool,
|
||||
pub index: Option<String>,
|
||||
pub fallback: Option<String>,
|
||||
pub suffix: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn respond_static(
|
||||
@@ -142,6 +143,22 @@ pub async fn respond_static(
|
||||
}
|
||||
|
||||
if !file_path.exists() {
|
||||
if let Some(suffix) = cfg.suffix {
|
||||
let file_name = file_path
|
||||
.file_name()
|
||||
.and_then(OsStr::to_str)
|
||||
.unwrap()
|
||||
.to_string();
|
||||
file_path.pop();
|
||||
file_path.push((file_name + &suffix).as_str());
|
||||
if file_path.is_file() {
|
||||
return Ok(StaticFileRequest::from_request_without_body(req)
|
||||
.await?
|
||||
.create_response(&file_path, cfg.utf8)?
|
||||
.into_response());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(file) = cfg.fallback {
|
||||
let fallback_path = base_path.join(file);
|
||||
if fallback_path.is_file() {
|
||||
|
Reference in New Issue
Block a user