add placeholder for generating scraper keys

main
_ 2021-04-09 20:00:08 -05:00
parent 3408feb619
commit 29eafb3ce7
3 changed files with 18 additions and 2 deletions

2
Cargo.lock generated
View File

@ -1443,7 +1443,7 @@ dependencies = [
[[package]]
name = "ptth_core"
version = "1.2.0"
version = "1.3.0"
dependencies = [
"base64",
"ctrlc",

View File

@ -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" }

View File

@ -469,6 +469,19 @@ async fn handle_endless_source (gib: usize, throttle: Option <usize>)
.body (Body::wrap_stream (ReceiverStream::new (rx)))
}
async fn handle_gen_scraper_key ()
-> Result <Response <Body>, 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 <Body>,
@ -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")?)
}