➕ add multi-root
parent
436adb98ef
commit
fb9b0c67f5
|
@ -257,21 +257,38 @@ struct RoutedPath <'a> {
|
|||
|
||||
impl <'a> FileRoots <'a> {
|
||||
fn route (self, input: &'a str) -> Result <Option <RoutedPath>, FileServerError> {
|
||||
let path = match input.strip_prefix ("/files/") {
|
||||
Some (x) => x,
|
||||
None => return Ok (None),
|
||||
};
|
||||
|
||||
// TODO: There is totally a dir traversal attack in here somewhere
|
||||
|
||||
let encoded_path = &path [0..];
|
||||
if let Some (path) = input.strip_prefix ("/dirs/") {
|
||||
if let Some ((dir, path)) = path.split_once ('/') {
|
||||
let root = match self.dirs.get (dir) {
|
||||
None => return Ok (None),
|
||||
Some (x) => x,
|
||||
};
|
||||
|
||||
let path_s = percent_decode (encoded_path.as_bytes ()).decode_utf8 ().map_err (FileServerError::PathNotUtf8)?;
|
||||
let path_s = percent_decode (path.as_bytes ()).decode_utf8 ().map_err (FileServerError::PathNotUtf8)?;
|
||||
|
||||
Ok (Some (RoutedPath {
|
||||
root: self.files,
|
||||
path_s,
|
||||
}))
|
||||
return Ok (Some (RoutedPath {
|
||||
root,
|
||||
path_s,
|
||||
}));
|
||||
}
|
||||
else {
|
||||
return Ok (None);
|
||||
}
|
||||
}
|
||||
if let Some (path) = input.strip_prefix ("/files/") {
|
||||
let encoded_path = &path [0..];
|
||||
|
||||
let path_s = percent_decode (encoded_path.as_bytes ()).decode_utf8 ().map_err (FileServerError::PathNotUtf8)?;
|
||||
|
||||
return Ok (Some (RoutedPath {
|
||||
root: self.files,
|
||||
path_s,
|
||||
}));
|
||||
}
|
||||
|
||||
return Ok (None);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue