♻️ Extract ptth_server crate. Docker still broken

main
_ 2020-11-27 00:50:22 +00:00
parent 4c9595ee2e
commit bbb88c01e8
12 changed files with 61 additions and 74 deletions

View File

@ -6,40 +6,22 @@ authors = ["Trish"]
edition = "2018"
license = "AGPL-3.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
aho-corasick = "0.7.14"
[dev-dependencies]
base64 = "0.12.3"
blake3 = "0.3.7"
chrono = "0.4.19"
futures = "0.3.7"
handlebars = "3.5.1"
http = "0.2.1"
hyper = "0.13.8"
itertools = "0.9.0"
lazy_static = "1.4.0"
maplit = "1.0.2"
percent-encoding = "2.1.0"
pulldown-cmark = "0.8.0"
rand = "0.7.3"
regex = "1.4.1"
reqwest = { version = "0.10.8", features = ["stream"] }
rmp-serde = "0.14.4"
serde = {version = "1.0.117", features = ["derive"]}
structopt = "0.3.20"
tokio = { version = "0.2.22", features = ["full"] }
tracing = "0.1.21"
tracing-futures = "0.2.4"
tracing-subscriber = "0.2.15"
toml = "0.5.7"
ulid = "0.4.1"
url = "2.2.0"
always_equal = { path = "crates/always_equal" }
ptth_core = { path = "crates/ptth_core" }
ptth_relay = { path = "crates/ptth_relay" }
ptth_server = { path = "crates/ptth_server" }
[workspace]

View File

@ -0,0 +1,37 @@
[package]
name = "ptth_server"
version = "0.1.0"
authors = ["Trish"]
edition = "2018"
license = "AGPL-3.0"
[dependencies]
aho-corasick = "0.7.14"
base64 = "0.12.3"
blake3 = "0.3.7"
futures = "0.3.7"
handlebars = "3.5.1"
hyper = "0.13.8"
lazy_static = "1.4.0"
percent-encoding = "2.1.0"
pulldown-cmark = "0.8.0"
regex = "1.4.1"
reqwest = { version = "0.10.8", features = ["stream"] }
rmp-serde = "0.14.4"
serde = {version = "1.0.117", features = ["derive"]}
structopt = "0.3.20"
tokio = { version = "0.2.22", features = ["full"] }
tracing = "0.1.21"
tracing-futures = "0.2.4"
tracing-subscriber = "0.2.15"
toml = "0.5.7"
always_equal = { path = "../always_equal" }
ptth_core = { path = "../ptth_core" }
[dev-dependencies]
maplit = "1.0.2"
rand = "0.6.5"

View File

@ -22,7 +22,10 @@ use ptth_core::{
http_serde::RequestParts,
prelude::*,
};
use ptth::server::file_server;
use ptth_server::{
file_server,
load_toml,
};
#[derive (Default)]
pub struct Config {
@ -103,7 +106,7 @@ async fn main () -> Result <(), Box <dyn Error>> {
tracing_subscriber::fmt::init ();
let path = PathBuf::from ("./config/ptth_server.toml");
let config_file: ConfigFile = ptth::server::load_toml::load (&path);
let config_file: ConfigFile = load_toml::load (&path);
info! ("file_server_root: {:?}", config_file.file_server_root);
let addr = SocketAddr::from(([0, 0, 0, 0], 4000));

View File

@ -5,7 +5,12 @@ use std::{
use structopt::StructOpt;
use tokio::runtime;
use tracing::debug;
use ptth_server::{
ConfigFile,
load_toml,
run_server,
};
#[derive (Debug, StructOpt)]
struct Opt {
@ -27,29 +32,17 @@ fn main () -> Result <(), Box <dyn Error>> {
tracing_subscriber::fmt::init ();
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
let config_file: ptth::server::ConfigFile = ptth::server::load_toml::load (&path);
let config_file: ConfigFile = load_toml::load (&path);
if opt.print_tripcode {
println! (r#""{}" = "{}""#, config_file.name, config_file.tripcode ());
return Ok (());
}
let mut rt = if false {
debug! ("Trying to use less RAM");
runtime::Builder::new ()
.threaded_scheduler ()
.enable_all ()
.core_threads (1)
.thread_stack_size (1024 * 1024)
.build ()?
}
else {
runtime::Runtime::new ()?
};
let mut rt = runtime::Runtime::new ()?;
rt.block_on (async move {
ptth::server::run_server (
run_server (
config_file,
ptth_core::graceful_shutdown::init (),
Some (path),

View File

@ -805,43 +805,21 @@ mod tests {
let mut rt = Runtime::new ().unwrap ();
rt.block_on (async {
let handlebars = load_templates (&PathBuf::new ()).unwrap ();
let server_info = ServerInfo {
server_name: "PTTH File Server".to_string (),
};
let file_server_root = PathBuf::from ("./");
let headers = Default::default ();
for (uri_path, expected_status) in vec! [
("/", StatusCode::Ok),
("/files", StatusCode::TemporaryRedirect),
("/files/src", StatusCode::TemporaryRedirect),
("/files/src/", StatusCode::Ok),
].into_iter () {
let resp = serve_all (
&handlebars,
&server_info,
&file_server_root,
Method::Get,
uri_path,
&headers,
None
).await;
assert_eq! (resp.parts.status_code, expected_status);
}
{
use InternalResponse::*;
let bad_passwords_path = "/files/src/bad_passwords.txt";
for (uri_path, expected) in vec! [
("/", Root),
("/files", Redirect ("files/".to_string ())),
("/files/?", InvalidQuery),
("/files/src", Redirect ("src/".to_string ())),
("/files/src/?", InvalidQuery),
("/files/src/server/bad_passwords.txt", ServeFile (ServeFileParams {
(bad_passwords_path, ServeFile (ServeFileParams {
send_body: true,
range: 0..1_048_576,
range_requested: false,
@ -869,7 +847,7 @@ mod tests {
let resp = internal_serve_all (
&file_server_root,
Method::Get,
"/files/src/server/bad_passwords.txt",
bad_passwords_path,
&hashmap! {
"range".into () => b"bytes=0-2000000".to_vec (),
},
@ -881,7 +859,7 @@ mod tests {
let resp = internal_serve_all (
&file_server_root,
Method::Head,
"/files/src/server/bad_passwords.txt",
bad_passwords_path,
&headers,
None
).await;

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -1,4 +1,2 @@
pub mod server;
#[cfg (test)]
mod tests;

View File

@ -13,10 +13,6 @@ use tokio::{
time::delay_for,
};
use super::{
server,
};
#[test]
fn end_to_end () {
use maplit::*;
@ -57,7 +53,7 @@ fn end_to_end () {
let relay_url = "http://127.0.0.1:4000";
let config_file = server::ConfigFile {
let config_file = ptth_server::ConfigFile {
name: server_name.into (),
api_key: api_key.into (),
relay_url: "http://127.0.0.1:4000/7ZSFUKGV".into (),
@ -67,7 +63,7 @@ fn end_to_end () {
let (stop_server_tx, stop_server_rx) = oneshot::channel ();
let task_server = {
spawn (async move {
server::run_server (config_file, stop_server_rx, None, None).await.unwrap ();
ptth_server::run_server (config_file, stop_server_rx, None, None).await.unwrap ();
})
};