diff --git a/Cargo.lock b/Cargo.lock index 7c2c642..94ed307 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,50 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", + "humansize", + "num-traits", + "percent-encoding", +] + +[[package]] +name = "askama_derive" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" +dependencies = [ + "nom", +] + [[package]] name = "async-channel" version = "2.5.0" @@ -178,6 +222,15 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd56f3e93b90fb323c852f11facb95c8edc6a535db42bcdbdfac4d9a4db132e1" +[[package]] +name = "basic-toml" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "2.10.0" @@ -188,6 +241,7 @@ checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" name = "blindforge" version = "0.1.0" dependencies = [ + "askama", "base64-turbo", "form_urlencoded", "rand", @@ -195,10 +249,10 @@ dependencies = [ "serde", "sha2", "trillium", + "trillium-askama", "trillium-caching-headers", "trillium-router", "trillium-smol", - "trillium-static-compiled", ] [[package]] @@ -539,6 +593,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + [[package]] name = "hyper" version = "1.8.1" @@ -730,6 +793,12 @@ version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + [[package]] name = "linux-raw-sys" version = "0.11.0" @@ -792,6 +861,12 @@ dependencies = [ "unicase", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "mio" version = "1.1.1" @@ -803,6 +878,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.50.3" @@ -812,6 +897,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -1379,6 +1473,17 @@ dependencies = [ "trillium-http", ] +[[package]] +name = "trillium-askama" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0a4eeb5246ff1baea3c81782ee46bc4601463d75d6a8502bcf44890456b4c1e" +dependencies = [ + "askama", + "mime_guess", + "trillium", +] + [[package]] name = "trillium-caching-headers" version = "0.2.3" @@ -1471,30 +1576,6 @@ dependencies = [ "trillium-server-common", ] -[[package]] -name = "trillium-static-compiled" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6b6af3eae0964ee41a93fc1758b9facdf53f2bafb2678db45e82ed89b7f3ca0" -dependencies = [ - "httpdate", - "log", - "mime", - "mime_guess", - "trillium", - "trillium-static-compiled-macros", -] - -[[package]] -name = "trillium-static-compiled-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74bb0f4cdf019c27ab8ac30d549e962765532aa203f443761b655444d3137f62" -dependencies = [ - "proc-macro2", - "quote", -] - [[package]] name = "try-lock" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index db9208b..85a8074 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] +askama = "0.12.1" base64-turbo = "0.1.3" #flate2 = "1.1.8" form_urlencoded = "1.2.2" @@ -13,7 +14,8 @@ serde = { version = "1.0.228", features = ["derive"] } sha2 = "0.10.9" #tar = "0.4.44" trillium = "0.2.20" +trillium-askama = "0.3.2" trillium-caching-headers = "0.2.3" trillium-router = "0.4.1" trillium-smol = "0.4.2" -trillium-static-compiled = "0.5.2" +#trillium-static-compiled = "0.5.2" diff --git a/src/main.rs b/src/main.rs index 474f403..53dd655 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,12 @@ mod api_client; mod config; mod repo; mod server; +mod templates; fn main() { let config = config::Config::default(); - trillium_smol::config().with_host(&config.listen_host).with_port(config.listen_port).run(server::make_router()); + trillium_smol::config() + .with_host(&config.listen_host) + .with_port(config.listen_port) + .run(server::make_router()); } diff --git a/src/server.rs b/src/server.rs index c10506e..df61e45 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; - +use askama::Template; use trillium::{Conn, Handler}; use trillium_router::{Router, RouterConnExt}; @@ -8,23 +7,33 @@ pub async fn hello_world(conn: Conn) -> Conn { } pub fn make_router() -> impl Handler { - (trillium_caching_headers::CachingHeaders::new(), - trillium_static_compiled::static_compiled!("./static").with_index_file("index.html"), + ( + trillium_caching_headers::CachingHeaders::new(), + //trillium_static_compiled::static_compiled!("./static").with_index_file("index.html"), Router::new() - .post("/fetch", |mut conn: Conn| async move { - if let Ok(request_body) = conn.request_body().await.with_max_len(8192).await { - let mut repo_url = None; - for (key, val) in form_urlencoded::parse(request_body.as_bytes()) { - if key == "repo-url" { - repo_url = Some(val); + .get("/", |conn: Conn| async move { + conn.ok(crate::templates::Home {}.render().unwrap()) + }) + .post("/fetch", |mut conn: Conn| async move { + if let Ok(request_body) = conn.request_body().await.with_max_len(8192).await { + let mut repo_url = None; + for (key, val) in form_urlencoded::parse(request_body.as_bytes()) { + if key == "repo-url" { + repo_url = Some(val); + } } + let Some(repo_url) = repo_url else { + return conn.ok("Missing arg"); + }; } - let Some(repo_url) = repo_url else { - return conn.ok("Missing arg"); - }; - } - //let planet = conn.param("planet").unwrap(); - let response_body = format!("hello"); - conn.ok(response_body) - })) + //let planet = conn.param("planet").unwrap(); + conn.ok(crate::templates::Home {}.render().unwrap()) + }) + .get("/r/:hash", |conn: Conn| async move { + conn.ok(crate::templates::Home {}.render().unwrap()) + }) + .get("/e/:secret", |conn: Conn| async move { + conn.ok(crate::templates::Home {}.render().unwrap()) + }), + ) } diff --git a/src/templates.rs b/src/templates.rs new file mode 100644 index 0000000..f86e350 --- /dev/null +++ b/src/templates.rs @@ -0,0 +1,5 @@ +use trillium_askama::Template; + +#[derive(Template)] +#[template(path = "home.html")] +pub struct Home {} diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..1e64cab --- /dev/null +++ b/templates/home.html @@ -0,0 +1,14 @@ + + + + + Blindforge + + +
+ +
+ +
+ +