From 0fc23cd90b4ad52e0676a56f491c06b7032e909d Mon Sep 17 00:00:00 2001 From: victor koenders Date: Fri, 11 Nov 2022 15:42:31 +0100 Subject: [PATCH 1/8] Working login and register and basicaly zettel rendering --- Cargo.lock | 1397 +++++++++++++++++++++++++++-- Cargo.toml | 1 + data/sqlite/src/lib.rs | 11 + front/terminal/Cargo.toml | 1 - front/terminal/src/lib.rs | 60 +- front/terminal/src/view/utils.rs | 55 +- front/terminal/src/view/zettel.rs | 3 +- front/web/Cargo.toml | 15 +- front/web/src/lib.rs | 84 ++ front/web/src/req/mod.rs | 22 + front/web/src/req/user.rs | 55 ++ front/web/src/routes/login.rs | 55 ++ front/web/src/routes/mod.rs | 35 + front/web/src/routes/register.rs | 53 ++ front/web/src/routes/zettel.rs | 42 + front/web/templates/_layout.html | 15 + front/web/templates/login.html | 27 + front/web/templates/register.html | 23 + front/web/templates/zettel.html | 13 + justfile | 42 +- shared/src/lib.rs | 17 +- shared/src/storage.rs | 3 + src/main.rs | 19 +- 23 files changed, 1935 insertions(+), 113 deletions(-) create mode 100644 front/web/src/req/mod.rs create mode 100644 front/web/src/req/user.rs create mode 100644 front/web/src/routes/login.rs create mode 100644 front/web/src/routes/mod.rs create mode 100644 front/web/src/routes/register.rs create mode 100644 front/web/src/routes/zettel.rs create mode 100644 front/web/templates/_layout.html create mode 100644 front/web/templates/login.html create mode 100644 front/web/templates/register.html create mode 100644 front/web/templates/zettel.html diff --git a/Cargo.lock b/Cargo.lock index 3b99bf7..e3ed17b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,67 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aead" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +dependencies = [ + "generic-array", +] + +[[package]] +name = "aes" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" +dependencies = [ + "aes-soft", + "aesni", + "cipher 0.2.5", +] + +[[package]] +name = "aes-gcm" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" +dependencies = [ + "aead", + "aes", + "cipher 0.2.5", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "aes-soft" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" +dependencies = [ + "cipher 0.2.5", + "opaque-debug", +] + +[[package]] +name = "aesni" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" +dependencies = [ + "cipher 0.2.5", + "opaque-debug", +] + [[package]] name = "ahash" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom", + "getrandom 0.2.8", "once_cell", "version_check", ] @@ -31,6 +85,67 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "askama" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139" +dependencies = [ + "askama_derive", + "askama_escape", + "askama_shared", +] + +[[package]] +name = "askama_derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71" +dependencies = [ + "askama_shared", + "proc-macro2", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_shared" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0" +dependencies = [ + "askama_escape", + "mime", + "mime_guess", + "nom", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "async-attributes" version = "1.1.2" @@ -47,22 +162,32 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" dependencies = [ - "concurrent-queue", + "concurrent-queue 1.2.4", "event-listener", "futures-core", ] +[[package]] +name = "async-dup" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7427a12b8dc09291528cfb1da2447059adb4a257388c2acd6497a79d55cf6f7c" +dependencies = [ + "futures-io", + "simple-mutex", +] + [[package]] name = "async-executor" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" dependencies = [ + "async-lock", "async-task", - "concurrent-queue", + "concurrent-queue 2.0.0", "fastrand", "futures-lite", - "once_cell", "slab", ] @@ -81,6 +206,22 @@ dependencies = [ "once_cell", ] +[[package]] +name = "async-h1" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8101020758a4fc3a7c326cb42aa99e9fa77cbfb76987c128ad956406fe1f70a7" +dependencies = [ + "async-channel", + "async-dup", + "async-std", + "futures-core", + "http-types", + "httparse", + "log", + "pin-project", +] + [[package]] name = "async-io" version = "1.10.0" @@ -89,7 +230,7 @@ checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" dependencies = [ "async-lock", "autocfg", - "concurrent-queue", + "concurrent-queue 1.2.4", "futures-lite", "libc", "log", @@ -120,7 +261,7 @@ dependencies = [ "async-io", "autocfg", "blocking", - "cfg-if", + "cfg-if 1.0.0", "event-listener", "futures-lite", "libc", @@ -129,6 +270,41 @@ dependencies = [ "winapi", ] +[[package]] +name = "async-session" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345022a2eed092cd105cc1b26fd61c341e100bd5fcbbd792df4baf31c2cc631f" +dependencies = [ + "anyhow", + "async-std", + "async-trait", + "base64 0.12.3", + "bincode", + "blake3", + "chrono", + "hmac 0.8.1", + "kv-log-macro", + "rand 0.7.3", + "serde", + "serde_json", + "sha2 0.9.9", +] + +[[package]] +name = "async-sse" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53bba003996b8fd22245cd0c59b869ba764188ed435392cf2796d03b805ade10" +dependencies = [ + "async-channel", + "async-std", + "http-types", + "log", + "memchr", + "pin-project-lite 0.1.12", +] + [[package]] name = "async-std" version = "1.12.0" @@ -151,7 +327,7 @@ dependencies = [ "log", "memchr", "once_cell", - "pin-project-lite", + "pin-project-lite 0.2.9", "pin-utils", "slab", "wasm-bindgen-futures", @@ -195,6 +371,18 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + [[package]] name = "base64" version = "0.13.1" @@ -207,9 +395,18 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7e7c93a3fb23b2fdde989b2c9ec4dd153063ec81f408507f84c090cd91c6641" dependencies = [ - "base64", + "base64 0.13.1", "blowfish", - "getrandom", + "getrandom 0.2.8", +] + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", ] [[package]] @@ -218,6 +415,30 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "blake3" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if 0.1.10", + "constant_time_eq", + "crypto-mac 0.8.0", + "digest 0.9.0", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "block-buffer" version = "0.10.3" @@ -248,7 +469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7" dependencies = [ "byteorder", - "cipher", + "cipher 0.4.3", ] [[package]] @@ -283,9 +504,15 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "cc" -version = "1.0.74" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" + +[[package]] +name = "cfg-if" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" @@ -300,11 +527,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ "iana-time-zone", + "js-sys", "num-integer", "num-traits", + "serde", + "time 0.1.44", + "wasm-bindgen", "winapi", ] +[[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array", +] + [[package]] name = "cipher" version = "0.4.3" @@ -334,6 +574,54 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "concurrent-queue" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const_fn" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cookie" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" +dependencies = [ + "aes-gcm", + "base64 0.13.1", + "hkdf", + "hmac 0.10.1", + "percent-encoding", + "rand 0.8.5", + "sha2 0.9.9", + "time 0.2.27", + "version_check", +] + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -349,6 +637,12 @@ dependencies = [ "libc", ] +[[package]] +name = "cpuid-bool" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" + [[package]] name = "crc" version = "3.0.0" @@ -370,7 +664,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-utils", ] @@ -380,7 +674,7 @@ version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -418,6 +712,26 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "crypto-mac" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "ctor" version = "0.1.26" @@ -428,6 +742,15 @@ dependencies = [ "syn", ] +[[package]] +name = "ctr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" +dependencies = [ + "cipher 0.2.5", +] + [[package]] name = "custom_debug" version = "0.5.0" @@ -450,9 +773,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" +checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" dependencies = [ "cc", "cxxbridge-flags", @@ -462,9 +785,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" +checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" dependencies = [ "cc", "codespan-reporting", @@ -477,28 +800,37 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" +checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" [[package]] name = "cxxbridge-macro" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" +checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "digest" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ - "block-buffer", + "block-buffer 0.10.3", "crypto-common", ] @@ -522,6 +854,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + [[package]] name = "doc-comment" version = "0.3.3" @@ -549,6 +887,15 @@ dependencies = [ "serde", ] +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -576,6 +923,27 @@ dependencies = [ "spin 0.9.4", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -654,10 +1022,21 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite", + "pin-project-lite 0.2.9", "waker-fn", ] +[[package]] +name = "futures-macro" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-rustls" version = "0.22.2" @@ -688,9 +1067,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures-core", + "futures-macro", "futures-sink", "futures-task", - "pin-project-lite", + "pin-project-lite 0.2.9", "pin-utils", "slab", ] @@ -705,15 +1085,36 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "ghash" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" +dependencies = [ + "opaque-debug", + "polyval", ] [[package]] @@ -729,14 +1130,33 @@ dependencies = [ ] [[package]] -name = "hashbrown" -version = "0.12.3" +name = "h2" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ - "ahash", -] - + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + [[package]] name = "hashlink" version = "0.8.1" @@ -755,12 +1175,156 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" +dependencies = [ + "digest 0.9.0", + "hmac 0.10.1", +] + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac 0.8.0", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" +dependencies = [ + "crypto-mac 0.10.1", + "digest 0.9.0", +] + +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite 0.2.9", +] + +[[package]] +name = "http-client" +version = "6.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1947510dc91e2bf586ea5ffb412caad7673264e14bb39fb9078da114a94ce1a5" +dependencies = [ + "async-trait", + "cfg-if 1.0.0", + "http-types", + "log", +] + +[[package]] +name = "http-types" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e9b187a72d63adbfba487f48095306ac823049cb504ee195541e91c7775f5ad" +dependencies = [ + "anyhow", + "async-channel", + "async-std", + "base64 0.13.1", + "cookie", + "futures-lite", + "infer", + "pin-project-lite 0.2.9", + "rand 0.7.3", + "serde", + "serde_json", + "serde_qs", + "serde_urlencoded", + "url", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite 0.2.9", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -805,6 +1369,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "infer" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e9829a50b42bb782c1df523f78d332fe371b10c661e78b7a3c34b0198e9fac" + [[package]] name = "inout" version = "0.1.3" @@ -820,9 +1390,15 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] +[[package]] +name = "ipnet" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" + [[package]] name = "itertools" version = "0.10.5" @@ -904,16 +1480,45 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "value-bag", ] +[[package]] +name = "markdown" +version = "1.0.0-alpha.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ad4f4705119913653a71784beb4cb7f2ca652aaa3f8f87d069efcbe6231e245" +dependencies = [ + "log", + "regex", + "reqwest", + "tokio", + "unicode-id", +] + [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -928,8 +1533,26 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi", - "windows-sys", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.42.0", +] + +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] @@ -961,12 +1584,73 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "once_cell" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "openssl" +version = "0.10.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parking" version = "2.0.0" @@ -1000,7 +1684,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "instant", "libc", "redox_syscall", @@ -1014,11 +1698,11 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1053,6 +1737,12 @@ dependencies = [ "syn", ] +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1078,13 +1768,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" dependencies = [ "autocfg", - "cfg-if", + "cfg-if 1.0.0", "libc", "log", "wepoll-ffi", "winapi", ] +[[package]] +name = "polyval" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" +dependencies = [ + "cpuid-bool", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" version = "1.0.47" @@ -1103,6 +1816,77 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.8", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -1118,7 +1902,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom", + "getrandom 0.2.8", "redox_syscall", "thiserror", ] @@ -1149,6 +1933,43 @@ dependencies = [ "winapi", ] +[[package]] +name = "reqwest" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" +dependencies = [ + "base64 0.13.1", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite 0.2.9", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.16.20" @@ -1164,6 +1985,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "route-recognizer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56770675ebc04927ded3e60633437841581c285dc6236109ea25fbf3beb7b59e" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + [[package]] name = "rustls" version = "0.20.7" @@ -1182,7 +2018,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" dependencies = [ - "base64", + "base64 0.13.1", ] [[package]] @@ -1191,6 +2027,16 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys 0.36.1", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -1213,6 +2059,44 @@ dependencies = [ "untrusted", ] +[[package]] +name = "security-framework" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.147" @@ -1244,15 +2128,66 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_qs" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7715380eec75f029a4ef7de39a9200e0a63823176b759d055b613f5a87df6a6" +dependencies = [ + "percent-encoding", + "serde", + "thiserror", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +dependencies = [ + "sha1_smol", +] + +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + [[package]] name = "sha2" version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.10.5", ] [[package]] @@ -1285,6 +2220,15 @@ dependencies = [ "libc", ] +[[package]] +name = "simple-mutex" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38aabbeafa6f6dead8cebf246fe9fae1f9215c8d29b3a69f93bd62a9e4a3dcd6" +dependencies = [ + "event-listener", +] + [[package]] name = "slab" version = "0.4.7" @@ -1406,7 +2350,7 @@ dependencies = [ "rustls-pemfile", "serde", "serde_json", - "sha2", + "sha2 0.10.6", "smallvec", "sqlformat", "sqlx-rt", @@ -1431,7 +2375,7 @@ dependencies = [ "quote", "serde", "serde_json", - "sha2", + "sha2 0.10.6", "sqlx-core", "sqlx-rt", "syn", @@ -1448,6 +2392,64 @@ dependencies = [ "futures-rustls", ] +[[package]] +name = "standback" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" +dependencies = [ + "version_check", +] + +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + [[package]] name = "stringprep" version = "0.1.2" @@ -1458,6 +2460,18 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "sval" +version = "1.0.0-alpha.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45f6ee7c7b87caf59549e9fe45d6a69c75c8019e79e212a835c5da0e92f0ba08" + [[package]] name = "syn" version = "1.0.103" @@ -1487,7 +2501,7 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "libc", "redox_syscall", @@ -1524,6 +2538,77 @@ dependencies = [ "syn", ] +[[package]] +name = "tide" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c459573f0dd2cc734b539047f57489ea875af8ee950860ded20cf93a79a1dee0" +dependencies = [ + "async-h1", + "async-session", + "async-sse", + "async-std", + "async-trait", + "futures-util", + "http-client", + "http-types", + "kv-log-macro", + "log", + "pin-project-lite 0.2.9", + "route-recognizer", + "serde", + "serde_json", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "time" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" +dependencies = [ + "const_fn", + "libc", + "standback", + "stdweb", + "time-macros", + "version_check", + "winapi", +] + +[[package]] +name = "time-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" +dependencies = [ + "proc-macro-hack", + "time-macros-impl", +] + +[[package]] +name = "time-macros-impl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1539,6 +2624,93 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +[[package]] +name = "tokio" +version = "1.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "parking_lot 0.12.1", + "pin-project-lite 0.2.9", + "signal-hook-registry", + "socket2", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite 0.2.9", + "tokio", + "tracing", +] + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite 0.2.9", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + [[package]] name = "tui" version = "0.19.0" @@ -1558,12 +2730,27 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +[[package]] +name = "unicode-id" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" + [[package]] name = "unicode-ident" version = "1.0.5" @@ -1603,6 +2790,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "universal-hash" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -1618,6 +2815,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -1627,6 +2825,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" dependencies = [ "ctor", + "sval", "version_check", ] @@ -1648,6 +2847,28 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1660,7 +2881,7 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -1685,7 +2906,7 @@ version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1789,6 +3010,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -1796,12 +3030,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_x86_64_msvc 0.42.0", ] [[package]] @@ -1810,24 +3044,48 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + [[package]] name = "windows_x86_64_gnu" version = "0.42.0" @@ -1840,12 +3098,27 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "zettelkasten" version = "0.1.1" @@ -1903,4 +3176,12 @@ dependencies = [ [[package]] name = "zettelkasten-web" -version = "0.0.0" +version = "0.1.1" +dependencies = [ + "askama", + "markdown", + "serde", + "snafu", + "tide", + "zettelkasten-shared", +] diff --git a/Cargo.toml b/Cargo.toml index 1d7e81c..174599e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [features] runtime-async-std = [ "zettelkasten-sqlite?/runtime-async-std", + "zettelkasten-web?/runtime-async-std", "zettelkasten-shared/runtime-async-std", ] diff --git a/data/sqlite/src/lib.rs b/data/sqlite/src/lib.rs index 83391df..7a71fb3 100644 --- a/data/sqlite/src/lib.rs +++ b/data/sqlite/src/lib.rs @@ -85,6 +85,17 @@ impl Storage for Connection { Ok(user) } + async fn get_user_by_id(&self, id: UserId) -> Result { + let mut conn = self.conn.lock().await; + let query = sqlx::query_as!( + User, + "SELECT user_id as id, username as name, password, last_visited_zettel FROM users WHERE user_id = ?", + id + ); + + query.fetch_one(&mut *conn).await.context(SqlxSnafu) + } + async fn get_zettels( &self, user: UserId, diff --git a/front/terminal/Cargo.toml b/front/terminal/Cargo.toml index a185ed0..adc4a41 100644 --- a/front/terminal/Cargo.toml +++ b/front/terminal/Cargo.toml @@ -2,7 +2,6 @@ name = "zettelkasten-terminal" version = "0.1.1" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] crossterm = { version = "0.25.0", default-features = false } diff --git a/front/terminal/src/lib.rs b/front/terminal/src/lib.rs index 49626df..a42db82 100644 --- a/front/terminal/src/lib.rs +++ b/front/terminal/src/lib.rs @@ -12,7 +12,7 @@ use crossterm::{ use snafu::ResultExt; use std::{io::Stdout, sync::Arc}; use tui::backend::CrosstermBackend; -use zettelkasten_shared::{storage, Front}; +use zettelkasten_shared::{async_trait, storage, Front}; pub(crate) type Terminal = tui::Terminal>; @@ -35,44 +35,48 @@ impl Tui<'_> { } } +#[async_trait] impl Front for Tui<'_> { type Config = (); - fn run( + async fn run( _: Self::Config, mut system_config: storage::SystemConfig, storage: Arc, ) { - enable_raw_mode().expect("Could not enable raw mode"); - let mut stdout = std::io::stdout(); - execute!(stdout, EnterAlternateScreen, EnableMouseCapture) - .expect("Could not enable alternate screen and mouse capture"); + zettelkasten_shared::spawn_blocking(move || { + enable_raw_mode().expect("Could not enable raw mode"); + let mut stdout = std::io::stdout(); + execute!(stdout, EnterAlternateScreen, EnableMouseCapture) + .expect("Could not enable alternate screen and mouse capture"); - let backend = CrosstermBackend::new(stdout); - let mut terminal = Terminal::new(backend).expect("Could not instantiate the terminal"); - let mut view = view::View::new(&system_config, &storage); - let mut tui = Tui { - terminal: &mut terminal, - system_config: &mut system_config, - storage: &storage, - running: true, - }; + let backend = CrosstermBackend::new(stdout); + let mut terminal = Terminal::new(backend).expect("Could not instantiate the terminal"); + let mut view = view::View::new(&system_config, &storage); + let mut tui = Tui { + terminal: &mut terminal, + system_config: &mut system_config, + storage: &storage, + running: true, + }; - while tui.running { - let Err(e) = view.render(&mut tui) else { continue }; - let keycode = view::alert(tui.terminal, |f| { - f.title("Could not render page") - .text(e.to_string()) - .action(KeyCode::Char('q'), "quit") - .action(KeyCode::Enter, "continue") - }) - .expect("Double fault, time to crash to desktop"); + while tui.running { + let Err(e) = view.render(&mut tui) else { continue }; + let keycode = view::alert(tui.terminal, |f| { + f.title("Could not render page") + .text(e.to_string()) + .action(KeyCode::Char('q'), "quit") + .action(KeyCode::Enter, "continue") + }) + .expect("Double fault, time to crash to desktop"); - if keycode == KeyCode::Char('q') { - tui.running = false; + if keycode == KeyCode::Char('q') { + tui.running = false; + } } - } - drop(tui.terminal.clear()); + drop(tui.terminal.clear()); + }) + .await; } } diff --git a/front/terminal/src/view/utils.rs b/front/terminal/src/view/utils.rs index a4d64cd..389a00e 100644 --- a/front/terminal/src/view/utils.rs +++ b/front/terminal/src/view/utils.rs @@ -2,7 +2,8 @@ use crossterm::event::KeyCode; use snafu::ResultExt; use std::{ collections::HashMap, - io::{Read, Seek, SeekFrom, Write}, + fmt::{self, Write as _}, + io::{Read, Seek, SeekFrom, Write as _}, }; use tui::{ style::{Color, Style}, @@ -36,7 +37,7 @@ impl Default for RenderStyle { } pub struct ParsedZettel<'a> { - pub links: HashMap, + pub links: HashMap, pub link_char_size: usize, pub lines: Vec>, } @@ -147,29 +148,67 @@ impl NamingScheme { } } +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Naming { + Single(char), + Double(char, char), +} + +impl Naming { + fn len(self) -> usize { + match self { + Self::Single(_) => 1, + Self::Double(_, _) => 2, + } + } +} + +impl From<&str> for Naming { + fn from(s: &str) -> Naming { + match s.as_bytes() { + [first] => Naming::Single(*first as char), + [first, second] => Naming::Double(*first as char, *second as char), + _ => panic!("Unimplemented; string length {} to Naming", s.len()), + } + } +} + +impl fmt::Display for Naming { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Single(c) => f.write_char(*c), + Self::Double(first, second) => { + f.write_char(*first)?; + f.write_char(*second)?; + Ok(()) + } + } + } +} + impl Iterator for NamingScheme { - type Item = String; + type Item = Naming; fn next(&mut self) -> Option { match self { Self::Single { idx, chars } => { - let result = chars.get(*idx)?.to_string(); + let result = *chars.get(*idx)?; *idx += 1; - Some(result) + Some(Naming::Single(result)) } Self::Double { first_idx, second_idx, chars, } => { - let first = chars.get(*first_idx)?; - let second = chars.get(*second_idx)?; + let first = *chars.get(*first_idx)?; + let second = *chars.get(*second_idx)?; *second_idx += 1; if *second_idx >= chars.len() { *second_idx = 0; *first_idx += 1; } - Some(format!("{}{}", first, second)) + Some(Naming::Double(first, second)) } } } diff --git a/front/terminal/src/view/zettel.rs b/front/terminal/src/view/zettel.rs index c2c7fe4..44659c2 100644 --- a/front/terminal/src/view/zettel.rs +++ b/front/terminal/src/view/zettel.rs @@ -136,7 +136,8 @@ impl Zettel { if let KeyCode::Char(c) = key_event.code { filter.push(c); if filter.len() == zettel.link_char_size { - if let Some(link) = zettel.links.get(filter) { + let filter_as_naming = super::utils::Naming::from(filter.as_str()); + if let Some(link) = zettel.links.get(&filter_as_naming) { let transition = if let Some(sys_page) = super::utils::try_get_sys_page(tui, link)? { diff --git a/front/web/Cargo.toml b/front/web/Cargo.toml index 271c7d5..e46d864 100644 --- a/front/web/Cargo.toml +++ b/front/web/Cargo.toml @@ -1,6 +1,19 @@ [package] name = "zettelkasten-web" -version = "0.0.0" +version = "0.1.1" edition = "2021" +[features] +runtime-async-std = ["zettelkasten-shared/runtime-async-std"] + [dependencies] +zettelkasten-shared = { version = "0.1.1", path = "../../shared" } +snafu = { version = "0.7.3", default-features = false } +serde = { version = "1.0.147", default-features = false, features = ["derive"] } +askama = { version = "0.11.1", default-features = false } +markdown = { version = "1.0.0-alpha.3", default-features = false } + +[dependencies.tide] +version = "0.16.0" +default-features = false +features = ["h1-server", "sessions"] diff --git a/front/web/src/lib.rs b/front/web/src/lib.rs index 8b13789..6a7c31d 100644 --- a/front/web/src/lib.rs +++ b/front/web/src/lib.rs @@ -1 +1,85 @@ +mod req; +mod routes; +use std::{net::SocketAddr, sync::Arc}; +use tide::{log::warn, sessions::SessionMiddleware}; +use zettelkasten_shared::{async_trait, storage}; + +#[cfg(not(feature = "runtime-async-std"))] +compile_error!("zettelkasten_web requires feature `runtime-async-std`"); + +#[derive(Clone)] +pub struct Web { + pub(crate) system_config: storage::SystemConfig, + pub(crate) storage: Arc, +} +impl Web { + async fn can_register(&self) -> bool { + self.storage.user_count().await.unwrap_or(0) == 0 + || matches!(self.system_config.user_mode, storage::UserMode::MultiUser) + } +} + +#[async_trait] +impl zettelkasten_shared::Front for Web { + type Config = ServerConfig; + async fn run( + config: Self::Config, + system_config: storage::SystemConfig, + storage: Arc, + ) { + let mut app = tide::with_state(Web { + system_config, + storage, + }); + app.with(SessionMiddleware::new( + tide::sessions::MemoryStore::new(), + config.session_secret.as_deref().unwrap_or_else(|| { + let warning = + "Missing session secret. This should be set in a production environment."; + warn!("{warning}"); + warning.as_bytes() + }), + )); + app.at("/").get(routes::get_index); + app.at("/sys:login") + .get(routes::login::get) + .post(routes::login::post); + app.at("/sys:register") + .get(routes::register::get) + .post(routes::register::post); + app.at("/sys:config") + .get(routes::get_config) + .post(routes::post_config); + app.at("/*") + .get(routes::zettel::get) + .post(routes::zettel::post); + app.listen(config.bind_addr) + .await + .expect("Could not bind to addr"); + } +} + +pub struct ServerConfig { + pub bind_addr: SocketAddr, + pub session_secret: Option>, +} + +#[derive(snafu::Snafu, Debug)] +#[snafu(visibility(pub(crate)))] +pub enum Error { + #[snafu(display("Internal storage issue: {source:?}"))] + Storage { source: storage::Error }, + #[snafu(display("You are not logged in"))] + NotLoggedIn, + #[snafu(display("User not found"))] + UserNotFound, + #[snafu(display("This system does not permit registering a new account"))] + CannotRegister, + #[snafu(display("Passwords do not match"))] + PasswordMismatch, + #[snafu(display("Internal rendering issue"))] + Askama { source: askama::Error }, +} + +pub type Result = std::result::Result; diff --git a/front/web/src/req/mod.rs b/front/web/src/req/mod.rs new file mode 100644 index 0000000..e254854 --- /dev/null +++ b/front/web/src/req/mod.rs @@ -0,0 +1,22 @@ +mod user; + +pub use user::User; + +use snafu::ResultExt; +use zettelkasten_shared::storage; + +pub(crate) fn render_template(tmpl: impl askama::Template) -> tide::Result { + let str = tmpl.render().context(crate::AskamaSnafu)?; + let mut response = tide::Response::new(200); + response.set_content_type("text/HTML"); + response.set_body(str); + Ok(response) +} + +pub fn default_zettel() -> storage::Zettel { + storage::Zettel { + path: "/home".to_string(), + body: r#"Welcome to zettelkasten\n\n**bold**"#.to_string(), + ..Default::default() + } +} diff --git a/front/web/src/req/user.rs b/front/web/src/req/user.rs new file mode 100644 index 0000000..b323a16 --- /dev/null +++ b/front/web/src/req/user.rs @@ -0,0 +1,55 @@ +use std::sync::Arc; + +use tide::Redirect; +use zettelkasten_shared::storage; + +pub struct User { + user: storage::User, +} + +impl User { + pub async fn from_req(req: &tide::Request) -> crate::Result { + let session = req.session(); + let Some(user_id) = session.get::("user_id") else { + return Err(crate::Error::NotLoggedIn) + }; + + match req.state().storage.get_user_by_id(user_id).await { + Ok(user) => Ok(User { user }), + Err(_) => Err(crate::Error::UserNotFound), + } + } + + pub(crate) async fn load_last_visited_zettel( + &self, + storage: &Arc, + ) -> storage::Zettel { + if let Some(zettel_id) = self.user.last_visited_zettel { + if let Ok(zettel) = storage.get_zettel(self.user.id, zettel_id).await { + return zettel; + } + } + super::default_zettel() + } + + pub(crate) fn new_session(user: storage::User, session: &mut tide::sessions::Session) -> Self { + session.insert("user_id", user.id).unwrap(); + Self { user } + } + + pub(crate) async fn redirect_to_latest_zettel( + &self, + storage: &Arc, + ) -> tide::Response { + if let Some(zettel_id) = self.user.last_visited_zettel { + if let Ok(zettel) = storage.get_zettel(self.user.id, zettel_id).await { + return Redirect::new(format!("/{}", zettel.path)).into(); + } + } + Redirect::new("/").into() + } + + pub(crate) fn id(&self) -> i64 { + self.user.id + } +} diff --git a/front/web/src/routes/login.rs b/front/web/src/routes/login.rs new file mode 100644 index 0000000..b49c388 --- /dev/null +++ b/front/web/src/routes/login.rs @@ -0,0 +1,55 @@ +use super::Web; +use snafu::ResultExt; +use tide::{Redirect, Request, Result}; + +pub async fn get(req: Request) -> Result { + crate::req::render_template(Login { + can_register: req.state().can_register().await, + username: "", + error: None, + }) +} + +pub async fn post(mut req: Request) -> Result { + let login = req.body_form::().await?; + match req + .state() + .storage + .login(&login.username, &login.password) + .await + .context(crate::StorageSnafu) + { + Ok(Some(user)) => { + let user = crate::req::User::new_session(user, req.session_mut()); + Ok(user.redirect_to_latest_zettel(&req.state().storage).await) + } + Ok(None) => crate::req::render_template(Login { + username: &login.username, + error: Some(crate::Error::UserNotFound), + can_register: req.state().can_register().await, + }), + Err(e) => crate::req::render_template(Login { + username: &login.username, + error: Some(e), + can_register: req.state().can_register().await, + }), + } +} + +#[derive(askama::Template)] +#[template(path = "login.html")] +struct Login<'a> { + error: Option, + username: &'a str, + can_register: bool, +} + +#[derive(serde::Deserialize)] +struct PostLogin { + username: String, + password: String, +} + +pub(crate) fn redirect() -> tide::Result { + Ok(Redirect::new("/sys:login").into()) +} diff --git a/front/web/src/routes/mod.rs b/front/web/src/routes/mod.rs new file mode 100644 index 0000000..32a4b38 --- /dev/null +++ b/front/web/src/routes/mod.rs @@ -0,0 +1,35 @@ +pub mod login; +pub mod register; +pub mod zettel; + +use super::Web; +use crate::req::User; +use tide::{Redirect, Request, Result}; + +pub async fn get_index(req: Request) -> Result { + match User::from_req(&req).await { + Ok(user) => { + let zettel = user.load_last_visited_zettel(&req.state().storage).await; + crate::req::render_template(zettel::Zettel { + user: &user, + body: &zettel.body, + path: &zettel.path, + }) + } + Err(_) => Ok(Redirect::new("/sys:login").into()), + } +} + +pub async fn get_config(req: Request) -> Result { + let Ok(_user) = User::from_req(&req).await else { + return login::redirect(); + }; + Ok("config".into()) +} + +pub async fn post_config(req: Request) -> Result { + let Ok(_user) = User::from_req(&req).await else { + return login::redirect(); + }; + Ok("config".into()) +} diff --git a/front/web/src/routes/register.rs b/front/web/src/routes/register.rs new file mode 100644 index 0000000..56d0d99 --- /dev/null +++ b/front/web/src/routes/register.rs @@ -0,0 +1,53 @@ +use super::Web; +use snafu::ResultExt; +use tide::{Request, Result}; + +pub async fn get(_req: Request) -> Result { + crate::req::render_template(Register::default()) +} + +pub async fn post(mut req: Request) -> Result { + let register = req.body_form::().await?; + if !req.state().can_register().await { + return crate::req::render_template(Register { + error: Some(crate::Error::CannotRegister), + username: "", + }); + } + if register.password != register.repeat_password { + return crate::req::render_template(Register { + error: Some(crate::Error::PasswordMismatch), + username: ®ister.username, + }); + } + match req + .state() + .storage + .register(®ister.username, ®ister.password) + .await + .context(crate::StorageSnafu) + { + Ok(user) => { + let user = crate::req::User::new_session(user, req.session_mut()); + Ok(user.redirect_to_latest_zettel(&req.state().storage).await) + } + Err(e) => crate::req::render_template(Register { + error: Some(e), + username: ®ister.username, + }), + } +} + +#[derive(askama::Template, Default)] +#[template(path = "register.html")] +struct Register<'a> { + error: Option, + username: &'a str, +} + +#[derive(serde::Deserialize)] +struct PostRegister { + username: String, + password: String, + repeat_password: String, +} diff --git a/front/web/src/routes/zettel.rs b/front/web/src/routes/zettel.rs new file mode 100644 index 0000000..d083c86 --- /dev/null +++ b/front/web/src/routes/zettel.rs @@ -0,0 +1,42 @@ +use super::Web; +use crate::req; +use tide::{Request, Result}; + +pub async fn get(req: Request) -> Result { + let Ok(user) = crate::req::User::from_req(&req).await else { + return super::login::redirect(); + }; + let path = req.url().path(); + let zettel = match req.state().storage.get_zettel_by_url(user.id(), path).await { + Ok(Some(zettel)) => zettel, + Ok(None) if path == "/" => user.load_last_visited_zettel(&req.state().storage).await, + Ok(None) => crate::req::default_zettel(), + Err(e) => { + return Ok(e.to_string().into()); + } + }; + + crate::req::render_template(Zettel { + user: &user, + path: &zettel.path, + body: &zettel.body, + }) +} + +pub async fn post(_req: Request) -> Result { + todo!() +} + +#[derive(askama::Template)] +#[template(path = "zettel.html")] +pub struct Zettel<'a> { + pub user: &'a req::User, + pub path: &'a str, + pub body: &'a str, +} + +mod filters { + pub fn render(s: &str) -> ::askama::Result { + Ok(markdown::to_html(s).replace("\\n", "
")) + } +} diff --git a/front/web/templates/_layout.html b/front/web/templates/_layout.html new file mode 100644 index 0000000..da6fd6c --- /dev/null +++ b/front/web/templates/_layout.html @@ -0,0 +1,15 @@ + + + + + {% block title %}{{ title }}{% endblock %} + {% block head %}{% endblock %} + + + +
+ {% block content %}{% endblock %} +
+ + + \ No newline at end of file diff --git a/front/web/templates/login.html b/front/web/templates/login.html new file mode 100644 index 0000000..30f7395 --- /dev/null +++ b/front/web/templates/login.html @@ -0,0 +1,27 @@ +{% extends "_layout.html" %} + +{% block title %}Login{% endblock %} + +{% block head %} + +{% endblock %} + +{% block content %} +

Login

+{% match error %} +{% when Some(error) %}{{ error }} +{% when None %} +{% endmatch %} +
+ Username:
+ Password:
+ +
+ +{% if can_register %} +Register +{% endif %} + + +{% endblock %} \ No newline at end of file diff --git a/front/web/templates/register.html b/front/web/templates/register.html new file mode 100644 index 0000000..a5b7cc5 --- /dev/null +++ b/front/web/templates/register.html @@ -0,0 +1,23 @@ +{% extends "_layout.html" %} + +{% block title %}Login{% endblock %} + +{% block head %} + +{% endblock %} + +{% block content %} +

Register

+{% match error %} +{% when Some(error) %}{{ error }} +{% when None %} +{% endmatch %} +
+ Username:
+ Password:
+ Repeat:
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/front/web/templates/zettel.html b/front/web/templates/zettel.html new file mode 100644 index 0000000..22e0739 --- /dev/null +++ b/front/web/templates/zettel.html @@ -0,0 +1,13 @@ +{% extends "_layout.html" %} + +{% block title %}{{ path }}{% endblock %} + +{% block head %} + +{% endblock %} + +{% block content %} +{{ body|render|safe }} + +{% endblock %} \ No newline at end of file diff --git a/justfile b/justfile index 1b7dec9..ec2c5dc 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,18 @@ default: just --list +lint: fmt clippy + +clippy: + cargo clippy --features front-terminal,front-web,data-sqlite,runtime-async-std -- -D warnings + +fmt: + cargo fmt --all + +test: test_terminal test_web_sqlite + + + docs_terminal: cargo doc --features front-terminal,data-sqlite,runtime-async-std --open @@ -10,21 +22,27 @@ check_terminal: run_terminal: cargo run --features front-terminal,data-sqlite,runtime-async-std -install_terminal: - cargo install --path . --features front-terminal,data-sqlite,runtime-async-std +test_terminal: + cargo test --features front-terminal,data-sqlite,runtime-async-std --workspace -prepare_sqlite: - cd data/sqlite && cargo sqlx prepare -- --features runtime-async-std -lint: fmt clippy +docs_web_sqlite: + cargo doc --features front-web,data-sqlite,runtime-async-std --open -clippy: - cargo clippy --features front-terminal,data-sqlite,runtime-async-std -- -D warnings +check_web_sqlite: + cargo check --features front-web,data-sqlite,runtime-async-std -fmt: - cargo fmt --all +run_web_sqlite: + cargo run --features front-web,data-sqlite,runtime-async-std -test: test_async_std +test_web_sqlite: + cargo test --features front-web,data-sqlite,runtime-async-std + + + +install_terminal: + cargo install --path . --features front-terminal,data-sqlite,runtime-async-std + +prepare_sqlite: + cd data/sqlite && cargo sqlx prepare -- --features runtime-async-std -test_async_std: - cargo test --features front-terminal,data-sqlite,runtime-async-std --workspace diff --git a/shared/src/lib.rs b/shared/src/lib.rs index c864988..2b937d9 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -7,9 +7,14 @@ use std::future::Future; use std::sync::Arc; use storage::SystemConfig; +#[async_trait] pub trait Front: Send + Sync { - type Config: serde::ser::Serialize + serde::de::DeserializeOwned + Default; - fn run(config: Self::Config, system_config: SystemConfig, storage: Arc); + type Config; + async fn run( + config: Self::Config, + system_config: SystemConfig, + storage: Arc, + ); } #[cfg(feature = "runtime-async-std")] @@ -19,3 +24,11 @@ where { async_std::task::block_on(f) } + +#[cfg(feature = "runtime-async-std")] +pub fn spawn_blocking(f: F) -> impl Future +where + F: FnOnce() + Send + 'static, +{ + async_std::task::spawn_blocking(f) +} diff --git a/shared/src/storage.rs b/shared/src/storage.rs index b5ef09f..fde81f4 100644 --- a/shared/src/storage.rs +++ b/shared/src/storage.rs @@ -11,6 +11,8 @@ pub trait Storage: Send + Sync { async fn login_single_user(&self) -> Result; async fn login(&self, username: &str, password: &str) -> Result, Error>; async fn register(&self, username: &str, password: &str) -> Result; + async fn get_user_by_id(&self, id: UserId) -> Result; + async fn get_zettels( &self, user: UserId, @@ -24,6 +26,7 @@ pub trait Storage: Send + Sync { user: UserId, zettel_id: Option, ) -> Result<(), Error>; + async fn update_config(&self, config: &SystemConfig) -> Result<(), Error>; } diff --git a/src/main.rs b/src/main.rs index 85c4a71..f109385 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,12 +4,27 @@ use zettelkasten_shared::{ Front, }; +#[cfg(feature = "front-web")] +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; + #[allow(clippy::redundant_clone)] fn main() { zettelkasten_shared::block_on(async { let (connection, system_config) = data_policy_should_exist_exactly_once().await; - #[cfg(feature = "front-terminal")] - zettelkasten_terminal::Tui::run((), system_config.clone(), Arc::clone(&connection)); + let futures = [ + #[cfg(feature = "front-web")] + zettelkasten_web::Web::run( + zettelkasten_web::ServerConfig { + bind_addr: SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 8080)), + session_secret: None, + }, + system_config.clone(), + Arc::clone(&connection), + ), + #[cfg(feature = "front-terminal")] + zettelkasten_terminal::Tui::run((), system_config.clone(), Arc::clone(&connection)), + ]; + zettelkasten_shared::futures::future::join_all(futures).await; }); } From 44005eb4253de84afcff5849c35ff29b2876f7a1 Mon Sep 17 00:00:00 2001 From: victor koenders Date: Fri, 11 Nov 2022 17:07:28 +0100 Subject: [PATCH 2/8] Started service javascript for the zettel.html page --- front/web/src/lib.rs | 11 +++++++++++ front/web/static/script.js | 3 +++ front/web/templates/zettel.html | 8 ++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 front/web/static/script.js diff --git a/front/web/src/lib.rs b/front/web/src/lib.rs index 6a7c31d..ebbefc3 100644 --- a/front/web/src/lib.rs +++ b/front/web/src/lib.rs @@ -41,6 +41,17 @@ impl zettelkasten_shared::Front for Web { warning.as_bytes() }), )); + if std::path::Path::new("static").exists() { + app.at("/static") + .serve_dir("static") + .expect("Could not serve static dir"); + } else if cfg!(debug_assertions) && std::path::Path::new("front/web/static").exists() { + app.at("/static") + .serve_dir("front/web/static") + .expect("Could not serve static dir"); + } else { + panic!("`static` directory not found"); + } app.at("/").get(routes::get_index); app.at("/sys:login") .get(routes::login::get) diff --git a/front/web/static/script.js b/front/web/static/script.js new file mode 100644 index 0000000..7b489cd --- /dev/null +++ b/front/web/static/script.js @@ -0,0 +1,3 @@ +addEventListener("keydown", (event) => { + console.log(event); +}); \ No newline at end of file diff --git a/front/web/templates/zettel.html b/front/web/templates/zettel.html index 22e0739..67c3d03 100644 --- a/front/web/templates/zettel.html +++ b/front/web/templates/zettel.html @@ -3,11 +3,15 @@ {% block title %}{{ path }}{% endblock %} {% block head %} - + {% endblock %} {% block content %} {{ body|render|safe }} +

+ + A: All zettels, C: config, E: edit, F: follow link, L: log out, S: search + +

{% endblock %} \ No newline at end of file From 5524091ad99d45b92e4128f87a567a3afebcd88e Mon Sep 17 00:00:00 2001 From: victor koenders Date: Fri, 11 Nov 2022 17:08:29 +0100 Subject: [PATCH 3/8] Added the new query to the sqlite sqlx-data.json --- data/sqlite/sqlx-data.json | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/data/sqlite/sqlx-data.json b/data/sqlite/sqlx-data.json index 3d6337a..f08802a 100644 --- a/data/sqlite/sqlx-data.json +++ b/data/sqlite/sqlx-data.json @@ -1,5 +1,41 @@ { "db": "SQLite", + "0303d30d5c0752c2f61299d38b7b2db7b747536c9713c22c66d513a04328e361": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Int64" + }, + { + "name": "name", + "ordinal": 1, + "type_info": "Text" + }, + { + "name": "password", + "ordinal": 2, + "type_info": "Text" + }, + { + "name": "last_visited_zettel", + "ordinal": 3, + "type_info": "Int64" + } + ], + "nullable": [ + false, + false, + false, + true + ], + "parameters": { + "Right": 1 + } + }, + "query": "SELECT user_id as id, username as name, password, last_visited_zettel FROM users WHERE user_id = ?" + }, "26b414106803d4de7f1ebdf7f2e7c8d467da46cbbfe46f02c8e9dfd90832cc3b": { "describe": { "columns": [], From 94db7fdb04d7912d7924ed246874420250196f30 Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Sat, 12 Nov 2022 15:33:29 +0100 Subject: [PATCH 4/8] Added front-web to the build matrices --- .github/workflows/lints.yml | 2 +- .github/workflows/release.yml | 4 ++-- .github/workflows/rust.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 2b24687..baa51cc 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -31,7 +31,7 @@ jobs: matrix: data: [sqlite, postgres] runtime: [async-std] - front: [terminal] + front: [terminal, web] steps: - name: Checkout sources diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b14c2b..32d68ee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: data: [sqlite, postgres] - front: [terminal] + front: [terminal, web] steps: - name: Checkout sources @@ -57,7 +57,7 @@ jobs: strategy: matrix: data: [sqlite, postgres] - front: [terminal] + front: [terminal, web] steps: - name: Checkout sources diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4648765..c97c9fd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ jobs: matrix: data: [sqlite, postgres] runtime: [async-std] - front: [terminal] + front: [terminal, web] steps: - uses: actions/checkout@v3 From 78027c8ddbd4565601dd790e3c76bf9248bad93c Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Sat, 12 Nov 2022 15:37:54 +0100 Subject: [PATCH 5/8] Updated data/postgres/sqlx-data.json --- data/postgres/sqlx-data.json | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/data/postgres/sqlx-data.json b/data/postgres/sqlx-data.json index 4bd0537..99eb8d9 100644 --- a/data/postgres/sqlx-data.json +++ b/data/postgres/sqlx-data.json @@ -253,6 +253,44 @@ }, "query": "UPDATE zettel SET body = $1, PATH = $2 WHERE zettel_id = $3 AND user_id = $4" }, + "b83d4febca265b16e681cea5081bd87c6aa4910ab7cf00ff5ce1978f8e8344a3": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Int8" + }, + { + "name": "name", + "ordinal": 1, + "type_info": "Text" + }, + { + "name": "password", + "ordinal": 2, + "type_info": "Text" + }, + { + "name": "last_visited_zettel", + "ordinal": 3, + "type_info": "Int8" + } + ], + "nullable": [ + false, + false, + false, + true + ], + "parameters": { + "Left": [ + "Int8" + ] + } + }, + "query": "SELECT user_id as id, username as name, password, last_visited_zettel FROM users WHERE user_id = $1" + }, "c04b5d95e00a6a58bbf69536707e0784f02a300576d897ed458bcdc8f3c0710f": { "describe": { "columns": [ From f072e29548397b9776305893e09b171ea18b328d Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Sat, 12 Nov 2022 20:01:53 +0100 Subject: [PATCH 6/8] Cleaned up front/web a bit --- front/web/src/lib.rs | 23 +++++++++++++++++++++-- front/web/src/req/mod.rs | 22 ---------------------- front/web/src/routes/login.rs | 8 ++++---- front/web/src/routes/mod.rs | 4 ++-- front/web/src/routes/register.rs | 10 +++++----- front/web/src/routes/zettel.rs | 9 ++++----- front/web/src/{req => }/user.rs | 0 7 files changed, 36 insertions(+), 40 deletions(-) delete mode 100644 front/web/src/req/mod.rs rename front/web/src/{req => }/user.rs (100%) diff --git a/front/web/src/lib.rs b/front/web/src/lib.rs index ebbefc3..ede909e 100644 --- a/front/web/src/lib.rs +++ b/front/web/src/lib.rs @@ -1,6 +1,9 @@ -mod req; mod routes; +mod user; +pub(crate) use user::User; + +use snafu::ResultExt; use std::{net::SocketAddr, sync::Arc}; use tide::{log::warn, sessions::SessionMiddleware}; use zettelkasten_shared::{async_trait, storage}; @@ -33,7 +36,7 @@ impl zettelkasten_shared::Front for Web { storage, }); app.with(SessionMiddleware::new( - tide::sessions::MemoryStore::new(), + tide::sessions::CookieStore::new(), config.session_secret.as_deref().unwrap_or_else(|| { let warning = "Missing session secret. This should be set in a production environment."; @@ -94,3 +97,19 @@ pub enum Error { } pub type Result = std::result::Result; + +pub(crate) fn render_template(tmpl: impl askama::Template) -> tide::Result { + let str = tmpl.render().context(crate::AskamaSnafu)?; + let mut response = tide::Response::new(200); + response.set_content_type("text/HTML"); + response.set_body(str); + Ok(response) +} + +pub(crate) fn default_zettel() -> storage::Zettel { + storage::Zettel { + path: "/home".to_string(), + body: r#"Welcome to zettelkasten\n\n**bold**"#.to_string(), + ..Default::default() + } +} diff --git a/front/web/src/req/mod.rs b/front/web/src/req/mod.rs deleted file mode 100644 index e254854..0000000 --- a/front/web/src/req/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -mod user; - -pub use user::User; - -use snafu::ResultExt; -use zettelkasten_shared::storage; - -pub(crate) fn render_template(tmpl: impl askama::Template) -> tide::Result { - let str = tmpl.render().context(crate::AskamaSnafu)?; - let mut response = tide::Response::new(200); - response.set_content_type("text/HTML"); - response.set_body(str); - Ok(response) -} - -pub fn default_zettel() -> storage::Zettel { - storage::Zettel { - path: "/home".to_string(), - body: r#"Welcome to zettelkasten\n\n**bold**"#.to_string(), - ..Default::default() - } -} diff --git a/front/web/src/routes/login.rs b/front/web/src/routes/login.rs index b49c388..c369760 100644 --- a/front/web/src/routes/login.rs +++ b/front/web/src/routes/login.rs @@ -3,7 +3,7 @@ use snafu::ResultExt; use tide::{Redirect, Request, Result}; pub async fn get(req: Request) -> Result { - crate::req::render_template(Login { + crate::render_template(Login { can_register: req.state().can_register().await, username: "", error: None, @@ -20,15 +20,15 @@ pub async fn post(mut req: Request) -> Result { .context(crate::StorageSnafu) { Ok(Some(user)) => { - let user = crate::req::User::new_session(user, req.session_mut()); + let user = crate::User::new_session(user, req.session_mut()); Ok(user.redirect_to_latest_zettel(&req.state().storage).await) } - Ok(None) => crate::req::render_template(Login { + Ok(None) => crate::render_template(Login { username: &login.username, error: Some(crate::Error::UserNotFound), can_register: req.state().can_register().await, }), - Err(e) => crate::req::render_template(Login { + Err(e) => crate::render_template(Login { username: &login.username, error: Some(e), can_register: req.state().can_register().await, diff --git a/front/web/src/routes/mod.rs b/front/web/src/routes/mod.rs index 32a4b38..d0ab667 100644 --- a/front/web/src/routes/mod.rs +++ b/front/web/src/routes/mod.rs @@ -3,14 +3,14 @@ pub mod register; pub mod zettel; use super::Web; -use crate::req::User; +use crate::User; use tide::{Redirect, Request, Result}; pub async fn get_index(req: Request) -> Result { match User::from_req(&req).await { Ok(user) => { let zettel = user.load_last_visited_zettel(&req.state().storage).await; - crate::req::render_template(zettel::Zettel { + crate::render_template(zettel::Zettel { user: &user, body: &zettel.body, path: &zettel.path, diff --git a/front/web/src/routes/register.rs b/front/web/src/routes/register.rs index 56d0d99..eb95fec 100644 --- a/front/web/src/routes/register.rs +++ b/front/web/src/routes/register.rs @@ -3,19 +3,19 @@ use snafu::ResultExt; use tide::{Request, Result}; pub async fn get(_req: Request) -> Result { - crate::req::render_template(Register::default()) + crate::render_template(Register::default()) } pub async fn post(mut req: Request) -> Result { let register = req.body_form::().await?; if !req.state().can_register().await { - return crate::req::render_template(Register { + return crate::render_template(Register { error: Some(crate::Error::CannotRegister), username: "", }); } if register.password != register.repeat_password { - return crate::req::render_template(Register { + return crate::render_template(Register { error: Some(crate::Error::PasswordMismatch), username: ®ister.username, }); @@ -28,10 +28,10 @@ pub async fn post(mut req: Request) -> Result { .context(crate::StorageSnafu) { Ok(user) => { - let user = crate::req::User::new_session(user, req.session_mut()); + let user = crate::User::new_session(user, req.session_mut()); Ok(user.redirect_to_latest_zettel(&req.state().storage).await) } - Err(e) => crate::req::render_template(Register { + Err(e) => crate::render_template(Register { error: Some(e), username: ®ister.username, }), diff --git a/front/web/src/routes/zettel.rs b/front/web/src/routes/zettel.rs index d083c86..48b58b1 100644 --- a/front/web/src/routes/zettel.rs +++ b/front/web/src/routes/zettel.rs @@ -1,22 +1,21 @@ use super::Web; -use crate::req; use tide::{Request, Result}; pub async fn get(req: Request) -> Result { - let Ok(user) = crate::req::User::from_req(&req).await else { + let Ok(user) = crate::User::from_req(&req).await else { return super::login::redirect(); }; let path = req.url().path(); let zettel = match req.state().storage.get_zettel_by_url(user.id(), path).await { Ok(Some(zettel)) => zettel, Ok(None) if path == "/" => user.load_last_visited_zettel(&req.state().storage).await, - Ok(None) => crate::req::default_zettel(), + Ok(None) => crate::default_zettel(), Err(e) => { return Ok(e.to_string().into()); } }; - crate::req::render_template(Zettel { + crate::render_template(Zettel { user: &user, path: &zettel.path, body: &zettel.body, @@ -30,7 +29,7 @@ pub async fn post(_req: Request) -> Result { #[derive(askama::Template)] #[template(path = "zettel.html")] pub struct Zettel<'a> { - pub user: &'a req::User, + pub user: &'a crate::User, pub path: &'a str, pub body: &'a str, } diff --git a/front/web/src/req/user.rs b/front/web/src/user.rs similarity index 100% rename from front/web/src/req/user.rs rename to front/web/src/user.rs From a85aefd3e0bf5449f668becce3eec211879e6474 Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Sun, 13 Nov 2022 16:15:42 +0100 Subject: [PATCH 7/8] Started switching front/web to pulldown-cmark with a custom renderer --- Cargo.lock | 477 +------------------------ front/web/Cargo.toml | 2 +- front/web/src/lib.rs | 3 +- front/web/src/routes/zettel.rs | 8 +- front/web/src/routes/zettel/filters.rs | 115 ++++++ 5 files changed, 139 insertions(+), 466 deletions(-) create mode 100644 front/web/src/routes/zettel/filters.rs diff --git a/Cargo.lock b/Cargo.lock index 74ad867..78a4b06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,16 +612,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -888,15 +878,6 @@ dependencies = [ "serde", ] -[[package]] -name = "encoding_rs" -version = "0.8.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "event-listener" version = "2.5.3" @@ -924,27 +905,6 @@ dependencies = [ "spin 0.9.4", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.1.0" @@ -1130,25 +1090,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "h2" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1176,15 +1117,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hex" version = "0.4.3" @@ -1239,28 +1171,6 @@ dependencies = [ "digest 0.10.5", ] -[[package]] -name = "http" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http", - "pin-project-lite 0.2.9", -] - [[package]] name = "http-client" version = "6.5.3" @@ -1301,49 +1211,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite 0.2.9", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1412,12 +1279,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "ipnet" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" - [[package]] name = "itertools" version = "0.10.5" @@ -1503,19 +1364,6 @@ dependencies = [ "value-bag", ] -[[package]] -name = "markdown" -version = "1.0.0-alpha.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ad4f4705119913653a71784beb4cb7f2ca652aaa3f8f87d069efcbe6231e245" -dependencies = [ - "log", - "regex", - "reqwest", - "tokio", - "unicode-id", -] - [[package]] name = "md-5" version = "0.10.5" @@ -1562,25 +1410,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.42.0", -] - -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "windows-sys", ] [[package]] @@ -1612,16 +1442,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "once_cell" version = "1.16.0" @@ -1634,51 +1454,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" -dependencies = [ - "bitflags", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking" version = "2.0.0" @@ -1730,7 +1505,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -1835,6 +1610,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pulldown-cmark" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d9cc634bc78768157b5cbfe988ffcd1dcba95cd2b2f03a88316c08c6d00ed63" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.21" @@ -1961,43 +1747,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "reqwest" -version = "0.11.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" -dependencies = [ - "base64 0.13.1", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite 0.2.9", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "ring" version = "0.16.20" @@ -2055,16 +1804,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" -[[package]] -name = "schannel" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" -dependencies = [ - "lazy_static", - "windows-sys 0.36.1", -] - [[package]] name = "scopeguard" version = "1.1.0" @@ -2087,29 +1826,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -2671,93 +2387,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "parking_lot 0.12.1", - "pin-project-lite 0.2.9", - "signal-hook-registry", - "socket2", - "tokio-macros", - "winapi", -] - -[[package]] -name = "tokio-macros" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite 0.2.9", - "tokio", - "tracing", -] - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if 1.0.0", - "pin-project-lite 0.2.9", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" -dependencies = [ - "once_cell", -] - -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - [[package]] name = "tui" version = "0.19.0" @@ -2792,12 +2421,6 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" -[[package]] -name = "unicode-id" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" - [[package]] name = "unicode-ident" version = "1.0.5" @@ -2894,16 +2517,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -3068,19 +2681,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - [[package]] name = "windows-sys" version = "0.42.0" @@ -3088,12 +2688,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc", ] [[package]] @@ -3102,48 +2702,24 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - [[package]] name = "windows_x86_64_gnu" version = "0.42.0" @@ -3156,27 +2732,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - [[package]] name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "zettelkasten" version = "0.1.1" @@ -3251,7 +2812,7 @@ name = "zettelkasten-web" version = "0.1.1" dependencies = [ "askama", - "markdown", + "pulldown-cmark", "serde", "snafu", "tide", diff --git a/front/web/Cargo.toml b/front/web/Cargo.toml index e46d864..29cfd25 100644 --- a/front/web/Cargo.toml +++ b/front/web/Cargo.toml @@ -11,7 +11,7 @@ zettelkasten-shared = { version = "0.1.1", path = "../../shared" } snafu = { version = "0.7.3", default-features = false } serde = { version = "1.0.147", default-features = false, features = ["derive"] } askama = { version = "0.11.1", default-features = false } -markdown = { version = "1.0.0-alpha.3", default-features = false } +pulldown-cmark = { version = "0.9.2", default-features = false } [dependencies.tide] version = "0.16.0" diff --git a/front/web/src/lib.rs b/front/web/src/lib.rs index ede909e..63d9552 100644 --- a/front/web/src/lib.rs +++ b/front/web/src/lib.rs @@ -109,7 +109,8 @@ pub(crate) fn render_template(tmpl: impl askama::Template) -> tide::Result { pub(crate) fn default_zettel() -> storage::Zettel { storage::Zettel { path: "/home".to_string(), - body: r#"Welcome to zettelkasten\n\n**bold**"#.to_string(), + body: r#"Welcome to zettelkasten\n\n**bold**\n\n[sys:config]\n\n[config](sys:config)"# + .to_string(), ..Default::default() } } diff --git a/front/web/src/routes/zettel.rs b/front/web/src/routes/zettel.rs index 48b58b1..a8b8360 100644 --- a/front/web/src/routes/zettel.rs +++ b/front/web/src/routes/zettel.rs @@ -1,3 +1,5 @@ +mod filters; + use super::Web; use tide::{Request, Result}; @@ -33,9 +35,3 @@ pub struct Zettel<'a> { pub path: &'a str, pub body: &'a str, } - -mod filters { - pub fn render(s: &str) -> ::askama::Result { - Ok(markdown::to_html(s).replace("\\n", "
")) - } -} diff --git a/front/web/src/routes/zettel/filters.rs b/front/web/src/routes/zettel/filters.rs new file mode 100644 index 0000000..8c0f5c7 --- /dev/null +++ b/front/web/src/routes/zettel/filters.rs @@ -0,0 +1,115 @@ +use pulldown_cmark::{BrokenLink, CowStr, Event, Options, Parser, Tag}; +use std::fmt::Write; + +pub fn render(s: &str) -> ::askama::Result { + let mut binding = accept_all_links; + + let mut parser = Parser::new_with_broken_link_callback(s, Options::all(), Some(&mut binding)); + let mut output = String::new(); + let mut writer = Writer { out: &mut output }; + while let Some(event) = parser.next() { + if let Err(e) = writer.event(&mut parser, event) { + return Err(askama::Error::Fmt(e)); + } + } + + Ok(output) +} + +struct Writer<'a> { + out: &'a mut String, +} +impl Writer<'_> { + pub(crate) fn event(&mut self, parser: &mut Parser, event: Event) -> std::fmt::Result { + match event { + Event::Start(tag) => self.start_tag(parser, tag), + Event::End(tag) => self.end_tag(parser, tag), + Event::Text(text) => self.text(parser, text), + Event::Code(code) => self.code(parser, code), + Event::Html(html) => self.html(parser, html), + Event::FootnoteReference(reference) => self.footnote_reference(parser, reference), + Event::SoftBreak => self.soft_break(), + Event::HardBreak => self.hard_break(), + Event::Rule => self.rule(), + Event::TaskListMarker(marker) => self.task_list_marker(parser, marker), + } + } + + fn start_tag(&mut self, _parser: &mut Parser, tag: Tag) -> std::fmt::Result { + match tag { + Tag::Paragraph => write!(self.out, "

"), + Tag::Heading(level, id, classes) => { + write!(self.out, "<{level}")?; + if let Some(id) = id { + write!(self.out, " id={id:?}")?; + } + if !classes.is_empty() { + write!(self.out, " class=\"")?; + for (idx, class) in classes.into_iter().enumerate() { + if idx != 0 { + self.out.push(' '); + } + *self.out += class; + } + self.out.push('"'); + } + self.out.push('>'); + Ok(()) + } + Tag::BlockQuote => todo!(), + Tag::CodeBlock(_) => todo!(), + Tag::List(_) => todo!(), + Tag::Item => todo!(), + Tag::FootnoteDefinition(_) => todo!(), + Tag::Table(_) => todo!(), + Tag::TableHead => todo!(), + Tag::TableRow => todo!(), + Tag::TableCell => todo!(), + Tag::Emphasis => todo!(), + Tag::Strong => todo!(), + Tag::Strikethrough => todo!(), + Tag::Link(_, _, _) => todo!(), + Tag::Image(_, _, _) => todo!(), + } + } + + fn end_tag(&mut self, _parser: &mut Parser, _tag: Tag) -> std::fmt::Result { + todo!() + } + + fn text(&mut self, _parser: &mut Parser, _text: CowStr) -> std::fmt::Result { + todo!() + } + + fn code(&mut self, _parser: &mut Parser, _code: CowStr) -> std::fmt::Result { + todo!() + } + + fn html(&mut self, _parser: &mut Parser, _html: CowStr) -> std::fmt::Result { + todo!() + } + + fn footnote_reference(&mut self, _parser: &mut Parser, _reference: CowStr) -> std::fmt::Result { + todo!() + } + + fn soft_break(&mut self) -> std::fmt::Result { + todo!() + } + + fn hard_break(&mut self) -> std::fmt::Result { + todo!() + } + + fn rule(&mut self) -> std::fmt::Result { + todo!() + } + + fn task_list_marker(&mut self, _parser: &mut Parser, _marker: bool) -> std::fmt::Result { + todo!() + } +} + +fn accept_all_links(link: BrokenLink<'_>) -> Option<(CowStr<'_>, CowStr<'_>)> { + Some((link.reference.clone(), link.reference)) +} From 62e0646bfab9b1ce51842b1718470a8301e0b853 Mon Sep 17 00:00:00 2001 From: victor koenders Date: Mon, 14 Nov 2022 17:19:19 +0100 Subject: [PATCH 8/8] Started working on getting a decent layout in front/web's zettel page --- front/web/src/lib.rs | 8 ++++- front/web/src/routes/zettel/filters.rs | 32 +++++++++---------- front/web/static/style.css | 43 ++++++++++++++++++++++++++ front/web/templates/_layout.html | 1 + front/web/templates/zettel.html | 11 +++++-- 5 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 front/web/static/style.css diff --git a/front/web/src/lib.rs b/front/web/src/lib.rs index 63d9552..f915618 100644 --- a/front/web/src/lib.rs +++ b/front/web/src/lib.rs @@ -109,7 +109,13 @@ pub(crate) fn render_template(tmpl: impl askama::Template) -> tide::Result { pub(crate) fn default_zettel() -> storage::Zettel { storage::Zettel { path: "/home".to_string(), - body: r#"Welcome to zettelkasten\n\n**bold**\n\n[sys:config]\n\n[config](sys:config)"# + body: r#"Welcome to zettelkasten + +**bold** + +[sys:config] + +[config](sys:config)"# .to_string(), ..Default::default() } diff --git a/front/web/src/routes/zettel/filters.rs b/front/web/src/routes/zettel/filters.rs index 8c0f5c7..1e3be5a 100644 --- a/front/web/src/routes/zettel/filters.rs +++ b/front/web/src/routes/zettel/filters.rs @@ -56,29 +56,25 @@ impl Writer<'_> { self.out.push('>'); Ok(()) } - Tag::BlockQuote => todo!(), - Tag::CodeBlock(_) => todo!(), - Tag::List(_) => todo!(), - Tag::Item => todo!(), - Tag::FootnoteDefinition(_) => todo!(), - Tag::Table(_) => todo!(), - Tag::TableHead => todo!(), - Tag::TableRow => todo!(), - Tag::TableCell => todo!(), - Tag::Emphasis => todo!(), - Tag::Strong => todo!(), - Tag::Strikethrough => todo!(), - Tag::Link(_, _, _) => todo!(), - Tag::Image(_, _, _) => todo!(), + Tag::Strong => write!(self.out, ""), + Tag::Link(_, url, text) => write!(self.out, "["), + tag => todo!("{tag:?}"), } } - fn end_tag(&mut self, _parser: &mut Parser, _tag: Tag) -> std::fmt::Result { - todo!() + fn end_tag(&mut self, _parser: &mut Parser, tag: Tag) -> std::fmt::Result { + match tag { + Tag::Paragraph => write!(self.out, "

"), + Tag::Heading(level, ..) => write!(self.out, ""), + Tag::Strong => write!(self.out, ""), + Tag::Link(_, _, _) => write!(self.out, "]"), + tag => todo!("{tag:?}"), + } } - fn text(&mut self, _parser: &mut Parser, _text: CowStr) -> std::fmt::Result { - todo!() + fn text(&mut self, _parser: &mut Parser, text: CowStr) -> std::fmt::Result { + *self.out += text.as_ref(); + Ok(()) } fn code(&mut self, _parser: &mut Parser, _code: CowStr) -> std::fmt::Result { diff --git a/front/web/static/style.css b/front/web/static/style.css new file mode 100644 index 0000000..480e439 --- /dev/null +++ b/front/web/static/style.css @@ -0,0 +1,43 @@ +html, +body { + width: 100%; + height: 100%; + padding: 0; + margin: 0; +} + +#content { + display: flex; + flex-direction: column; + height: 100%; +} + +.flex { + display: flex; + flex-grow: 1; +} + +.zettel { + width: 800px; +} + +.edit_zettel { + display: none; + flex-grow: 1; + /* textareas are 5px larger than their parents for god-knows why */ + /* so we fix that here */ + padding-right: 5px; + padding-bottom: 5px; +} + +.edit_zettel>textarea { + width: 100%; + height: 100%; + padding: 0; + margin: 0; +} + +.footer { + width: 100%; + flex-grow: 0; +} \ No newline at end of file diff --git a/front/web/templates/_layout.html b/front/web/templates/_layout.html index da6fd6c..39a7f34 100644 --- a/front/web/templates/_layout.html +++ b/front/web/templates/_layout.html @@ -3,6 +3,7 @@ {% block title %}{{ title }}{% endblock %} + {% block head %}{% endblock %} diff --git a/front/web/templates/zettel.html b/front/web/templates/zettel.html index 67c3d03..3894c81 100644 --- a/front/web/templates/zettel.html +++ b/front/web/templates/zettel.html @@ -7,8 +7,15 @@ {% endblock %} {% block content %} -{{ body|render|safe }} -

+

+
+ {{ body|render|safe }} +
+
+ +
+
+