♻️ refactor: remove pointless `Option <>` for file server root
parent
259f71b478
commit
324c1f7cd6
|
@ -95,7 +95,7 @@ async fn main () -> anyhow::Result <()> {
|
|||
});
|
||||
|
||||
let state = Arc::new (FileServer::new (
|
||||
config_file.file_server_root,
|
||||
config_file.file_server_root.unwrap_or_else (|| PathBuf::from (".")),
|
||||
&PathBuf::new (),
|
||||
config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ()),
|
||||
metrics_interval,
|
||||
|
|
|
@ -105,7 +105,7 @@ async fn main () -> Result <(), anyhow::Error> {
|
|||
name: opt.name.or (config_file.name).ok_or (anyhow::anyhow! ("`name` must be provided in command line or config file"))?,
|
||||
api_key: config_file.api_key,
|
||||
relay_url: opt.relay_url.or (config_file.relay_url).ok_or (anyhow::anyhow! ("`--relay-url` must be provided in command line or `relay_url` in config file"))?,
|
||||
file_server_root: opt.file_server_root.or (config_file.file_server_root),
|
||||
file_server_root: opt.file_server_root.or (config_file.file_server_root).unwrap_or_else (|| PathBuf::from (".")),
|
||||
throttle_upload: opt.throttle_upload,
|
||||
};
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ use errors::FileServerError;
|
|||
|
||||
#[derive (Default)]
|
||||
pub struct Config {
|
||||
pub file_server_root: Option <PathBuf>,
|
||||
pub file_server_root: PathBuf,
|
||||
}
|
||||
|
||||
pub struct FileServer {
|
||||
|
@ -69,7 +69,7 @@ pub struct FileServer {
|
|||
|
||||
impl FileServer {
|
||||
pub fn new (
|
||||
file_server_root: Option <PathBuf>,
|
||||
file_server_root: PathBuf,
|
||||
asset_root: &Path,
|
||||
name: String,
|
||||
metrics_interval: Arc <ArcSwap <Option <metrics::Interval>>>,
|
||||
|
@ -364,10 +364,7 @@ impl FileServer {
|
|||
resp
|
||||
}
|
||||
|
||||
let default_root = PathBuf::from ("./");
|
||||
let root: &std::path::Path = self.config.file_server_root
|
||||
.as_ref ()
|
||||
.unwrap_or (&default_root);
|
||||
let root: &std::path::Path = &self.config.file_server_root;
|
||||
|
||||
Ok (match internal::serve_all (root, method, uri, headers, self.hidden_path.as_deref ()).await? {
|
||||
Favicon => serve_error (StatusCode::NotFound, "Not found\n"),
|
||||
|
|
|
@ -214,7 +214,7 @@ pub struct ConfigFile {
|
|||
|
||||
/// Directory that the file server module will expose to clients
|
||||
/// over the relay. If None, the current working dir is used.
|
||||
pub file_server_root: Option <PathBuf>,
|
||||
pub file_server_root: PathBuf,
|
||||
|
||||
/// For debugging.
|
||||
pub throttle_upload: bool,
|
||||
|
@ -227,7 +227,7 @@ impl ConfigFile {
|
|||
name,
|
||||
api_key,
|
||||
relay_url,
|
||||
file_server_root: None,
|
||||
file_server_root: PathBuf::from ("."),
|
||||
throttle_upload: false,
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ impl Builder {
|
|||
name,
|
||||
api_key: ptth_core::gen_key (),
|
||||
relay_url,
|
||||
file_server_root: None,
|
||||
file_server_root: PathBuf::from ("."),
|
||||
throttle_upload: false,
|
||||
};
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ fn main ()
|
|||
name: gui.input_name.value ().to_string (),
|
||||
api_key: gui.input_api_key.value ().to_string (),
|
||||
relay_url: gui.input_relay_url.value ().to_string (),
|
||||
file_server_root: Some (std::path::PathBuf::from (gui.input_file_server_root.value ())),
|
||||
file_server_root: std::path::PathBuf::from (gui.input_file_server_root.value ()),
|
||||
throttle_upload: false,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue