diff --git a/Cargo.lock b/Cargo.lock index a0e9fec..b3bcc62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1443,7 +1443,7 @@ dependencies = [ [[package]] name = "ptth_core" -version = "1.4.0" +version = "2.0.0" dependencies = [ "base64", "ctrlc", @@ -1529,7 +1529,7 @@ dependencies = [ [[package]] name = "ptth_relay" -version = "1.3.0" +version = "2.0.0" dependencies = [ "base64", "blake3", diff --git a/crates/ptth_core/Cargo.toml b/crates/ptth_core/Cargo.toml index 13b557f..412637e 100644 --- a/crates/ptth_core/Cargo.toml +++ b/crates/ptth_core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ptth_core" -version = "1.4.0" +version = "2.0.0" authors = ["Trish"] edition = "2018" license = "AGPL-3.0" diff --git a/crates/ptth_core/src/lib.rs b/crates/ptth_core/src/lib.rs index bf16068..fec27a5 100644 --- a/crates/ptth_core/src/lib.rs +++ b/crates/ptth_core/src/lib.rs @@ -22,19 +22,6 @@ pub mod prelude; pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4"; -// The arguments are in order so they are in order overall: -// e.g. prefix_match ("/prefix", "/prefix/middle/suffix") -> "/middle/suffix" - -#[must_use] -#[deprecated ( - since = "1.4.0", - note = "Use `str::strip_prefix instead`" -)] -pub fn prefix_match <'a> (prefix: &str, hay: &'a str) -> Option <&'a str> -{ - hay.strip_prefix (prefix) -} - /// Generates 64 bytes of entropy and returns it as Base64 pub fn gen_key () -> String { @@ -48,16 +35,17 @@ pub fn gen_key () -> String { #[cfg (test)] mod tests { use super::*; + #[test] - fn prefix () { - for (p, h, expected) in &[ - ("/files/", "/files/a", Some ("a")), - ("/files/", "/files/abc/def", Some ("abc/def")), - ("/files/", "/files", None), - ("/files/", "/not_files", None), - ("/files/", "/files/", Some ("")), - ] { - assert_eq! (prefix_match (*p, *h), *expected); - } + fn test_gen_key () { + // Smoke test + + let blank = base64::encode (&vec! [0_u8; 64]); + let a = gen_key (); + let b = gen_key (); + + assert_ne! (blank, a); + assert_ne! (blank, b); + assert_ne! (a, b); } } diff --git a/crates/ptth_relay/Cargo.toml b/crates/ptth_relay/Cargo.toml index 0290303..fc39059 100644 --- a/crates/ptth_relay/Cargo.toml +++ b/crates/ptth_relay/Cargo.toml @@ -35,4 +35,4 @@ tracing = "0.1.25" tracing-futures = "0.2.4" tracing-subscriber = "0.2.15" -ptth_core = { path = "../ptth_core", version = "1.4.0" } +ptth_core = { path = "../ptth_core", version = "2.0.0" } diff --git a/crates/ptth_relay/src/lib.rs b/crates/ptth_relay/src/lib.rs index 44d52b3..74a8641 100644 --- a/crates/ptth_relay/src/lib.rs +++ b/crates/ptth_relay/src/lib.rs @@ -56,7 +56,6 @@ use tokio_stream::wrappers::ReceiverStream; use ptth_core::{ http_serde, - prefix_match, prelude::*, }; @@ -559,7 +558,7 @@ async fn handle_all ( Ok (response) } -pub fn load_templates (asset_root: &Path) +fn load_templates (asset_root: &Path) -> Result , RelayError> { let mut handlebars = Handlebars::new (); @@ -606,7 +605,7 @@ async fn reload_config ( pub async fn run_relay ( state: Arc , - handlebars: Arc >, + asset_root: &Path, shutdown_oneshot: oneshot::Receiver <()>, config_reload_path: Option ) @@ -617,6 +616,8 @@ pub async fn run_relay ( AuditEvent, }; + let handlebars = Arc::new (load_templates (asset_root)?); + if let Some (x) = git_version::read ().await { info! ("ptth_relay Git version: {:?}", x); } diff --git a/crates/ptth_relay/src/main.rs b/crates/ptth_relay/src/main.rs index 394e0d5..8b2d617 100644 --- a/crates/ptth_relay/src/main.rs +++ b/crates/ptth_relay/src/main.rs @@ -55,7 +55,7 @@ async fn main () -> Result <(), Box > { forced_shutdown.wrap_server ( run_relay ( Arc::new (RelayState::try_from (config)?), - Arc::new (ptth_relay::load_templates (&PathBuf::new ())?), + &PathBuf::new (), shutdown_rx, Some (config_path) ) diff --git a/crates/ptth_relay/src/scraper_api.rs b/crates/ptth_relay/src/scraper_api.rs index a5cbd5f..22693aa 100644 --- a/crates/ptth_relay/src/scraper_api.rs +++ b/crates/ptth_relay/src/scraper_api.rs @@ -26,7 +26,6 @@ use crate::{ BlakeHashWrapper, KeyValidity, }, - prefix_match, relay_state::RelayState, }; @@ -160,7 +159,7 @@ async fn api_v1 ( let x = v1_server_list (&state).await; Ok (error_reply (StatusCode::OK, &serde_json::to_string (&x).unwrap ())?) } - else if let Some (rest) = prefix_match ("server/", path_rest) { + else if let Some (rest) = path_rest.strip_prefix ("server/") { // DRY T4H76LB3 if let Some (idx) = rest.find ('/') { @@ -196,10 +195,10 @@ pub async fn handle ( } } - if let Some (rest) = prefix_match ("v1/", path_rest) { + if let Some (rest) = path_rest.strip_prefix ("v1/") { api_v1 (req, state, rest).await } - else if let Some (rest) = prefix_match ("api/", path_rest) { + else if let Some (rest) = path_rest.strip_prefix ("api/") { api_v1 (req, state, rest).await } else { diff --git a/crates/ptth_server/Cargo.toml b/crates/ptth_server/Cargo.toml index 5bcd92e..a656b01 100644 --- a/crates/ptth_server/Cargo.toml +++ b/crates/ptth_server/Cargo.toml @@ -43,7 +43,7 @@ toml = "0.5.7" uom = "0.30.0" always_equal = { path = "../always_equal", version = "1.0.0" } -ptth_core = { path = "../ptth_core", version = "1.4.0" } +ptth_core = { path = "../ptth_core", version = "2.0.0" } [dev-dependencies]