add `file_server_roots` config

main
Trisha 2022-03-25 15:30:38 -05:00
parent 8c4e7d484c
commit 81141e2faf
2 changed files with 20 additions and 2 deletions

View File

@ -207,9 +207,14 @@ pub struct ConfigFile {
pub relay_url: String, pub relay_url: String,
/// Directory that the file server module will expose to clients /// Directory that the file server module will expose to clients
/// over the relay. If None, the current working dir is used. /// over the relay, under `/files`. If None, the current working dir is used.
pub file_server_root: PathBuf, pub file_server_root: PathBuf,
/// The file server module will expose these directories to clients under
/// `/dirs`. If symlinks can't be used (like on Windows), this allows PTTH
/// to serve multiple directories easily.
pub file_server_roots: BTreeMap <String, PathBuf>,
/// For debugging. /// For debugging.
pub throttle_upload: bool, pub throttle_upload: bool,
@ -226,6 +231,7 @@ impl ConfigFile {
api_key, api_key,
relay_url, relay_url,
file_server_root: PathBuf::from ("."), file_server_root: PathBuf::from ("."),
file_server_roots: Default::default (),
throttle_upload: false, throttle_upload: false,
client_keys: Default::default (), client_keys: Default::default (),
allow_any_client: true, allow_any_client: true,
@ -268,6 +274,7 @@ impl Builder {
api_key: ptth_core::gen_key (), api_key: ptth_core::gen_key (),
relay_url, relay_url,
file_server_root: PathBuf::from ("."), file_server_root: PathBuf::from ("."),
file_server_roots: Default::default (),
throttle_upload: false, throttle_upload: false,
client_keys: Default::default (), client_keys: Default::default (),
allow_any_client: true, allow_any_client: true,
@ -529,6 +536,12 @@ pub mod executable {
api_key: config_file.api_key, 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"))?, 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).unwrap_or_else (PathBuf::new), file_server_root: opt.file_server_root.or (config_file.file_server_root).unwrap_or_else (PathBuf::new),
file_server_roots: vec! [
("c", "C:/"),
("d", "D:/"),
].into_iter ()
.map (|(k, v)| (String::from (k), PathBuf::from (v)))
.collect (),
throttle_upload: opt.throttle_upload, throttle_upload: opt.throttle_upload,
allow_any_client: true, allow_any_client: true,
client_keys: Default::default (), client_keys: Default::default (),

View File

@ -1,4 +1,5 @@
use std::{ use std::{
collections::*,
path::PathBuf, path::PathBuf,
}; };
@ -59,7 +60,10 @@ fn main ()
name: gui.input_name.value ().to_string (), name: gui.input_name.value ().to_string (),
api_key: gui.input_api_key.value ().to_string (), api_key: gui.input_api_key.value ().to_string (),
relay_url: gui.input_relay_url.value ().to_string (), relay_url: gui.input_relay_url.value ().to_string (),
file_server_root: std::path::PathBuf::from (gui.input_file_server_root.value ()), file_server_root: PathBuf::from (gui.input_file_server_root.value ()),
file_server_roots: config_file_opt.as_ref ()
.map (|cf| cf.file_server_roots.clone ())
.unwrap_or_else (|| Default::default ()),
throttle_upload: false, throttle_upload: false,
client_keys: Default::default (), client_keys: Default::default (),
allow_any_client: true, allow_any_client: true,
@ -110,6 +114,7 @@ pub struct ConfigFile {
pub api_key: String, pub api_key: String,
pub relay_url: Option <String>, pub relay_url: Option <String>,
pub file_server_root: Option <PathBuf>, pub file_server_root: Option <PathBuf>,
pub file_server_roots: BTreeMap <String, PathBuf>,
} }
impl Gui { impl Gui {