From 29eafb3ce708aa05d2063da84988692160b8afc2 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Fri, 9 Apr 2021 20:00:08 -0500 Subject: [PATCH] add placeholder for generating scraper keys --- Cargo.lock | 2 +- crates/ptth_relay/Cargo.toml | 2 +- crates/ptth_relay/src/lib.rs | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93aee24..162ff02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1443,7 +1443,7 @@ dependencies = [ [[package]] name = "ptth_core" -version = "1.2.0" +version = "1.3.0" dependencies = [ "base64", "ctrlc", diff --git a/crates/ptth_relay/Cargo.toml b/crates/ptth_relay/Cargo.toml index 5093db5..c3f0364 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.2.0" } +ptth_core = { path = "../ptth_core", version = "1.3.0" } diff --git a/crates/ptth_relay/src/lib.rs b/crates/ptth_relay/src/lib.rs index 15365cb..2e5b49a 100644 --- a/crates/ptth_relay/src/lib.rs +++ b/crates/ptth_relay/src/lib.rs @@ -469,6 +469,19 @@ async fn handle_endless_source (gib: usize, throttle: Option ) .body (Body::wrap_stream (ReceiverStream::new (rx))) } +async fn handle_gen_scraper_key () +-> Result , http::Error> +{ + let key = ptth_core::gen_key (); + + let body = format! ("Random key: {}\n", key); + + Response::builder () + .status (StatusCode::OK) + .header ("content-type", "text/plain") + .body (Body::from (body)) +} + #[instrument (level = "trace", skip (req, state, handlebars))] async fn handle_all ( req: Request , @@ -545,6 +558,9 @@ async fn handle_all ( else if rest == "endless_sink" { Ok (error_reply (StatusCode::METHOD_NOT_ALLOWED, "Don't GET this URL, POST to it.")?) } + else if rest == "gen_key" { + Ok (handle_gen_scraper_key ().await?) + } else { Ok (error_reply (StatusCode::NOT_FOUND, "Can't route URL")?) }