From 3869dad772a9e3b2cad7a44801dadfc34523109a Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:32:24 +0200 Subject: [PATCH] add crate for future frontend --- Cargo.lock | 108 ++++++++++++++++++++++++++- Cargo.toml | 1 + crates/frontend/Cargo.toml | 11 +++ crates/frontend/src/lib.rs | 31 ++++++++ crates/frontend/templates/index.html | 15 ++++ src/app.rs | 8 +- 6 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 crates/frontend/Cargo.toml create mode 100644 crates/frontend/src/lib.rs create mode 100644 crates/frontend/templates/index.html diff --git a/Cargo.lock b/Cargo.lock index 64c01b2..8df8b4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -342,6 +342,61 @@ dependencies = [ "password-hash", ] +[[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", + "serde", +] + +[[package]] +name = "askama_actix" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4b0dd17cfe203b00ba3853a89fba459ecf24c759b738b244133330607c78e55" +dependencies = [ + "actix-web", + "askama", +] + +[[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-trait" version = "0.1.81" @@ -395,6 +450,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "basic-toml" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "823388e228f614e9558c6804262db37960ec8821856535f5c3f59913140558f8" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -1068,6 +1132,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 = "humantime" version = "2.1.0" @@ -1265,6 +1338,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1526,9 +1609,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.35.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86e446ed58cef1bbfe847bc2fda0e2e4ea9f0e57b90c507d4781292590d72a4e" +checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc" dependencies = [ "memchr", "serde", @@ -1726,6 +1809,7 @@ dependencies = [ "rustical_auth", "rustical_caldav", "rustical_carddav", + "rustical_frontend", "rustical_store", "serde", "sqlx", @@ -1811,6 +1895,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "rustical_frontend" +version = "0.1.0" +dependencies = [ + "actix-web", + "askama", + "askama_actix", + "rustical_store", + "tokio", +] + [[package]] name = "rustical_store" version = "0.1.0" @@ -2491,6 +2586,15 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" diff --git a/Cargo.toml b/Cargo.toml index 15facec..f539b8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ rustical_store = { path = "./crates/store/" } rustical_auth = { path = "./crates/auth/" } rustical_caldav = { path = "./crates/caldav/" } rustical_carddav = { path = "./crates/carddav/" } +rustical_frontend = { path = "./crates/frontend/" } serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.39", features = [ "net", diff --git a/crates/frontend/Cargo.toml b/crates/frontend/Cargo.toml new file mode 100644 index 0000000..9c6c2c0 --- /dev/null +++ b/crates/frontend/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rustical_frontend" +version = "0.1.0" +edition = "2021" + +[dependencies] +actix-web = "4.8" +askama = { version = "0.12", features = ["serde", "with-actix-web"] } +askama_actix = "0.14" +tokio = { version = "1.39", features = ["sync", "full"] } +rustical_store = { path = "../store/" } diff --git a/crates/frontend/src/lib.rs b/crates/frontend/src/lib.rs new file mode 100644 index 0000000..76eb90c --- /dev/null +++ b/crates/frontend/src/lib.rs @@ -0,0 +1,31 @@ +use actix_web::{ + get, + http::Method, + web::{self, Data}, +}; +use askama::Template; +use rustical_store::CalendarStore; +use std::sync::Arc; +use tokio::sync::RwLock; + +#[derive(Template)] +#[template(path = "index.html")] +struct IndexTemplate {} + +#[get("")] +async fn route_index() -> IndexTemplate { + IndexTemplate {} +} + +async fn route_user(store: Data>) -> IndexTemplate { + IndexTemplate {} +} + +pub fn configure_frontend( + cfg: &mut web::ServiceConfig, + store: Arc>, +) { + cfg.app_data(Data::from(store.clone())) + .service(route_index) + .service(web::resource("/user/{user}").route(web::method(Method::GET).to(route_user::))); +} diff --git a/crates/frontend/templates/index.html b/crates/frontend/templates/index.html new file mode 100644 index 0000000..ab9d63c --- /dev/null +++ b/crates/frontend/templates/index.html @@ -0,0 +1,15 @@ + + + + + + + Test + + + + +

Test

+ + + diff --git a/src/app.rs b/src/app.rs index 4c02e77..4ac7d2c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,11 +1,11 @@ -use std::sync::Arc; - use actix_web::body::MessageBody; use actix_web::dev::{ServiceFactory, ServiceRequest, ServiceResponse}; use actix_web::middleware::{Logger, NormalizePath}; use actix_web::{web, App}; use rustical_auth::CheckAuthentication; +use rustical_frontend::configure_frontend; use rustical_store::CalendarStore; +use std::sync::Arc; use tokio::sync::RwLock; pub fn make_app( @@ -40,4 +40,8 @@ pub fn make_app( // rustical_carddav::configure_well_known(cfg, "/carddav".to_string()) // }), ) + .service( + web::scope("/frontend").configure(|cfg| configure_frontend(cfg, cal_store.clone())), + ) + .service(web::redirect("/", "/frontend").permanent()) }