From 9ebf7b0f0ad059faa84beb9e12d867b739d6e40d Mon Sep 17 00:00:00 2001 From: catvayor Date: Thu, 16 May 2024 16:52:34 +0200 Subject: [PATCH] Static serving, templating preparation & internal state preparation --- Cargo.lock | 320 ++++++++++++++++++++++++++++++- Cargo.toml | 4 + src/main.rs | 54 +++++- static/tracking/conscrit.html | 76 -------- static/tracking/invalid.html | 16 -- static/tracking/vieux.html | 119 ------------ {static => templates}/admin.html | 0 templates/conscrit.html.hbs | 76 ++++++++ templates/vieux.html.hbs | 119 ++++++++++++ 9 files changed, 568 insertions(+), 216 deletions(-) delete mode 100644 static/tracking/conscrit.html delete mode 100644 static/tracking/invalid.html delete mode 100644 static/tracking/vieux.html rename {static => templates}/admin.html (100%) create mode 100644 templates/conscrit.html.hbs create mode 100644 templates/vieux.html.hbs diff --git a/Cargo.lock b/Cargo.lock index 6d46f40..e2b89f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,12 +101,27 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bytemuck" version = "1.16.0" @@ -142,6 +157,40 @@ dependencies = [ "version_check", ] +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "deranged" version = "0.3.11" @@ -177,13 +226,23 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35b50dba0afdca80b187392b24f2499a88c336d5a8493e4b4ccfb608708be56a" dependencies = [ - "bitflags", + "bitflags 2.5.0", "proc-macro2", "proc-macro2-diagnostics", "quote", "syn", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "either" version = "1.11.0" @@ -235,12 +294,33 @@ dependencies = [ "version_check", ] +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + [[package]] name = "futures" version = "0.3.30" @@ -319,6 +399,16 @@ dependencies = [ "windows", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -361,6 +451,20 @@ dependencies = [ "tracing", ] +[[package]] +name = "handlebars" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faa67bab9ff362228eb3d00bd024a4965d8231bbb7921167f0cfa66c6626b225" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -448,6 +552,26 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "is-terminal" version = "0.4.12" @@ -465,6 +589,26 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -551,6 +695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", + "log", "wasi", "windows-sys 0.48.0", ] @@ -575,6 +720,34 @@ dependencies = [ "version_check", ] +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.5.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys 0.48.0", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -640,7 +813,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.1", "smallvec", "windows-targets 0.52.5", ] @@ -674,6 +847,51 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pest" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -759,13 +977,22 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags", + "bitflags 2.5.0", ] [[package]] @@ -886,6 +1113,19 @@ dependencies = [ "version_check", ] +[[package]] +name = "rocket_dyn_templates" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04bfc006e547e4f72b760ab861f5943b688aed8a82c4977b5500c98f5d17dbfa" +dependencies = [ + "handlebars", + "normpath", + "notify", + "rocket", + "walkdir", +] + [[package]] name = "rocket_http" version = "0.5.0" @@ -925,7 +1165,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -944,6 +1184,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -996,6 +1245,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1086,6 +1346,26 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "thiserror" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -1286,6 +1566,7 @@ name = "traque" version = "0.1.0" dependencies = [ "rocket", + "rocket_dyn_templates", ] [[package]] @@ -1294,6 +1575,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "ubyte" version = "0.10.4" @@ -1303,6 +1590,12 @@ dependencies = [ "serde", ] +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "uncased" version = "0.9.10" @@ -1337,6 +1630,16 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -1368,6 +1671,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 43e1340..bdab94e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,7 @@ edition = "2021" [dependencies] rocket = "0.5.0" + +[dependencies.rocket_dyn_templates] +version = "0.1.0" +features = ["handlebars"] diff --git a/src/main.rs b/src/main.rs index 5411c6b..1067fda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,50 @@ #[macro_use] extern crate rocket; +use rocket::fs::{FileServer, relative}; +use rocket::State; +use std::{ + collections::HashMap, + sync::RwLock, +}; +use rocket_dyn_templates::{Template, context}; + +enum TrackedState { + Conscrit { + invisible: bool, + blurred: bool, + captured: bool, + malette: bool, + invisibility_codes: u32, + blur_codes: u32, + }, + Vieux { + color: u8, + invisible: bool, + } +} + +struct Tracked { + name: String, + pos: (f32, f32), + state: TrackedState, +} + +type Tracking = RwLock>>; + +#[get("/track/conscrit")] +fn conscrit() -> Template{ + Template::render("conscrit", context!{ + name: "un nom", + id: "ID", + gpslog: "no" + }) +} + +#[put("/track/?&")] +fn store_pos(id: String, lat: f32, long: f32, tracking: &State){ + if let Some(tracked) = tracking.read().unwrap().get(&id) { + tracked.write().unwrap().pos = (lat, long); + } +} #[get("/")] fn index() -> &'static str { @@ -7,5 +53,11 @@ fn index() -> &'static str { #[launch] fn rocket() -> _ { - rocket::build().mount("/", routes![index]) + let tracking = HashMap::>::from([ + ]); + rocket::build() + .attach(Template::fairing()) + .manage(RwLock::new(tracking)) + .mount("/", routes![index, store_pos, conscrit]) + .mount("/", FileServer::from(relative!("static"))) } diff --git a/static/tracking/conscrit.html b/static/tracking/conscrit.html deleted file mode 100644 index 2bdb4ef..0000000 --- a/static/tracking/conscrit.html +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - Traque | Client conscrit - - - - - - - - - - - - - -

- -
-
-
- Merci à la Délégation Générale NUMérique de l'ENS, qui héberge ce site. -
- - - - diff --git a/static/tracking/invalid.html b/static/tracking/invalid.html deleted file mode 100644 index a2d24a6..0000000 --- a/static/tracking/invalid.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - Équipe %ID inconnue ! - - -

Équipe %ID inconnue !

- Utilise bien les urls qu'on te donne petit conscrit. - -

-
- Merci à la Délégation Générale NUMérique de l'ENS, qui héberge ce site. - - diff --git a/static/tracking/vieux.html b/static/tracking/vieux.html deleted file mode 100644 index 2598c43..0000000 --- a/static/tracking/vieux.html +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - Traque | Client vieilleux - - - - - - - - - - - - - -

- -
-
- - - - -
- - - - - - - - - - - - - - - - - - - - - -

- -
-
- Merci à la Délégation Générale NUMérique de l'ENS, qui héberge ce site. -
- - - - diff --git a/static/admin.html b/templates/admin.html similarity index 100% rename from static/admin.html rename to templates/admin.html diff --git a/templates/conscrit.html.hbs b/templates/conscrit.html.hbs new file mode 100644 index 0000000..167add7 --- /dev/null +++ b/templates/conscrit.html.hbs @@ -0,0 +1,76 @@ + + + + + + Traque -- {{name}} | Client conscrit + + + + + + + + + + + + + +

+ +
+
+
+ Merci à la Délégation Générale NUMérique de l'ENS, qui héberge ce site. +
+ + + + diff --git a/templates/vieux.html.hbs b/templates/vieux.html.hbs new file mode 100644 index 0000000..87f2bf1 --- /dev/null +++ b/templates/vieux.html.hbs @@ -0,0 +1,119 @@ + + + + + + Traque -- {{name}} | Client vieilleux + + + + + + + + + + + + + +

+ +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +

+ +
+
+ Merci à la Délégation Générale NUMérique de l'ENS, qui héberge ce site. +
+ + + +