From 6f1849ac7e73314cba6cbf61c4f8151b0d82347f Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Wed, 20 Mar 2024 23:40:10 +0100 Subject: [PATCH] Update deps + better html escaping stratergy --- Cargo.lock | 176 +++++++++++++++----------------- Cargo.toml | 22 ++-- README.md | 1 + src/filters.rs | 4 +- src/models/todo_item.rs | 1 - src/render_html.rs | 11 ++ src/routes/todos/create_todo.rs | 14 ++- src/serde_converters.rs | 11 +- 8 files changed, 117 insertions(+), 123 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90a6342..264a18e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom", "once_cell", @@ -41,11 +41,12 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.7" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -127,7 +128,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -138,7 +139,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -268,7 +269,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -335,7 +336,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.48", + "syn 2.0.52", "which", ] @@ -398,9 +399,9 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytecheck" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6372023ac861f6e6dc89c8344a8f398fb42aaba2b5dbc649ca0c0e9dbcb627" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" dependencies = [ "bytecheck_derive", "ptr_meta", @@ -409,9 +410,9 @@ dependencies = [ [[package]] name = "bytecheck_derive" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7ec4c6f261935ad534c0c22dbef2201b45918860eb1c574b972bd213a76af61" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" dependencies = [ "proc-macro2", "quote", @@ -444,12 +445,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cexpr" @@ -468,9 +466,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.33" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -621,7 +619,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" dependencies = [ "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -821,7 +819,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -932,7 +930,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.2.2", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -951,7 +949,7 @@ dependencies = [ "futures-sink", "futures-util", "http 1.0.0", - "indexmap 2.2.2", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -964,7 +962,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash 0.7.7", + "ahash 0.7.8", ] [[package]] @@ -973,7 +971,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.7", + "ahash 0.8.11", "bumpalo", ] @@ -983,7 +981,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.7", + "ahash 0.8.11", "allocator-api2", ] @@ -1017,15 +1015,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "html-escape" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" -dependencies = [ - "utf8-width", -] - [[package]] name = "http" version = "0.2.12" @@ -1229,9 +1218,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.2" +version = "2.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -1378,7 +1367,7 @@ dependencies = [ "bitflags 2.4.2", "cc", "fallible-iterator 0.3.0", - "indexmap 2.2.2", + "indexmap 2.2.5", "log", "memchr", "phf 0.11.2", @@ -1433,17 +1422,18 @@ dependencies = [ [[package]] name = "lightningcss" -version = "1.0.0-alpha.52" +version = "1.0.0-alpha.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771a62dedf5ec563bbfea9760f6c6a6bc546e67355eba0cd7d00c0dc34b11d90" +checksum = "3bd5bed3814fb631bfc1e24c2be6f7e86a9837c660909acab79a38374dcb8798" dependencies = [ - "ahash 0.7.7", + "ahash 0.8.11", "bitflags 2.4.2", "const-str", "cssparser", "cssparser-color", "dashmap", "data-encoding", + "getrandom", "itertools 0.10.5", "lazy_static", "parcel_selectors", @@ -1474,9 +1464,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "mach2" @@ -1570,9 +1560,9 @@ dependencies = [ [[package]] name = "minijinja" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe0ff215195a22884d867b547c70a0c4815cbbcc70991f281dca604b20d10ce" +checksum = "fe5b00f90b3542f74bb9aaaccd2627920c16367787de103883461365580e5481" dependencies = [ "memo-map", "self_cell", @@ -1588,18 +1578,18 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "wasi", @@ -1642,9 +1632,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -1856,7 +1846,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1895,7 +1885,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1935,14 +1925,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -1967,7 +1957,7 @@ dependencies = [ "itertools 0.10.5", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2062,9 +2052,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" +checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd" dependencies = [ "either", "rayon-core", @@ -2120,9 +2110,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rend" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2571463863a6bd50c32f94402933f03457a3fbaf697a707c5be741e459f08fd" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" dependencies = [ "bytecheck", ] @@ -2144,9 +2134,9 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.43" +version = "0.7.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527a97cdfef66f65998b5f3b637c26f5a5ec09cc52a3f9932313ac645f4190f5" +checksum = "5cba464629b3394fc4dbc6f940ff8f5b4ff5c7aef40f29166fd4ad12acbc99c0" dependencies = [ "bitvec", "bytecheck", @@ -2162,9 +2152,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.7.43" +version = "0.7.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5c462a1328c8e67e4d6dbad1eb0355dd43e8ab432c6e227a43657f16ade5033" +checksum = "a7dddfff8de25e6f62b9d64e6e432bf1c6736c57d20323e15ee10435fbda7c65" dependencies = [ "proc-macro2", "quote", @@ -2202,7 +2192,6 @@ dependencies = [ "axum-htmx", "chrono", "dotenv", - "html-escape", "libsql", "minify-html", "minijinja", @@ -2216,6 +2205,7 @@ dependencies = [ "tower-sessions", "tower-sessions-libsql-store", "tower_governor", + "v_htmlescape", ] [[package]] @@ -2294,9 +2284,9 @@ checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "schannel" @@ -2360,29 +2350,29 @@ checksum = "58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba" [[package]] name = "serde" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -2464,12 +2454,12 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2497,9 +2487,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", @@ -2535,7 +2525,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2621,7 +2611,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2801,9 +2791,9 @@ checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" [[package]] name = "tower-livereload" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e74a1dba7fccc96d1ea1fe8abe0ad8e9b84fb1d55ddefc7bc9da3b0681dc73" +checksum = "61d6cbbab4b2d3cafd21fb211cc4b06525a0df919c3e8ca3d36485b1c1bd4cd4" dependencies = [ "bytes", "http 1.0.0", @@ -2886,9 +2876,9 @@ dependencies = [ [[package]] name = "tower_governor" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d31d2cd0776b0e10664d3db2e362b9a8b38a18cb09ba97d3f2f775c54f2c51b" +checksum = "3790eac6ad3fb8d9d96c2b040ae06e2517aa24b067545d1078b96ae72f7bb9a7" dependencies = [ "axum 0.7.4", "forwarded-header-value", @@ -2920,7 +2910,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2974,12 +2964,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "utf8-width" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" - [[package]] name = "uuid" version = "1.7.0" @@ -3044,7 +3028,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wasm-bindgen-shared", ] @@ -3066,7 +3050,7 @@ checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3295,5 +3279,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] diff --git a/Cargo.toml b/Cargo.toml index 09216eb..7bb76ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,21 +7,21 @@ edition = "2021" [dependencies] axum = { version = "0.7.4", features = ["form", "macros"] } -tokio = { version = "1.36.0", features = ["full"] } +tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] } tower-http = { version = "0.5", features = ["fs","set-header"] } -serde = { version = "1.0.196", features = ["derive"] } +serde = { version = "1.0.197", features = ["derive"] } rand = "0.8" -chrono = "0.4.33" -html-escape = "0.2.13" +chrono = "0.4.35" dotenv = "0.15.0" -tower = { version = "0.4.13" } -tower_governor = { version = "0.3.1" } -minijinja = { version = "1.0.12", features = ["loader", "v_htmlescape", "multi_template"] } +tower = "0.4.13" +tower_governor = "0.3.2" +tower-sessions = "0.10.2" +tower-sessions-libsql-store = "0.1.0" +tower-livereload = "0.9.2" +minijinja = { version = "1.0.14", features = ["loader", "v_htmlescape", "multi_template"] } axum-htmx = "0.5.0" -tower-livereload = "0.9.1" argon2 = "0.5.3" -tower-sessions = "0.10.1" -tower-sessions-libsql-store = "0.1.0" -time = "0.3.33" +time = "0.3.34" minify-html = "0.15.0" libsql = "0.3.1" +v_htmlescape = "0.15.8" diff --git a/README.md b/README.md index 3136a0b..7f9b7b3 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ npm run tailwind - [x] Improve code for render_html.rs - [x] Setup build via GH actions - [x] Migrate from SQLX/PostgreSQL to Libsql/Turso (sqlx doesn't support turso yet... such a shame) +- [ ] Use minijinja autoreload https://docs.rs/minijinja-autoreload/latest/minijinja_autoreload/ - [ ] Rename to RATH stack, Rust Axum Turso Hhtmx ## Handy commands diff --git a/src/filters.rs b/src/filters.rs index 682b41a..102ca93 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -1,8 +1,8 @@ -use chrono::NaiveDateTime; +use chrono::DateTime; pub fn date_string(timestamp: String) -> String { let timestamp = timestamp.parse::().expect("timestamp to be a avalid integer"); - let date_formatted: String = NaiveDateTime::from_timestamp_opt(timestamp, 0) + let date_formatted: String = DateTime::from_timestamp(timestamp, 0) .unwrap() .format("%d-%m-%Y") .to_string(); diff --git a/src/models/todo_item.rs b/src/models/todo_item.rs index 98a8380..8078ffb 100644 --- a/src/models/todo_item.rs +++ b/src/models/todo_item.rs @@ -5,7 +5,6 @@ use serde::{Deserialize, Serialize}; pub struct TodoItemRequest { #[serde(default)] pub id: i64, - #[serde(deserialize_with = "serde_converters::html_encode")] pub title: String, #[serde(deserialize_with = "serde_converters::date_to_timestamp")] pub date: i64, diff --git a/src/render_html.rs b/src/render_html.rs index 3728b43..b2e5638 100644 --- a/src/render_html.rs +++ b/src/render_html.rs @@ -26,6 +26,17 @@ pub fn render_block(template_name: &str, block_name: &str, context } } +// TODO: Improve error handling +pub fn render_html_str(template_raw: &str, context: S) -> Result, Box> { + let template = SHARED_JINJA_ENV + .get() + .expect("Jinja environment not initialized!") + .render_str(template_raw, context)?; + // Minijiinja does not escape html when using render() + let str = v_htmlescape::escape(template.as_str()); + return Ok(Html(str.to_string())); +} + fn render( template_name: &str, block_name: &str, diff --git a/src/routes/todos/create_todo.rs b/src/routes/todos/create_todo.rs index 78b0f17..4c7ae2d 100644 --- a/src/routes/todos/create_todo.rs +++ b/src/routes/todos/create_todo.rs @@ -1,9 +1,11 @@ use crate::{ models::{todo_item::TodoItemRequest, user::User}, + render_html::render_html_str, AppState, }; -use axum::{extract::State, http::StatusCode, response::IntoResponse, Form}; +use axum::{extract::State, http::StatusCode, response::Html, Form}; use libsql::params; +use minijinja::context; use std::sync::Arc; use tower_sessions::Session; @@ -11,7 +13,7 @@ pub async fn create_todo( session: Session, State(state): State>, Form(form): Form, -) -> Result { +) -> Result, (StatusCode, String)> { let title_clone = form.title.clone(); let user = session.get::("user").await.unwrap().unwrap(); @@ -28,5 +30,11 @@ pub async fn create_todo( return Err((StatusCode::INTERNAL_SERVER_ERROR, String::from("Unknown error"))); } - return Ok(format!("Todo item '{}' succesfuly added", title_clone)); + return Ok(render_html_str( + "Todo item '{{ title_clone }}' succesfuly added!", + context! { + title_clone + }, + ) + .unwrap()); } diff --git a/src/serde_converters.rs b/src/serde_converters.rs index b9dbedb..2703fde 100644 --- a/src/serde_converters.rs +++ b/src/serde_converters.rs @@ -7,15 +7,6 @@ where { let s = String::deserialize(deserializer)?; let dt = NaiveDate::parse_from_str(&s, "%Y-%m-%d").map_err(serde::de::Error::custom)?; - let ts = dt.and_hms_opt(0, 0, 0).unwrap().timestamp(); + let ts = dt.and_hms_opt(0, 0, 0).unwrap().and_utc().timestamp(); return Ok(ts); } - -pub fn html_encode<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let s = String::deserialize(deserializer)?; - let s = html_escape::encode_text(&s); - return Ok(s.to_string()); -}