diff --git a/Cargo.lock b/Cargo.lock index fe3d61d..fd43ed1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,6 +110,48 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "askama" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" +dependencies = [ + "askama_derive", + "itoa", + "percent-encoding", + "serde", + "serde_json", +] + +[[package]] +name = "askama_derive" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" +dependencies = [ + "askama_parser", + "basic-toml", + "memchr", + "proc-macro2", + "quote", + "rustc-hash", + "serde", + "serde_derive", + "syn 2.0.100", +] + +[[package]] +name = "askama_parser" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" +dependencies = [ + "memchr", + "serde", + "serde_derive", + "winnow", +] + [[package]] name = "async-stream" version = "0.3.6" @@ -206,6 +248,15 @@ version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" +[[package]] +name = "basic-toml" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a" +dependencies = [ + "serde", +] + [[package]] name = "binascii" version = "0.1.4" @@ -2156,6 +2207,7 @@ dependencies = [ name = "server" version = "0.1.0" dependencies = [ + "askama", "chrono", "main", "rand 0.8.5", diff --git a/ferri-server/Cargo.toml b/ferri-server/Cargo.toml index a378685..11d5807 100644 --- a/ferri-server/Cargo.toml +++ b/ferri-server/Cargo.toml @@ -18,4 +18,5 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } thiserror = { workspace = true } serde_json = { workspace = true } -serde = { workspace = true } \ No newline at end of file +serde = { workspace = true } +askama = "0.14.0" diff --git a/ferri-server/src/endpoints/admin/mod.rs b/ferri-server/src/endpoints/admin/mod.rs new file mode 100644 index 0000000..51e6ec7 --- /dev/null +++ b/ferri-server/src/endpoints/admin/mod.rs @@ -0,0 +1,20 @@ +use rocket::{get, post, response::content::RawHtml}; +use askama::Template; + +#[derive(Template)] +#[template(path = "index.html")] +struct IndexTemplate { + val: String +} + +#[post("/clicked")] +pub async fn button_clicked() -> RawHtml { + let tmpl = IndexTemplate { val: "clicked".to_string() }; + RawHtml(tmpl.render().unwrap()) +} + +#[get("/")] +pub async fn index() -> RawHtml { + let tmpl = IndexTemplate { val: "test".to_string() }; + RawHtml(tmpl.render().unwrap()) +} diff --git a/ferri-server/src/endpoints/mod.rs b/ferri-server/src/endpoints/mod.rs index 50f374c..74f42d3 100644 --- a/ferri-server/src/endpoints/mod.rs +++ b/ferri-server/src/endpoints/mod.rs @@ -4,6 +4,8 @@ pub mod oauth; pub mod user; pub mod api; +pub mod admin; + pub mod custom; pub mod inbox; pub mod well_known; diff --git a/ferri-server/src/lib.rs b/ferri-server/src/lib.rs index d373a7e..c8cfb9a 100644 --- a/ferri-server/src/lib.rs +++ b/ferri-server/src/lib.rs @@ -1,6 +1,6 @@ use endpoints::{ api::{self, timeline}, - custom, inbox, oauth, user, well_known, + admin, custom, inbox, oauth, user, well_known, }; use tracing_subscriber::fmt; @@ -122,6 +122,13 @@ pub fn launch(cfg: Config) -> Rocket { .attach(Db::init()) .attach(cors::CORS) .mount("/assets", rocket::fs::FileServer::from("./assets")) + .mount( + "/admin", + routes![ + admin::index, + admin::button_clicked + ] + ) .mount( "/", routes![ diff --git a/ferri-server/templates/index.html b/ferri-server/templates/index.html new file mode 100644 index 0000000..f912bcf --- /dev/null +++ b/ferri-server/templates/index.html @@ -0,0 +1,19 @@ + + + + + + + + + Ferri Test + + + + + + + +