From 81141e2faf1b075a7fc7c16f12d84053e2ec74c6 Mon Sep 17 00:00:00 2001 From: Trisha Date: Fri, 25 Mar 2022 15:30:38 -0500 Subject: [PATCH] :heavy_plus_sign: add `file_server_roots` config --- crates/ptth_server/src/lib.rs | 15 ++++++++++++++- crates/ptth_server_gui/src/main.rs | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/ptth_server/src/lib.rs b/crates/ptth_server/src/lib.rs index 4f8e26a..c90093d 100644 --- a/crates/ptth_server/src/lib.rs +++ b/crates/ptth_server/src/lib.rs @@ -207,9 +207,14 @@ pub struct ConfigFile { pub relay_url: String, /// 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, + /// 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 , + /// For debugging. pub throttle_upload: bool, @@ -226,6 +231,7 @@ impl ConfigFile { api_key, relay_url, file_server_root: PathBuf::from ("."), + file_server_roots: Default::default (), throttle_upload: false, client_keys: Default::default (), allow_any_client: true, @@ -268,6 +274,7 @@ impl Builder { api_key: ptth_core::gen_key (), relay_url, file_server_root: PathBuf::from ("."), + file_server_roots: Default::default (), throttle_upload: false, client_keys: Default::default (), allow_any_client: true, @@ -529,6 +536,12 @@ pub mod executable { 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).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, allow_any_client: true, client_keys: Default::default (), diff --git a/crates/ptth_server_gui/src/main.rs b/crates/ptth_server_gui/src/main.rs index f9f7e10..fe6dba8 100644 --- a/crates/ptth_server_gui/src/main.rs +++ b/crates/ptth_server_gui/src/main.rs @@ -1,4 +1,5 @@ use std::{ + collections::*, path::PathBuf, }; @@ -59,7 +60,10 @@ 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: 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, client_keys: Default::default (), allow_any_client: true, @@ -110,6 +114,7 @@ pub struct ConfigFile { pub api_key: String, pub relay_url: Option , pub file_server_root: Option , + pub file_server_roots: BTreeMap , } impl Gui {