diff --git a/crates/ptth_server/src/bin/ptth_server.rs b/crates/ptth_server/src/bin/ptth_server.rs index 53ba1f2..1b61058 100644 --- a/crates/ptth_server/src/bin/ptth_server.rs +++ b/crates/ptth_server/src/bin/ptth_server.rs @@ -19,6 +19,9 @@ struct Opt { #[structopt (long)] auto_gen_key: bool, + #[structopt (long)] + simulate_slow_upload: bool, + #[structopt (long)] file_server_root: Option , @@ -85,8 +88,9 @@ async fn main () -> Result <(), anyhow::Error> { let config_file = ptth_server::ConfigFile { name: opt.name.or (config_file.name).expect ("`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).expect ("`relay_url` must be provided in command line of config file"), + relay_url: opt.relay_url.or (config_file.relay_url).expect ("`relay_url` must be provided in command line or config file"), file_server_root: opt.file_server_root.or (config_file.file_server_root), + simulate_slow_upload: opt.simulate_slow_upload, }; if opt.print_tripcode { diff --git a/crates/ptth_server/src/lib.rs b/crates/ptth_server/src/lib.rs index 0c6efc1..bb5e852 100644 --- a/crates/ptth_server/src/lib.rs +++ b/crates/ptth_server/src/lib.rs @@ -149,15 +149,27 @@ async fn handle_req_resp ( // type to load an incomplete file, as long as the command line options // complete it. -#[derive (Default)] +#[derive (Clone)] pub struct ConfigFile { pub name: String, pub api_key: String, pub relay_url: String, pub file_server_root: Option , + pub simulate_slow_upload: bool, } impl ConfigFile { + #[must_use] + pub fn new (name: String, api_key: String, relay_url: String) -> Self { + Self { + name, + api_key, + relay_url, + file_server_root: None, + simulate_slow_upload: false, + } + } + #[must_use] pub fn tripcode (&self) -> String { base64::encode (blake3::hash (self.api_key.as_bytes ()).as_bytes ()) @@ -317,12 +329,11 @@ mod tests { #[test] fn tripcode_algo () { - let config = ConfigFile { - name: "TestName".into (), - api_key: "PlaypenCausalPlatformCommodeImproveCatalyze".into (), - relay_url: "".into (), - file_server_root: None, - }; + let config = ConfigFile::new ( + "TestName".into (), + "PlaypenCausalPlatformCommodeImproveCatalyze".into (), + "".into (), + ); assert_eq! (config.tripcode (), "A9rPwZyY89Ag4TJjMoyYA2NeGOm99Je6rq1s0rg8PfY=".to_string ()); } diff --git a/src/main.rs b/src/main.rs index cce7c79..b7bd88a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,12 +74,11 @@ async fn main () -> anyhow::Result <()> { let relay_url = format! ("http://127.0.0.1:{}", proxy_port); - let config_file = ptth_server::ConfigFile { - name: server_name.into (), - api_key: api_key.into (), - relay_url: format! ("{}/7ZSFUKGV", relay_url), - file_server_root: None, - }; + let config_file = ptth_server::ConfigFile::new ( + server_name.into (), + api_key.into (), + format! ("{}/7ZSFUKGV", relay_url), + ); let (stop_server_tx, stop_server_rx) = oneshot::channel (); let task_server = { diff --git a/src/tests.rs b/src/tests.rs index 050decd..657702a 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -147,12 +147,11 @@ impl TestingRelay { impl TestingServer { async fn new (testing_config: &TestingConfig) -> Self { - let config_file = ptth_server::ConfigFile { - name: testing_config.server_name.into (), - api_key: testing_config.api_key.into (), - relay_url: format! ("{}/7ZSFUKGV", testing_config.relay_url ()), - file_server_root: None, - }; + let config_file = ptth_server::ConfigFile::new ( + testing_config.server_name.into (), + testing_config.api_key.into (), + format! ("{}/7ZSFUKGV", testing_config.relay_url ()), + ); let (stop_tx, stop_rx) = oneshot::channel (); let task = {