➕ add subcommand to generate a random ULID
parent
931ad6d81b
commit
c852efb343
|
@ -1206,6 +1206,8 @@ dependencies = [
|
||||||
"ptth_file_server",
|
"ptth_file_server",
|
||||||
"ptth_server",
|
"ptth_server",
|
||||||
"quic_demo",
|
"quic_demo",
|
||||||
|
"reqwest",
|
||||||
|
"rusty_ulid",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
|
|
@ -6,11 +6,23 @@ edition = "2018"
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
# Cookie 01FYZ3SDP2XABT7W19ACQVYKXT
|
||||||
|
# Dependencies should be in sync because ptth_multi_call_server intentionally
|
||||||
|
# tries to re-use as much code as possible between all of its subcommands,
|
||||||
|
# including ptth_server and ptth_file_server.
|
||||||
|
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
ctrlc = "3.2.1"
|
ctrlc = "3.2.1"
|
||||||
ptth_file_server = { path = "../ptth_file_server_bin" }
|
ptth_file_server = { path = "../ptth_file_server_bin" }
|
||||||
ptth_server = { path = "../ptth_server" }
|
ptth_server = { path = "../ptth_server" }
|
||||||
quic_demo = { path = "../../prototypes/quic_demo" }
|
quic_demo = { path = "../../prototypes/quic_demo" }
|
||||||
|
rusty_ulid = "0.10.1"
|
||||||
tokio = { version = "1.8.1", features = ["full"] }
|
tokio = { version = "1.8.1", features = ["full"] }
|
||||||
tracing-subscriber = "0.2.16"
|
tracing-subscriber = "0.2.16"
|
||||||
tracing = "0.1.25"
|
tracing = "0.1.25"
|
||||||
|
|
||||||
|
[dependencies.reqwest]
|
||||||
|
version = "0.11.1"
|
||||||
|
default-features = false
|
||||||
|
features = ["stream", "rustls-tls", "hyper-rustls"]
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
use std::{
|
||||||
|
ffi::OsString,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
|
use anyhow::{
|
||||||
|
anyhow,
|
||||||
|
bail,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
|
||||||
|
let mut url = None;
|
||||||
|
let mut sha512 = None;
|
||||||
|
|
||||||
|
let mut args = args [1..].into_iter ();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let arg = match args.next () {
|
||||||
|
None => break,
|
||||||
|
Some (x) => x,
|
||||||
|
};
|
||||||
|
|
||||||
|
match arg.to_str ().ok_or_else (|| anyhow! ("All arguments must be valid UTF-8"))?
|
||||||
|
{
|
||||||
|
"--help" => println! ("For now, just look at the source code"),
|
||||||
|
"--sha512" => {
|
||||||
|
sha512 = args.next ();
|
||||||
|
}
|
||||||
|
arg => {
|
||||||
|
url = Some (arg);
|
||||||
|
break;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = match url {
|
||||||
|
None => bail! ("URL argument is required"),
|
||||||
|
Some (x) => x,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cookie 01FYZ3W64SM6KYNP48J6EWSCEF
|
||||||
|
// Try to keep the Clients similar here
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder ()
|
||||||
|
.connect_timeout (Duration::from_secs (30))
|
||||||
|
.build ()?;
|
||||||
|
|
||||||
|
Ok (())
|
||||||
|
}
|
|
@ -5,24 +5,32 @@ use std::{
|
||||||
|
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
|
mod download;
|
||||||
|
mod ulid;
|
||||||
|
|
||||||
#[derive (Clone, Copy, Debug, PartialEq)]
|
#[derive (Clone, Copy, Debug, PartialEq)]
|
||||||
enum Subcommand {
|
enum Subcommand {
|
||||||
|
Download,
|
||||||
PtthServer,
|
PtthServer,
|
||||||
PtthFileServer,
|
PtthFileServer,
|
||||||
PtthQuicEndServer,
|
PtthQuicEndServer,
|
||||||
|
Ulid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main () -> anyhow::Result <()> {
|
async fn main () -> anyhow::Result <()> {
|
||||||
|
use Subcommand::*;
|
||||||
|
|
||||||
tracing_subscriber::fmt::init ();
|
tracing_subscriber::fmt::init ();
|
||||||
|
|
||||||
let args = Vec::from_iter (std::env::args_os ());
|
let args = Vec::from_iter (std::env::args_os ());
|
||||||
|
|
||||||
let (subcommand, args) = parse_args (&args)?;
|
let (subcommand, args) = parse_args (&args)?;
|
||||||
match subcommand {
|
match subcommand {
|
||||||
Subcommand::PtthServer => ptth_server::executable::main (&args).await,
|
Download => download::main (&args).await,
|
||||||
Subcommand::PtthFileServer => ptth_file_server::main (&args).await,
|
PtthServer => ptth_server::executable::main (&args).await,
|
||||||
Subcommand::PtthQuicEndServer => {
|
PtthFileServer => ptth_file_server::main (&args).await,
|
||||||
|
PtthQuicEndServer => {
|
||||||
let (shutdown_tx, shutdown_rx) = watch::channel (false);
|
let (shutdown_tx, shutdown_rx) = watch::channel (false);
|
||||||
|
|
||||||
ctrlc::set_handler (move || {
|
ctrlc::set_handler (move || {
|
||||||
|
@ -33,6 +41,7 @@ async fn main () -> anyhow::Result <()> {
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
Ulid => ulid::main (&args).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,9 +50,11 @@ fn parse_subcommand (arg: &str) -> Option <Subcommand>
|
||||||
use Subcommand::*;
|
use Subcommand::*;
|
||||||
|
|
||||||
let map = vec! [
|
let map = vec! [
|
||||||
|
("download", Download),
|
||||||
("ptth_server", PtthServer),
|
("ptth_server", PtthServer),
|
||||||
("ptth_file_server", PtthFileServer),
|
("ptth_file_server", PtthFileServer),
|
||||||
("ptth_quic_end_server", PtthQuicEndServer),
|
("ptth_quic_end_server", PtthQuicEndServer),
|
||||||
|
("ulid", Ulid),
|
||||||
];
|
];
|
||||||
|
|
||||||
let arg = arg.strip_suffix (".exe").unwrap_or (arg);
|
let arg = arg.strip_suffix (".exe").unwrap_or (arg);
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
use std::{
|
||||||
|
ffi::OsString,
|
||||||
|
};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
pub async fn main (args: &[OsString]) -> Result <()>
|
||||||
|
{
|
||||||
|
println! ("{}", rusty_ulid::generate_ulid_string ());
|
||||||
|
|
||||||
|
Ok (())
|
||||||
|
}
|
|
@ -13,6 +13,11 @@ default-run = "ptth_server"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
# Cookie 01FYZ3SDP2XABT7W19ACQVYKXT
|
||||||
|
# Dependencies should be in sync because ptth_multi_call_server intentionally
|
||||||
|
# tries to re-use as much code as possible between all of its subcommands,
|
||||||
|
# including ptth_server and ptth_file_server.
|
||||||
|
|
||||||
aho-corasick = "0.7.15"
|
aho-corasick = "0.7.15"
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
arc-swap = "1.2.0"
|
arc-swap = "1.2.0"
|
||||||
|
|
|
@ -361,6 +361,9 @@ impl State {
|
||||||
let mut headers = reqwest::header::HeaderMap::new ();
|
let mut headers = reqwest::header::HeaderMap::new ();
|
||||||
headers.insert ("X-ApiKey", config_file.api_key.try_into ().map_err (ServerError::ApiKeyInvalid)?);
|
headers.insert ("X-ApiKey", config_file.api_key.try_into ().map_err (ServerError::ApiKeyInvalid)?);
|
||||||
|
|
||||||
|
// Cookie 01FYZ3W64SM6KYNP48J6EWSCEF
|
||||||
|
// Try to keep the Clients similar here
|
||||||
|
|
||||||
let client = Client::builder ()
|
let client = Client::builder ()
|
||||||
.default_headers (headers)
|
.default_headers (headers)
|
||||||
.connect_timeout (Duration::from_secs (30))
|
.connect_timeout (Duration::from_secs (30))
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
1.55.0
|
|
Loading…
Reference in New Issue