From 3691b817aa7f218c3368f6677aeb097d1ebea7dd Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Mon, 29 Aug 2022 13:21:41 -0500 Subject: [PATCH 01/17] start rocket 0.5 port --- Cargo.lock | 1651 +++++++++++++---- Cargo.toml | 13 +- Rocket.toml | 2 + build.rs | 5 + .../20220829063159_initial_migration.sql | 16 + rust-toolchain | 1 - src/actions.rs | 164 +- src/db.rs | 32 + src/main.rs | 134 +- 9 files changed, 1464 insertions(+), 554 deletions(-) create mode 100644 Rocket.toml create mode 100644 build.rs create mode 100644 migrations/20220829063159_initial_migration.sql delete mode 100644 rust-toolchain create mode 100644 src/db.rs diff --git a/Cargo.lock b/Cargo.lock index 7f7c63b..841fd83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" -dependencies = [ - "gimli", -] - [[package]] name = "adler" version = "1.0.2" @@ -19,29 +10,30 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" -version = "0.3.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" dependencies = [ "generic-array 0.14.5", ] [[package]] name = "aes" -version = "0.6.0" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ - "aes-soft", - "aesni", + "cfg-if 1.0.0", "cipher", + "cpufeatures", + "opaque-debug 0.3.0", ] [[package]] name = "aes-gcm" -version = "0.8.0" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" +checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" dependencies = [ "aead", "aes", @@ -52,38 +44,41 @@ dependencies = [ ] [[package]] -name = "aes-soft" -version = "0.6.4" +name = "ahash" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "cipher", - "opaque-debug 0.3.0", + "getrandom 0.2.7", + "once_cell", + "version_check 0.9.4", ] [[package]] -name = "aesni" -version = "0.10.0" +name = "aho-corasick" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ - "cipher", - "opaque-debug 0.3.0", + "memchr", ] [[package]] -name = "ahash" -version = "0.4.7" +name = "android_system_properties" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" +checksum = "d7ed72e1635e121ca3e79420540282af22da58be50de153d36f81ddc6b83aa9e" +dependencies = [ + "libc", +] [[package]] -name = "aho-corasick" -version = "0.7.18" +name = "ansi_term" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "memchr", + "winapi 0.3.9", ] [[package]] @@ -103,15 +98,54 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97be891acc47ca214468e09425d02cef3af2c94d0d82081cd02061f996802f14" +[[package]] +name = "async-stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "async-trait" version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" dependencies = [ - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atoi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" +dependencies = [ + "autocfg 1.1.0", ] [[package]] @@ -141,19 +175,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "backtrace" -version = "0.3.66" +name = "base-x" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" -dependencies = [ - "addr2line", - "cc", - "cfg-if 1.0.0", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" [[package]] name = "base64" @@ -177,6 +202,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" +[[package]] +name = "binascii" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72" + [[package]] name = "bitflags" version = "1.3.2" @@ -204,15 +235,6 @@ dependencies = [ "generic-array 0.12.4", ] -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array 0.14.5", -] - [[package]] name = "block-buffer" version = "0.10.2" @@ -231,6 +253,15 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "memchr", +] + [[package]] name = "buf_redux" version = "0.8.4" @@ -285,17 +316,41 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ - "libc", + "iana-time-zone", + "js-sys", "num-integer", "num-traits", - "time", + "time 0.1.44", + "wasm-bindgen", "winapi 0.3.9", ] +[[package]] +name = "chrono-tz" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde" +dependencies = [ + "chrono", + "chrono-tz-build", + "phf 0.11.1", +] + +[[package]] +name = "chrono-tz-build" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c" +dependencies = [ + "parse-zoneinfo", + "phf 0.11.1", + "phf_codegen 0.11.1", +] + [[package]] name = "chunked_transfer" version = "0.3.1" @@ -304,9 +359,9 @@ checksum = "498d20a7aaf62625b9bf26e637cf7736417cde1d0c99f1d04d1170229a85cf87" [[package]] name = "cipher" -version = "0.2.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ "generic-array 0.14.5", ] @@ -320,20 +375,28 @@ dependencies = [ "bitflags", ] +[[package]] +name = "const_fn" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" + [[package]] name = "cookie" -version = "0.11.4" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80f6044740a4a516b8aac14c140cdf35c1a640b1bd6b98b6224e49143b2f1566" +checksum = "94d4706de1b0fa5b132270cddffa8585166037822e260a944fe161acd137ca05" dependencies = [ "aes-gcm", "base64 0.13.0", "hkdf", - "hmac 0.10.1", + "hmac", "percent-encoding 2.1.0", "rand 0.8.5", - "sha2 0.9.9", - "time", + "sha2", + "subtle", + "time 0.3.14", + "version_check 0.9.4", ] [[package]] @@ -362,10 +425,19 @@ dependencies = [ ] [[package]] -name = "cpuid-bool" -version = "0.2.0" +name = "crc" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49fc9a695bca7f35f5f4c15cddc84415f66a74ea78eef08e90c5024f2b540e23" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" +checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" [[package]] name = "crc32fast" @@ -377,30 +449,40 @@ dependencies = [ ] [[package]] -name = "crypto-common" -version = "0.1.5" +name = "crossbeam-queue" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ccfd8c0ee4cce11e45b3fd6f9d5e69e0cc62912aa6a0cb1bf4617b0eba5a12f" +checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" dependencies = [ - "generic-array 0.14.5", - "typenum", + "cfg-if 1.0.0", + "crossbeam-utils", ] [[package]] -name = "crypto-mac" -version = "0.10.1" +name = "crossbeam-utils" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + +[[package]] +name = "crypto-common" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a" +checksum = "2ccfd8c0ee4cce11e45b3fd6f9d5e69e0cc62912aa6a0cb1bf4617b0eba5a12f" dependencies = [ "generic-array 0.14.5", - "subtle", + "typenum", ] [[package]] name = "ctr" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" +checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" dependencies = [ "cipher", ] @@ -413,9 +495,9 @@ checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" [[package]] name = "devise" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd716c4a507adc5a2aa7c2a372d06c7497727e0892b243d3036bc7478a13e526" +checksum = "50c7580b072f1c8476148f16e0a0d5dedddab787da98d86c5082c5e9ed8ab595" dependencies = [ "devise_codegen", "devise_core", @@ -423,24 +505,25 @@ dependencies = [ [[package]] name = "devise_codegen" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea7b8290d118127c08e3669da20b331bed56b09f20be5945b7da6c116d8fab53" +checksum = "123c73e7a6e51b05c75fe1a1b2f4e241399ea5740ed810b0e3e6cacd9db5e7b2" dependencies = [ "devise_core", - "quote 0.6.13", + "quote", ] [[package]] name = "devise_core" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1053e9d5d5aade9bcedb5ab53b78df2b56ff9408a3138ce77eaaef87f932373" +checksum = "841ef46f4787d9097405cac4e70fb8644fc037b526e8c14054247c0263c400d0" dependencies = [ "bitflags", - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "syn", ] [[package]] @@ -452,15 +535,6 @@ dependencies = [ "generic-array 0.12.4", ] -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array 0.14.5", -] - [[package]] name = "digest" version = "0.10.3" @@ -472,12 +546,44 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi 0.3.9", +] + +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + [[package]] name = "dotenv" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + [[package]] name = "encoding_rs" version = "0.8.31" @@ -488,14 +594,10 @@ dependencies = [ ] [[package]] -name = "error-chain" -version = "0.12.4" +name = "event-listener" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "backtrace", - "version_check 0.9.4", -] +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "fake-simd" @@ -503,18 +605,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -[[package]] -name = "fallible-iterator" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" - -[[package]] -name = "fallible-streaming-iterator" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" - [[package]] name = "fastrand" version = "1.7.0" @@ -524,6 +614,20 @@ dependencies = [ "instant", ] +[[package]] +name = "figment" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df" +dependencies = [ + "atomic", + "pear", + "serde", + "toml", + "uncased", + "version_check 0.9.4", +] + [[package]] name = "filetime" version = "0.2.17" @@ -546,6 +650,18 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project", + "spin 0.9.4", +] + [[package]] name = "fnv" version = "1.0.7" @@ -626,7 +742,6 @@ checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" dependencies = [ "futures-channel", "futures-core", - "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -661,21 +776,21 @@ dependencies = [ ] [[package]] -name = "futures-io" -version = "0.3.21" +name = "futures-intrusive" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +checksum = "62007592ac46aa7c2b6416f7deb9a8a8f63a01e0f1d6e1787d5630170db2b63e" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot 0.11.2", +] [[package]] -name = "futures-macro" +name = "futures-io" version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" -dependencies = [ - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", -] +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-sink" @@ -698,7 +813,6 @@ dependencies = [ "futures-channel", "futures-core", "futures-io", - "futures-macro", "futures-sink", "futures-task", "memchr", @@ -707,6 +821,19 @@ dependencies = [ "slab", ] +[[package]] +name = "generator" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc184cace1cea8335047a471cc1da80f18acf8a76f3bab2028d499e328948ec7" +dependencies = [ + "cc", + "libc", + "log 0.4.17", + "rustversion", + "windows", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -750,31 +877,43 @@ dependencies = [ [[package]] name = "ghash" -version = "0.3.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" +checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" dependencies = [ "opaque-debug 0.3.0", "polyval", ] [[package]] -name = "gimli" -version = "0.26.1" +name = "glob" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] -name = "glob" -version = "0.2.11" +name = "globset" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" +checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log 0.4.17", + "regex", +] [[package]] -name = "glob" -version = "0.3.0" +name = "globwalk" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] [[package]] name = "groupable" @@ -803,9 +942,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.9.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ "ahash", ] @@ -818,11 +957,20 @@ checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" [[package]] name = "hashlink" -version = "0.6.0" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +dependencies = [ + "hashbrown 0.11.2", +] + +[[package]] +name = "heck" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d99cf782f0dc4372d26846bec3de7804ceb5df083c2d4462c0b8d2330e894fa8" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" dependencies = [ - "hashbrown 0.9.1", + "unicode-segmentation", ] [[package]] @@ -835,23 +983,18 @@ dependencies = [ ] [[package]] -name = "hkdf" -version = "0.10.0" +name = "hex" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" -dependencies = [ - "digest 0.9.0", - "hmac 0.10.1", -] +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] -name = "hmac" -version = "0.10.1" +name = "hkdf" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" +checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" dependencies = [ - "crypto-mac", - "digest 0.9.0", + "hmac", ] [[package]] @@ -915,7 +1058,7 @@ dependencies = [ "log 0.3.9", "mime 0.2.6", "num_cpus", - "time", + "time 0.1.44", "traitobject", "typeable", "unicase 1.4.2", @@ -959,6 +1102,19 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "iana-time-zone" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad2bfd338099682614d3ee3fe0cd72e0b6a41ca6a87f6a74a3bd593c91650501" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "js-sys", + "wasm-bindgen", + "winapi 0.3.9", +] + [[package]] name = "idna" version = "0.1.5" @@ -981,6 +1137,24 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "ignore" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" +dependencies = [ + "crossbeam-utils", + "globset", + "lazy_static", + "log 0.4.17", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + [[package]] name = "indexmap" version = "1.9.1" @@ -989,8 +1163,15 @@ checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg 1.1.0", "hashbrown 0.12.2", + "serde", ] +[[package]] +name = "inlinable_string" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" + [[package]] name = "inotify" version = "0.7.1" @@ -1051,6 +1232,15 @@ dependencies = [ "url 1.7.2", ] +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.2" @@ -1102,9 +1292,9 @@ checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libsqlite3-sys" -version = "0.20.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d31059f22935e6c31830db5249ba2b7ecd54fd73a9909286f0a67aa55c2fbd" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" dependencies = [ "cc", "pkg-config", @@ -1139,12 +1329,36 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "loom" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" +dependencies = [ + "cfg-if 1.0.0", + "generator", + "scoped-tls", + "serde", + "serde_json", + "tracing", + "tracing-subscriber", +] + [[package]] name = "maplit" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.9" @@ -1189,7 +1403,7 @@ checksum = "216929a5ee4dd316b1702eedf5e74548c123d370f47841ceaac38ca154690ca3" dependencies = [ "mime 0.2.6", "phf 0.7.24", - "phf_codegen", + "phf_codegen 0.7.24", "unicase 1.4.2", ] @@ -1203,6 +1417,12 @@ dependencies = [ "unicase 2.6.0", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.5.3" @@ -1273,6 +1493,26 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" +[[package]] +name = "multer" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a30ba6d97eb198c5e8a35d67d5779d6680cca35652a60ee90fc23dc431d4fde8" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http", + "httparse", + "log 0.4.17", + "memchr", + "mime 0.3.16", + "spin 0.9.4", + "tokio", + "tokio-util", + "version_check 0.9.4", +] + [[package]] name = "multipart" version = "0.17.1" @@ -1350,11 +1590,30 @@ dependencies = [ "regex", "serde", "serde_json", - "time", + "time 0.1.44", "typemap", "url 1.7.2", ] +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "normpath" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04aaf5e9cb0fbf883cc0423159eacdf96a9878022084b35c462c428cab73bcaf" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "notify" version = "4.0.17" @@ -1403,12 +1662,12 @@ dependencies = [ ] [[package]] -name = "object" -version = "0.29.0" +name = "num_threads" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" dependencies = [ - "memchr", + "libc", ] [[package]] @@ -1450,9 +1709,9 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1474,6 +1733,17 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.5", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1481,7 +1751,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.3", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi 0.3.9", ] [[package]] @@ -1497,6 +1781,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "parse-zoneinfo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" +dependencies = [ + "regex", +] + [[package]] name = "password-hash" version = "0.3.2" @@ -1508,26 +1801,33 @@ dependencies = [ "subtle", ] +[[package]] +name = "paste" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22" + [[package]] name = "pear" -version = "0.1.5" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32dfa7458144c6af7f9ce6a137ef975466aa68ffa44d4d816ee5934018ba960a" +checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702" dependencies = [ + "inlinable_string", "pear_codegen", + "yansi", ] [[package]] name = "pear_codegen" -version = "0.1.5" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0288ba5d581afbc93e2bbd931c1013584c15ecf46b1cdb927edc7abddbc8ca6" +checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0" dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", - "version_check 0.9.4", - "yansi", + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "syn", ] [[package]] @@ -1569,9 +1869,9 @@ checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" dependencies = [ "pest", "pest_meta", - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1582,7 +1882,7 @@ checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" dependencies = [ "maplit", "pest", - "sha-1", + "sha-1 0.8.2", ] [[package]] @@ -1596,11 +1896,11 @@ dependencies = [ [[package]] name = "phf" -version = "0.10.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" dependencies = [ - "phf_shared 0.10.0", + "phf_shared 0.11.1", ] [[package]] @@ -1609,10 +1909,20 @@ version = "0.7.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" dependencies = [ - "phf_generator", + "phf_generator 0.7.24", "phf_shared 0.7.24", ] +[[package]] +name = "phf_codegen" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770" +dependencies = [ + "phf_generator 0.11.1", + "phf_shared 0.11.1", +] + [[package]] name = "phf_generator" version = "0.7.24" @@ -1623,6 +1933,16 @@ dependencies = [ "rand 0.6.5", ] +[[package]] +name = "phf_generator" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" +dependencies = [ + "phf_shared 0.11.1", + "rand 0.8.5", +] + [[package]] name = "phf_shared" version = "0.7.24" @@ -1635,11 +1955,32 @@ dependencies = [ [[package]] name = "phf_shared" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" dependencies = [ "siphasher 0.3.10", + "uncased", +] + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1671,72 +2012,16 @@ dependencies = [ [[package]] name = "polyval" -version = "0.4.5" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" +checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ - "cpuid-bool", + "cfg-if 1.0.0", + "cpufeatures", "opaque-debug 0.3.0", "universal-hash", ] -[[package]] -name = "postgres" -version = "0.19.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8bbcd5f6deb39585a0d9f4ef34c4a41c25b7ad26d23c75d837d78c8e7adc85f" -dependencies = [ - "bytes", - "fallible-iterator", - "futures", - "log 0.4.17", - "tokio", - "tokio-postgres", -] - -[[package]] -name = "postgres-native-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d442770e2b1e244bb5eb03b31c79b65bb2568f413b899eaba850fa945a65954" -dependencies = [ - "futures", - "native-tls", - "tokio", - "tokio-native-tls", - "tokio-postgres", -] - -[[package]] -name = "postgres-protocol" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "878c6cbf956e03af9aa8204b407b9cbf47c072164800aa918c516cd4b056c50c" -dependencies = [ - "base64 0.13.0", - "byteorder", - "bytes", - "fallible-iterator", - "hmac 0.12.1", - "md-5", - "memchr", - "rand 0.8.5", - "sha2 0.10.2", - "stringprep", -] - -[[package]] -name = "postgres-types" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd6e8b7189a73169290e89bd24c771071f1012d8fe6f738f5226531f0b03d89" -dependencies = [ - "bytes", - "chrono", - "fallible-iterator", - "postgres-protocol", -] - [[package]] name = "ppv-lite86" version = "0.2.16" @@ -1744,13 +2029,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] -name = "proc-macro2" -version = "0.4.30" +name = "proc-macro-hack" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid", -] +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" @@ -1762,19 +2044,23 @@ dependencies = [ ] [[package]] -name = "quick-error" -version = "1.2.3" +name = "proc-macro2-diagnostics" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "version_check 0.9.4", + "yansi", +] [[package]] -name = "quote" -version = "0.6.13" +name = "quick-error" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -dependencies = [ - "proc-macro2 0.4.30", -] +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" @@ -1782,7 +2068,7 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ - "proc-macro2 1.0.40", + "proc-macro2", ] [[package]] @@ -1980,6 +2266,37 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.7", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "ref-cast" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13bcd201494ab44900a96490291651d200730904221832b9547d24a87d332b" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5234cd6063258a5e32903b53b1b6ac043a0541c8adc1f610f67b0326c7a578fa" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "regex" version = "1.6.0" @@ -1991,6 +2308,15 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.27" @@ -2043,94 +2369,165 @@ dependencies = [ "winreg", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted", + "web-sys", + "winapi 0.3.9", +] + [[package]] name = "rocket" -version = "0.4.11" +version = "0.5.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83b9d9dc08c5dcc1d8126a9dd615545e6a358f8c13c883c8dfed8c0376fa355e" +checksum = "98ead083fce4a405feb349cf09abdf64471c6077f14e0ce59364aa90d4b99317" dependencies = [ + "async-stream", + "async-trait", + "atomic", "atty", - "base64 0.13.0", + "binascii", + "bytes", + "either", + "figment", + "futures", + "indexmap", "log 0.4.17", "memchr", + "multer", "num_cpus", - "pear", + "parking_lot 0.12.1", + "pin-project-lite", + "rand 0.8.5", + "ref-cast", "rocket_codegen", "rocket_http", + "serde", + "serde_json", "state", - "time", - "toml", + "tempfile", + "time 0.3.14", + "tokio", + "tokio-stream", + "tokio-util", + "ubyte", "version_check 0.9.4", "yansi", ] [[package]] name = "rocket_codegen" -version = "0.4.11" +version = "0.5.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2810037b5820098af97bd4fdd309e76a8101ceb178147de775c835a2537284fe" +checksum = "d6aeb6bb9c61e9cd2c00d70ea267bf36f76a4cc615e5908b349c2f9d93999b47" dependencies = [ "devise", - "glob 0.3.0", + "glob", "indexmap", - "quote 0.6.13", + "proc-macro2", + "quote", "rocket_http", + "syn", + "unicode-xid", +] + +[[package]] +name = "rocket_db_pools" +version = "0.1.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bc154f4f4985a136e2d59c336474a56da02103993f5e637e3a5424971ee4eff" +dependencies = [ + "rocket", + "rocket_db_pools_codegen", + "sqlx", "version_check 0.9.4", - "yansi", ] [[package]] -name = "rocket_contrib" -version = "0.4.11" +name = "rocket_db_pools_codegen" +version = "0.1.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e20efbc6a211cb3df5375accf532d4186f224b623f39eca650b19b96240c596b" +checksum = "0aa8f9b37bb1d4827aa5cca400d74e91d30f4352713cb65d6e7427bafe21336c" dependencies = [ - "glob 0.3.0", - "log 0.4.17", + "devise", + "quote", +] + +[[package]] +name = "rocket_dyn_templates" +version = "0.1.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab13df598440527c200f46fb944dc55d8d67a1818b617eb5a3981dcd8b63fd2" +dependencies = [ + "glob", + "normpath", "notify", "rocket", - "serde", - "serde_json", "tera", ] [[package]] name = "rocket_http" -version = "0.4.11" +version = "0.5.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf9cbd128e1f321a2d0bebd2b7cf0aafd89ca43edf69e49b56a5c46e48eb19f" +checksum = "2ded65d127954de3c12471630bf4b81a2792f065984461e65b91d0fdaafc17a2" dependencies = [ "cookie", - "hyper 0.10.16", + "either", + "futures", + "http", + "hyper 0.14.20", "indexmap", + "log 0.4.17", + "memchr", "pear", - "percent-encoding 1.0.1", + "percent-encoding 2.1.0", + "pin-project-lite", + "ref-cast", + "serde", "smallvec", + "stable-pattern", "state", - "time", - "unicode-xid", + "time 0.3.14", + "tokio", + "uncased", ] [[package]] -name = "rusqlite" -version = "0.24.2" +name = "rustc_version" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38ee71cbab2c827ec0ac24e76f82eca723cee92c509a65f67dee393c25112" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "bitflags", - "fallible-iterator", - "fallible-streaming-iterator", - "hashlink", - "libsqlite3-sys", - "memchr", - "smallvec", + "semver", ] [[package]] -name = "rustc-demangle" -version = "0.1.21" +name = "rustls" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +dependencies = [ + "base64 0.13.0", + "log 0.4.17", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustversion" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" [[package]] name = "ryu" @@ -2151,19 +2548,18 @@ dependencies = [ "argon2", "chrono", "dotenv", + "log 0.4.17", "multipart", "native-tls", - "postgres", - "postgres-native-tls", "rand 0.8.5", "regex", "reqwest", "rocket", - "rocket_contrib", - "rusqlite", + "rocket_db_pools", + "rocket_dyn_templates", "serde", - "serde_derive", "serde_json", + "sqlx", "uuid", "zip", ] @@ -2187,12 +2583,28 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "security-framework" version = "2.6.1" @@ -2216,11 +2628,29 @@ dependencies = [ "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.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" +dependencies = [ + "serde_derive", +] [[package]] name = "serde_derive" @@ -2228,9 +2658,9 @@ version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -2269,18 +2699,31 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.9.9" +name = "sha-1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" dependencies = [ - "block-buffer 0.9.0", "cfg-if 1.0.0", "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.0", + "digest 0.10.3", ] +[[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.10.2" @@ -2292,6 +2735,24 @@ dependencies = [ "digest 0.10.3", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + [[package]] name = "siphasher" version = "0.2.3" @@ -2335,11 +2796,203 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + +[[package]] +name = "sqlformat" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "551873805652ba0d912fec5bbb0f8b4cdd96baf8e2ebf5970e5671092966019b" +dependencies = [ + "sqlx-core", + "sqlx-macros", +] + +[[package]] +name = "sqlx-core" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48c61941ccf5ddcada342cd59e3e5173b007c509e1e8e990dafc830294d9dc5" +dependencies = [ + "ahash", + "atoi", + "base64 0.13.0", + "bitflags", + "byteorder", + "bytes", + "crc", + "crossbeam-queue", + "dirs", + "either", + "event-listener", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "hashlink", + "hex", + "hkdf", + "hmac", + "indexmap", + "itoa", + "libc", + "libsqlite3-sys", + "log 0.4.17", + "md-5", + "memchr", + "once_cell", + "paste", + "percent-encoding 2.1.0", + "rand 0.8.5", + "rustls", + "serde", + "serde_json", + "sha-1 0.10.0", + "sha2", + "smallvec", + "sqlformat", + "sqlx-rt", + "stringprep", + "thiserror", + "time 0.2.27", + "tokio-stream", + "url 2.2.2", + "webpki", + "webpki-roots", + "whoami", +] + +[[package]] +name = "sqlx-macros" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0fba2b0cae21fc00fe6046f8baa4c7fcb49e379f0f592b04696607f69ed2e1" +dependencies = [ + "dotenv", + "either", + "heck", + "once_cell", + "proc-macro2", + "quote", + "sha2", + "sqlx-core", + "sqlx-rt", + "syn", + "url 2.2.2", +] + +[[package]] +name = "sqlx-rt" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4db708cd3e459078f85f39f96a00960bd841f66ee2a669e90bf36907f5a79aae" +dependencies = [ + "once_cell", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "stable-pattern" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4564168c00635f88eaed410d5efa8131afa8d8699a612c80c455a0ba05c21045" +dependencies = [ + "memchr", +] + +[[package]] +name = "standback" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" +dependencies = [ + "version_check 0.9.4", +] + [[package]] name = "state" -version = "0.4.2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe866e1e51e8260c9eed836a042a5e7f6726bb2b411dffeaa712e19c388f23b" +dependencies = [ + "loom", +] + +[[package]] +name = "stdweb" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483" +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" @@ -2357,25 +3010,14 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" -[[package]] -name = "syn" -version = "0.15.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "unicode-xid", -] - [[package]] name = "syn" version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ - "proc-macro2 1.0.40", - "quote 1.0.20", + "proc-macro2", + "quote", "unicode-ident", ] @@ -2395,23 +3037,24 @@ dependencies = [ [[package]] name = "tera" -version = "0.11.20" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" +checksum = "1d4685e72cb35f0eb74319c8fe2d3b61e93da5609841cde2cb87fcc3bea56d20" dependencies = [ "chrono", - "error-chain", - "glob 0.2.11", + "chrono-tz", + "globwalk", "humansize", "lazy_static", + "percent-encoding 2.1.0", "pest", "pest_derive", + "rand 0.8.5", "regex", "serde", "serde_json", "slug", "unic-segment", - "url 1.7.2", ] [[package]] @@ -2429,9 +3072,18 @@ version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", ] [[package]] @@ -2445,6 +3097,62 @@ dependencies = [ "winapi 0.3.9", ] +[[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 0.1.1", + "version_check 0.9.4", + "winapi 0.3.9", +] + +[[package]] +name = "time" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b" +dependencies = [ + "itoa", + "libc", + "num_threads", + "time-macros 0.2.4", +] + +[[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" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" + +[[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 = "tiny_http" version = "0.6.4" @@ -2486,10 +3194,23 @@ dependencies = [ "num_cpus", "once_cell", "pin-project-lite", + "signal-hook-registry", "socket2", + "tokio-macros", "winapi 0.3.9", ] +[[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" @@ -2501,26 +3222,25 @@ dependencies = [ ] [[package]] -name = "tokio-postgres" -version = "0.7.6" +name = "tokio-rustls" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19c88a47a23c5d2dc9ecd28fb38fba5fc7e5ddc1fe64488ec145076b0c71c8ae" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ - "async-trait", - "byteorder", - "bytes", - "fallible-iterator", - "futures", - "log 0.4.17", - "parking_lot", - "percent-encoding 2.1.0", - "phf 0.10.1", + "rustls", + "tokio", + "webpki", +] + +[[package]] +name = "tokio-stream" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df54d54117d6fdc4e4fea40fe1e4e566b3505700e148a6827e59b34b0d2600d9" +dependencies = [ + "futures-core", "pin-project-lite", - "postgres-protocol", - "postgres-types", - "socket2", "tokio", - "tokio-util", ] [[package]] @@ -2539,9 +3259,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.10" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] @@ -2560,9 +3280,21 @@ checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.28" @@ -2570,6 +3302,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log 0.4.17", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b" +dependencies = [ + "ansi_term", + "matchers", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -2614,47 +3376,66 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "ubyte" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a58e29f263341a29bb79e14ad7fda5f63b1c7e48929bad4c685d7876b1d04e94" +dependencies = [ + "serde", +] + [[package]] name = "ucd-trie" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" +[[package]] +name = "uncased" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" +dependencies = [ + "serde", + "version_check 0.9.4", +] + [[package]] name = "unic-char-property" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36d3f7ce754afdbccccf8ff0dd0134e50fb44aaae579f96218856e9e5dbd1e" +checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" dependencies = [ "unic-char-range", ] [[package]] name = "unic-char-range" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9ab85fab42ad1b26cafc03bf891f69cb4d6e15f491030e89a0122197baa8ae8" +checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" [[package]] name = "unic-common" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8d4a7ade929ef7d971e16ced21a8cd56a63869aa6032dfb8cb083cf7d077bf" +checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" [[package]] name = "unic-segment" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9ca47cbb09fb5fcd066b5867d11dc528302fa465277882797d6a836e1ee6f9e" +checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" dependencies = [ "unic-ucd-segment", ] [[package]] name = "unic-ucd-segment" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f1a08ce0409a9e391b88d1930118eec48af12742fc538bcec55f775865776e" +checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" dependencies = [ "unic-char-property", "unic-char-range", @@ -2663,9 +3444,9 @@ dependencies = [ [[package]] name = "unic-ucd-version" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1f5e6c6c53c2d0ece4a5964bc55fcff8602153063cb4fab20958ff32998ff6" +checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" dependencies = [ "unic-common", ] @@ -2709,11 +3490,23 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" + [[package]] name = "unicode-xid" -version = "0.1.0" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" + +[[package]] +name = "unicode_categories" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" [[package]] name = "universal-hash" @@ -2734,6 +3527,12 @@ dependencies = [ "traitobject", ] +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "1.7.2" @@ -2766,6 +3565,12 @@ dependencies = [ "getrandom 0.2.7", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" @@ -2842,9 +3647,9 @@ dependencies = [ "bumpalo", "lazy_static", "log 0.4.17", - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", + "proc-macro2", + "quote", + "syn", "wasm-bindgen-shared", ] @@ -2866,7 +3671,7 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" dependencies = [ - "quote 1.0.20", + "quote", "wasm-bindgen-macro-support", ] @@ -2876,9 +3681,9 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ - "proc-macro2 1.0.40", - "quote 1.0.20", - "syn 1.0.98", + "proc-macro2", + "quote", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2899,6 +3704,35 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +dependencies = [ + "webpki", +] + +[[package]] +name = "whoami" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524b58fa5a20a2fb3014dd6358b70e6579692a56ef6fce928834e488f42f65e8" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + [[package]] name = "winapi" version = "0.2.8" @@ -2942,43 +3776,86 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbedf6db9096bc2364adce0ae0aa636dcd89f3c3f2cd67947062aaf0ca2a10ec" +dependencies = [ + "windows_aarch64_msvc 0.32.0", + "windows_i686_gnu 0.32.0", + "windows_i686_msvc 0.32.0", + "windows_x86_64_gnu 0.32.0", + "windows_x86_64_msvc 0.32.0", +] + [[package]] name = "windows-sys" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "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_aarch64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_i686_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" + [[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_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_x86_64_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" + [[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_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" diff --git a/Cargo.toml b/Cargo.toml index 496073a..b4ae2ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,17 +9,16 @@ dotenv = "0.15" regex = "1.4" argon2 = "0.3" rand = "0.8.3" -rocket = { version = "0.4.10", features = ["private-cookies"] } -rocket_contrib = { version = "0.4.10", features = ["tera_templates"] } multipart = "0.17.1" zip = { version = "0.5.9", default-features = false, features = ["deflate"] } -rusqlite = { version = "0.24.2", features = ["bundled"] } -postgres = { version = "0.19", features = ["with-chrono-0_4"] } -postgres-native-tls = "0.5" native-tls = "0.2.7" chrono = "0.4" uuid = { version = "0.8.2", features = ["v4"] } -serde = "1.0" -serde_derive = "1.0" +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" reqwest = { version = "0.11", features = ["blocking", "json"] } +rocket = { version = "0.5.0-rc.2", features = ["secrets", "json"] } +rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] } +sqlx = { version = "0.5", features = ["postgres", "sqlite", "tls", "migrate", "macros", "time"] } +rocket_db_pools = { version = "0.1.0-rc.2", features = ["sqlx_postgres", "sqlx_sqlite"] } +log = "0.4" diff --git a/Rocket.toml b/Rocket.toml new file mode 100644 index 0000000..58fd27c --- /dev/null +++ b/Rocket.toml @@ -0,0 +1,2 @@ +[default.databases.fixes] +url = "host=localhost port=5432 dbname=sakubun connect_timeout=10" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..7609593 --- /dev/null +++ b/build.rs @@ -0,0 +1,5 @@ +// generated by `sqlx migrate build-script` +fn main() { + // trigger recompilation when a new migration is added + println!("cargo:rerun-if-changed=migrations"); +} \ No newline at end of file diff --git a/migrations/20220829063159_initial_migration.sql b/migrations/20220829063159_initial_migration.sql new file mode 100644 index 0000000..c4276c6 --- /dev/null +++ b/migrations/20220829063159_initial_migration.sql @@ -0,0 +1,16 @@ +CREATE TABLE overrides ( + id serial PRIMARY KEY, + sentence_id INTEGER NOT NULL, + override_type VARCHAR NOT NULL, + value VARCHAR NOT NULL, + primary_value BOOLEAN NOT NULL DEFAULT FALSE +); + +CREATE TABLE reports ( + id serial PRIMARY KEY, + sentence_id INTEGER NOT NULL, + report_type VARCHAR NOT NULL, + suggested VARCHAR (500), + comment VARCHAR (500), + reported_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index bf867e0..0000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly diff --git a/src/actions.rs b/src/actions.rs index d57cf02..b5a35d0 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,9 +1,11 @@ +use sqlx::{Executor, query, query_as}; +use crate::db::Db; + use super::{AdminReport, AdminOverride, OrderedImport, QuizSettings, Report, AddOverride, EditOverride}; -use postgres::Client; use rand::prelude::*; use regex::Regex; -use rocket::{http::Status, request::Form, response::status::Custom}; -use rusqlite::{Connection, NO_PARAMS}; +use rocket::{http::Status, form::Form, response::status::Custom}; +use rocket_db_pools::Connection; use std::{ collections::{HashMap, HashSet}, error::Error, @@ -121,7 +123,7 @@ impl Sentence for AdminOverride { } } -fn fill_sentences(client: &mut Client, sentences: &mut Vec, add_overrides: bool) { +async fn fill_sentences(mut db: Connection, sentences: &mut Vec, add_overrides: bool) { let mut queue: HashMap> = HashMap::new(); for (i, sentence) in sentences.iter().enumerate() { if queue.contains_key(&sentence.get_id()) { @@ -151,33 +153,34 @@ fn fill_sentences(client: &mut Client, sentences: &mut Vec, add_ } // Add the overrides - for row in client - .query( + let sentence_ids = queue.keys().copied().collect::>(); + for row in + query!( "SELECT * FROM overrides WHERE sentence_id = ANY($1) ORDER BY primary_value DESC", - &[&queue.keys().collect::>()], + &sentence_ids ) - .unwrap() + .fetch_all(&mut *db) + .await.unwrap() { - let indices = queue.get(&row.get("sentence_id")).unwrap(); + let indices = queue.get(&row.sentence_id).unwrap(); // The concept of a primary value exists only for readings - let override_type = row.get("override_type"); - if override_type != "reading" || row.get("primary_value") { + if row.override_type != "reading" || row.primary_value { // This is either a primary reading or a non-reading override, so we can just set that // property to the new value for i in indices { - sentences[*i].set(override_type, row.get("value")); + sentences[*i].set(&row.override_type, row.value.clone()); } } else { // This is a non-primary reading for i in indices { - sentences[*i].add_reading(row.get("value")); + sentences[*i].add_reading(row.value.clone()); } } } } pub fn get_sentences( - client: &mut Client, + client: Connection, quiz_settings: Form, ) -> Result, Box> { let mut sentences = Vec::new(); @@ -222,13 +225,14 @@ pub fn get_sentences( } pub fn generate_essay( - client: &mut Client, + client: Connection, quiz_settings: Form, ) -> Vec<[String; 4]> { let mut essay = Vec::new(); let mut sentences = Vec::new(); let mut rng = thread_rng(); + // TODO: use unicode crate for this? let mut known_kanji: HashSet<_> = quiz_settings.known_kanji.chars().collect(); // Read the sentences and shuffle the order let sentence_records = fs::read_to_string("sentences.csv").unwrap(); @@ -317,8 +321,9 @@ CREATE TABLE reports ( ) */ -pub fn save_report(client: &mut Client, report: Form) -> String { +pub async fn save_report(mut db: Connection, report: Form) -> String { // Validate input + // TODO: move validation to struct definition if let Some(suggested) = &report.suggested { if suggested.chars().count() > 500 { return String::from("Suggested value too long"); @@ -329,20 +334,19 @@ pub fn save_report(client: &mut Client, report: Form) -> String { } } // Save the report - client - .execute( + query!( "INSERT INTO reports VALUES (DEFAULT, $1, $2, $3, $4, DEFAULT)", - &[ &report.sentence_id, &report.report_type, - &report.suggested, - &report.comment, - ], + report.suggested.as_ref(), + report.comment.as_ref(), ) - .unwrap(); + .execute(&mut *db).await; + // TODO: use correct return for save_report String::from("success") } +// TODO: use function rather than macro for this macro_rules! add_question_and_translation { ($vector:ident, $queue:ident, $record:ident) => { // We're doing a for loop because the ID could be there multiple times @@ -355,7 +359,7 @@ macro_rules! add_question_and_translation { }; } -pub fn get_admin_stuff(client: &mut Client) -> (Vec, Vec) { +pub async fn get_admin_stuff(mut db: Connection) -> (Vec, Vec) { // Variable to store the reports let mut reports = Vec::new(); // Variable to store the overrides @@ -365,41 +369,20 @@ pub fn get_admin_stuff(client: &mut Client) -> (Vec, Vec("sentence_id").to_string()); - let reported_at: chrono::DateTime = row.get("reported_at"); - reports.push(AdminReport { - report_id: row.get("id"), - sentence_id: row.get("sentence_id"), - question: String::new(), - translation: String::new(), - readings: Vec::new(), - report_type: row.get("report_type"), - suggested: row.get("suggested"), - comment: row.get("comment"), - reported_at: reported_at.to_string(), - }); + ).fetch_all(&mut *db).await.unwrap() { + reports_sentence_ids.push(row.sentence_id.to_string()); + reports.push(row); } // Get the overrides from the database let mut overrides_sentence_ids = Vec::new(); - for row in client.query( + for row in query_as!(AdminOverride, "SELECT * FROM overrides ORDER BY id DESC", - &[] - ).unwrap() { - overrides_sentence_ids.push(row.get::<_, i32>("sentence_id").to_string()); - overrides.push(AdminOverride { - override_id: row.get("id"), - sentence_id: row.get("sentence_id"), - question: String::new(), - translation: String::new(), - reading: String::new(), - override_type: row.get("override_type"), - value: row.get("value"), - primary_value: row.get("primary_value"), - }); + ).fetch_all(&mut *db).await.unwrap() { + overrides_sentence_ids.push(row.sentence_id.to_string()); + overrides.push(row); } // Iterate over the sentences to add the question and translation for result in records.lines() { @@ -413,11 +396,12 @@ pub fn get_admin_stuff(client: &mut Client) -> (Vec, Vec>, only_learnt: bool, @@ -441,7 +425,7 @@ pub fn extract_kanji_from_anki_deck( if contents.len() > 0 { // We now have the sqlite3 database with the notes // Write the database to a file - let mut f = fs::File::create(&file_name).unwrap(); + let mut f = fs::File::create(&file_name).unwrap(); // FIXME: absolutely fucking not f.write_all(&contents).unwrap(); if let Ok(conn) = Connection::open(&file_name) { // Create a variable to store the kanji @@ -511,6 +495,7 @@ pub fn kanji_from_wanikani(api_key: &str) -> Result> { // Create a variable to store the kanji let mut kanji = Vec::new(); // reqwest client to interact with the WaniKani API + // TODO: use async client let client = reqwest::blocking::Client::new(); let mut url = String::from("https://api.wanikani.com/v2/assignments"); let mut ids = Vec::new(); @@ -610,17 +595,19 @@ pub fn kanji_in_order( } } -pub fn delete_from_table(client: &mut Client, table: String, id: i32) -> String { - client.execute(format!("DELETE FROM {} WHERE id = $1", table).as_str(), &[&id]).unwrap(); +// TODO: split function into delete override and delete report +pub async fn delete_from_table(mut db: Connection, table: String, id: i32) -> String { + sqlx::query(&format!("DELETE FROM {} WHERE id = $1", table)).bind(id).execute(&mut *db).await.unwrap(); + // TODO: proper return type String::from("success") } -pub fn add_override(client: &mut Client, override_details: Form) -> String { - let row = client.query_one( +pub async fn add_override(mut db: Connection, override_details: Form) -> String { + let row = query_as!(AdminReport, "SELECT sentence_id FROM reports WHERE id = $1", - &[&override_details.report_id] - ).unwrap(); - let sentence_id: i32 = row.get("sentence_id"); + override_details.report_id + ).fetch_one(&mut *db).await.unwrap(); + let sentence_id: i32 = row.sentence_id; let mut original_question = String::new(); let mut original_translation = String::new(); let mut original_reading = String::new(); @@ -651,61 +638,62 @@ pub fn add_override(client: &mut Client, override_details: Form) -> let mut skip_translation = override_details.translation == original_translation; let mut skip_reading = override_details.reading == original_reading; // Compare with the existing overrides - for row in client.query( + for row in query!( "SELECT override_type, value FROM overrides WHERE sentence_id = $1 AND (primary_value = TRUE OR override_type != 'reading')", - &[&sentence_id] - ).unwrap() { - let override_type: String = row.get("override_type"); + sentence_id + ).fetch_all(&mut *db).await.unwrap() { + // TODO: use match for this + let override_type: String = row.override_type; if override_type == "question" && !skip_question { - skip_question = override_details.question == row.get::<_, String>("value"); + skip_question = override_details.question == row.value; } else if override_type == "translation" && !skip_translation { - skip_translation = override_details.translation == row.get::<_, String>("value"); + skip_translation = override_details.translation == row.value; } else if override_type == "reading" && !skip_reading { - skip_reading = override_details.reading == row.get::<_, String>("value"); + skip_reading = override_details.reading == row.value; } } // Add the overrides let mut something_changed = false; if !skip_question { - client.execute( + query!( "INSERT INTO overrides VALUES (DEFAULT, $1, 'question', $2, FALSE)", - &[&sentence_id, &override_details.question] - ).unwrap(); + sentence_id, override_details.question + ).execute(&mut *db).await.unwrap(); something_changed = true; } if !skip_translation { - client.execute( + query!( "INSERT INTO overrides VALUES (DEFAULT, $1, 'translation', $2, FALSE)", - &[&sentence_id, &override_details.translation] - ).unwrap(); + sentence_id, override_details.translation + ).execute(&mut *db).await.unwrap(); something_changed = true; } if !skip_reading { - client.execute( + query!( "INSERT INTO overrides VALUES (DEFAULT, $1, 'reading', $2, TRUE)", - &[&sentence_id, &override_details.reading] - ).unwrap(); + sentence_id, override_details.reading + ).execute(&mut *db).await.unwrap(); something_changed = true; } if let Some(reading) = override_details.additional_reading.clone() { - client.execute( + query!( "INSERT INTO overrides VALUES (DEFAULT, $1, 'reading', $2, FALSE)", - &[&sentence_id, &reading] - ).unwrap(); + sentence_id, reading + ).execute(&mut *db).await.unwrap(); something_changed = true; } if something_changed { - delete_from_table(client, String::from("reports"), override_details.report_id) + delete_from_table(db, String::from("reports"), override_details.report_id).await } else { String::from("Nothing to override") } } -pub fn edit_override(client: &mut Client, override_details: Form) -> String { - client.execute( +pub async fn edit_override(mut db: Connection, override_details: Form) -> String { + query!( "UPDATE overrides SET value = $1, primary_value = $2 WHERE id = $3", - &[&override_details.value, &override_details.primary_value, &override_details.override_id] - ).unwrap(); + override_details.value, override_details.primary_value, override_details.override_id + ).execute(&mut *db).await.unwrap(); String::from("success") } diff --git a/src/db.rs b/src/db.rs new file mode 100644 index 0000000..5a40cd3 --- /dev/null +++ b/src/db.rs @@ -0,0 +1,32 @@ +use log::error; +use rocket::fairing::AdHoc; +use rocket::{fairing, Build, Rocket}; +use rocket_db_pools::sqlx; +use rocket_db_pools::Database; + +#[derive(Database)] +#[database("fixes")] +pub struct Db(sqlx::PgPool); + +pub type Result> = std::result::Result; + +pub async fn run_migrations(rocket: Rocket) -> fairing::Result { + match Db::fetch(&rocket) { + Some(db) => match sqlx::migrate!().run(&**db).await { + Ok(_) => Ok(rocket), + Err(e) => { + error!("Failed to initialize SQLx database: {}", e); + Err(rocket) + } + }, + None => Err(rocket), + } +} + +pub fn stage() -> AdHoc { + AdHoc::on_ignite("SQLx Stage", |rocket| async { + rocket + .attach(Db::init()) + .attach(AdHoc::try_on_ignite("SQLx Migrations", run_migrations)) + }) +} diff --git a/src/main.rs b/src/main.rs index 2fc3105..4608294 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,32 +1,24 @@ -#![feature(proc_macro_hygiene, decl_macro)] - -#[macro_use] -extern crate rocket; -#[macro_use] -extern crate serde_derive; - -use dotenv::dotenv; use io::Read; use multipart::server::Multipart; -use native_tls::TlsConnector; -use postgres_native_tls::MakeTlsConnector; -use postgres::Client; use rocket::{ - http::{ContentType, Cookies, Cookie, Status}, - request::Form, - response::status::Custom, - Config, Data, State, + fs::relative, + http::{ContentType, CookieJar, Cookie, Status}, + response::status::Custom, Data, FromForm, get, post, + form::Form, serde::json::Json, fs::FileServer, routes, launch, }; -use rocket_contrib::{serve::StaticFiles, templates::Template, json::Json}; +use rocket_db_pools::Connection; +use rocket_dyn_templates::Template; +use serde::Serialize; use argon2::{password_hash::{PasswordHash, PasswordVerifier}, Argon2}; use std::{ collections::HashMap, env, io::{self, Cursor}, - sync::Mutex, }; +use db::Db; mod actions; +mod db; use actions::*; @@ -105,7 +97,7 @@ struct AdminContext { overrides: Vec, } -fn create_context<'a>(cookies: &'a Cookies, page: &'a str) -> HashMap<&'a str, String> { +fn create_context<'a>(cookies: &'a CookieJar, page: &'a str) -> HashMap<&'a str, String> { let mut context = HashMap::new(); context.insert( "theme", @@ -121,44 +113,44 @@ fn create_context<'a>(cookies: &'a Cookies, page: &'a str) -> HashMap<&'a str, S } #[get("/")] -fn get_index(cookies: Cookies) -> Template { +fn get_index(cookies: &CookieJar<'_>) -> Template { Template::render("index", create_context(&cookies, "/")) } #[get("/known_kanji")] -fn get_known_kanji(cookies: Cookies) -> Template { +fn get_known_kanji(cookies: &CookieJar<'_>) -> Template { Template::render("known_kanji", create_context(&cookies, "known_kanji")) } #[get("/quiz")] -fn get_quiz(cookies: Cookies) -> Template { +fn get_quiz(cookies: &CookieJar<'_>) -> Template { Template::render("quiz", create_context(&cookies, "quiz")) } #[get("/essay")] -fn get_essay(cookies: Cookies) -> Template { +fn get_essay(cookies: &CookieJar<'_>) -> Template { Template::render("essay", create_context(&cookies, "essay")) } #[get("/custom_text")] -fn get_custom_text(cookies: Cookies) -> Template { +fn get_custom_text(cookies: &CookieJar<'_>) -> Template { Template::render("custom_text", create_context(&cookies, "custom_text")) } #[get("/offline")] -fn get_offline(cookies: Cookies) -> Template { +fn get_offline(cookies: &CookieJar<'_>) -> Template { Template::render("offline", create_context(&cookies, "offline")) } #[get("/admin")] -fn get_admin(client: State>, mut cookies: Cookies) -> Template { +async fn get_admin(db: Connection, mut cookies: &CookieJar<'_>) -> Template { let mut page = String::from("admin_signin"); if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { page = String::from("admin"); } } - let (reports, overrides) = get_admin_stuff(&mut client.lock().unwrap()); + let (reports, overrides) = get_admin_stuff(db).await; Template::render( page.clone(), AdminContext { @@ -174,8 +166,8 @@ fn get_admin(client: State>, mut cookies: Cookies) -> Template { } #[post("/sentences", data = "")] -fn post_sentences(client: State>, quiz_settings: Form) -> String { - get_sentences(&mut client.lock().unwrap(), quiz_settings) +fn post_sentences(db: Connection, quiz_settings: Form) -> String { + get_sentences(db, quiz_settings) .unwrap() .iter() .map(|x| x.join("~")) @@ -184,8 +176,9 @@ fn post_sentences(client: State>, quiz_settings: Form>, report: Form) -> String { - save_report(&mut client.lock().unwrap(), report) +async fn post_report(db: Connection, report: Form) -> String { + // TODO: inline + save_report(db, report).await } #[post("/import_anki", data = "")] @@ -208,6 +201,7 @@ fn post_import_anki(cont_type: &ContentType, data: Data) -> Result Result) -> Result> { kanji_from_wanikani(&api_key.value) @@ -262,12 +258,13 @@ fn post_import_kanken(import_settings: Form) -> Result>, quiz_settings: Form) -> Json> { - Json(generate_essay(&mut client.lock().unwrap(), quiz_settings)) +fn post_essay(db: Connection, quiz_settings: Form) -> Json> { + // TODO: do this in a separate thread + Json(generate_essay(db, quiz_settings)) } #[post("/admin_signin", data = "")] -fn post_admin_signin(password: Form, mut cookies: Cookies) -> String { +fn post_admin_signin(password: Form, mut cookies: &CookieJar<'_>) -> String { let argon2 = Argon2::default(); let admin_hash = env::var("ADMIN_HASH").unwrap(); let parsed_hash = PasswordHash::new(&admin_hash).unwrap(); @@ -280,69 +277,72 @@ fn post_admin_signin(password: Form, mut cookies: Cookies) -> Strin } #[post("/delete_report", data = "")] -fn post_delete_report(client: State>, report_id: Form, mut cookies: Cookies) -> String { +async fn post_delete_report(db: Connection, report_id: Form, mut cookies: &CookieJar<'_>) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { - return delete_from_table(&mut client.lock().unwrap(), String::from("reports"), report_id.value.parse().unwrap()); + return delete_from_table(db, String::from("reports"), report_id.value.parse().unwrap()).await; } } String::from("Error: not signed in") } #[post("/add_override", data = "")] -fn post_add_override(client: State>, override_details: Form, mut cookies: Cookies) -> String { +async fn post_add_override(db: Connection, override_details: Form, mut cookies: &CookieJar<'_>) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { - return add_override(&mut client.lock().unwrap(), override_details); + return add_override(db, override_details).await; } } String::from("Error: not signed in") } #[post("/delete_override", data = "")] -fn post_delete_override(client: State>, override_id: Form, mut cookies: Cookies) -> String { +async fn post_delete_override(db: Connection, override_id: Form, mut cookies: &CookieJar<'_>) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { - return delete_from_table(&mut client.lock().unwrap(), String::from("overrides"), override_id.value.parse().unwrap()); + return delete_from_table(db, String::from("overrides"), override_id.value.parse().unwrap()).await; } } String::from("Error: not signed in") } #[post("/edit_override", data = "")] -fn post_edit_override(client: State>, override_details: Form, mut cookies: Cookies) -> String { +async fn post_edit_override(db: Connection, override_details: Form, mut cookies: &CookieJar<'_>) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { - return edit_override(&mut client.lock().unwrap(), override_details) + return edit_override(db, override_details).await } } String::from("Error: not signed in") } #[post("/admin_signout")] -fn post_admin_signout(mut cookies: Cookies) -> String { +fn post_admin_signout(mut cookies: &CookieJar<'_>) -> String { cookies.remove_private(Cookie::named("admin_hash")); String::from("success") } -fn configure() -> Config { - let mut config = Config::active().expect("could not load configuration"); - // Add secret key - config - .set_secret_key(env::var("SECRET_KEY").expect("Env var SECRET_KEY not found")) - .expect("Secret key could not be set"); - // Configure Rocket to use the PORT env var or fall back to 8000 - let port = if let Ok(port_str) = env::var("PORT") { - port_str.parse().expect("could not parse PORT") - } else { - 8000 - }; - config.set_port(port); - config -} - -fn rocket() -> rocket::Rocket { - rocket::custom(configure()) +//fn configure() -> Config { +// let mut config = Config::active().expect("could not load configuration"); +// // Add secret key +// config +// .set_secret_key(env::var("SECRET_KEY").expect("Env var SECRET_KEY not found")) +// .expect("Secret key could not be set"); +// // Configure Rocket to use the PORT env var or fall back to 8000 +// let port = if let Ok(port_str) = env::var("PORT") { +// port_str.parse().expect("could not parse PORT") +// } else { +// 8000 +// }; +// config.set_port(port); +// config +//} + +#[launch] +fn rocket() -> _ { + rocket::build() + .attach(db::stage()) + // TODO: configure .mount( "/", routes![ @@ -370,18 +370,10 @@ fn rocket() -> rocket::Rocket { post_edit_override, ], ) - .mount("/styles", StaticFiles::from("static/styles")) - .mount("/scripts", StaticFiles::from("static/scripts")) - .mount("/fonts", StaticFiles::from("static/fonts")) - .mount("/dict", StaticFiles::from("static/dict")) - .mount("/", StaticFiles::from("static/pwa").rank(20)) + .mount("/", FileServer::from(relative!("static")).rank(20)) .attach(Template::fairing()) } -fn main() { - dotenv().ok(); - let connector = MakeTlsConnector::new(TlsConnector::builder().danger_accept_invalid_certs(true).build().unwrap()); - let client = Client::connect(&env::var("DATABASE_URL").unwrap(), connector).unwrap(); - rocket().manage(Mutex::new(client)).launch(); -} +// TODO: use figment for config +// TODO: sqlx client From d3223963c67d8e26ab3067b78c9ef44a1c5c9d01 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Mon, 29 Aug 2022 17:03:40 -0500 Subject: [PATCH 02/17] remove unnecessary deps --- Cargo.lock | 699 ++++++----------------------------------------------- Cargo.toml | 5 +- 2 files changed, 79 insertions(+), 625 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 841fd83..f93c822 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,9 +49,9 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.7", + "getrandom", "once_cell", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -92,12 +92,6 @@ dependencies = [ "password-hash", ] -[[package]] -name = "ascii" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97be891acc47ca214468e09425d02cef3af2c94d0d82081cd02061f996802f14" - [[package]] name = "async-stream" version = "0.3.3" @@ -145,7 +139,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -159,15 +153,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -180,16 +165,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" -[[package]] -name = "base64" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" -dependencies = [ - "byteorder", - "safemem", -] - [[package]] name = "base64" version = "0.13.0" @@ -262,16 +237,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "buf_redux" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" -dependencies = [ - "memchr", - "safemem", -] - [[package]] name = "bumpalo" version = "3.10.0" @@ -337,7 +302,7 @@ checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde" dependencies = [ "chrono", "chrono-tz-build", - "phf 0.11.1", + "phf", ] [[package]] @@ -347,16 +312,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c" dependencies = [ "parse-zoneinfo", - "phf 0.11.1", - "phf_codegen 0.11.1", + "phf", + "phf_codegen", ] -[[package]] -name = "chunked_transfer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "498d20a7aaf62625b9bf26e637cf7736417cde1d0c99f1d04d1170229a85cf87" - [[package]] name = "cipher" version = "0.3.0" @@ -366,15 +325,6 @@ dependencies = [ "generic-array 0.14.5", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "const_fn" version = "0.4.9" @@ -388,15 +338,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94d4706de1b0fa5b132270cddffa8585166037822e260a944fe161acd137ca05" dependencies = [ "aes-gcm", - "base64 0.13.0", + "base64", "hkdf", "hmac", - "percent-encoding 2.1.0", - "rand 0.8.5", + "percent-encoding", + "rand", "sha2", "subtle", "time 0.3.14", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -625,7 +575,7 @@ dependencies = [ "serde", "toml", "uncased", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -690,7 +640,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ "matches", - "percent-encoding 2.1.0", + "percent-encoding", ] [[package]] @@ -712,12 +662,6 @@ dependencies = [ "libc", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -829,7 +773,7 @@ checksum = "cc184cace1cea8335047a471cc1da80f18acf8a76f3bab2028d499e328948ec7" dependencies = [ "cc", "libc", - "log 0.4.17", + "log", "rustversion", "windows", ] @@ -850,18 +794,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ "typenum", - "version_check 0.9.4", -] - -[[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", + "version_check", ] [[package]] @@ -900,7 +833,7 @@ dependencies = [ "aho-corasick", "bstr", "fnv", - "log 0.4.17", + "log", "regex", ] @@ -915,12 +848,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "groupable" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32619942b8be646939eaf3db0602b39f5229b74575b67efc897811ded1db4e57" - [[package]] name = "h2" version = "0.3.13" @@ -1046,25 +973,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" -[[package]] -name = "hyper" -version = "0.10.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" -dependencies = [ - "base64 0.9.3", - "httparse", - "language-tags", - "log 0.3.9", - "mime 0.2.6", - "num_cpus", - "time 0.1.44", - "traitobject", - "typeable", - "unicase 1.4.2", - "url 1.7.2", -] - [[package]] name = "hyper" version = "0.14.20" @@ -1096,7 +1004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper 0.14.20", + "hyper", "native-tls", "tokio", "tokio-native-tls", @@ -1115,17 +1023,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "idna" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.2.3" @@ -1146,7 +1043,7 @@ dependencies = [ "crossbeam-utils", "globset", "lazy_static", - "log 0.4.17", + "log", "memchr", "regex", "same-file", @@ -1161,7 +1058,7 @@ version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown 0.12.2", "serde", ] @@ -1216,22 +1113,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" -[[package]] -name = "iron" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6d308ca2d884650a8bf9ed2ff4cb13fbb2207b71f64cda11dc9b892067295e8" -dependencies = [ - "hyper 0.10.16", - "log 0.3.9", - "mime_guess 1.8.8", - "modifier", - "num_cpus", - "plugin", - "typemap", - "url 1.7.2", -] - [[package]] name = "itertools" version = "0.10.3" @@ -1266,12 +1147,6 @@ dependencies = [ "winapi-build", ] -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" - [[package]] name = "lazy_static" version = "1.4.0" @@ -1307,19 +1182,10 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -dependencies = [ - "log 0.4.17", -] - [[package]] name = "log" version = "0.4.17" @@ -1380,43 +1246,12 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "mime" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -dependencies = [ - "log 0.3.9", -] - [[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "mime_guess" -version = "1.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216929a5ee4dd316b1702eedf5e74548c123d370f47841ceaac38ca154690ca3" -dependencies = [ - "mime 0.2.6", - "phf 0.7.24", - "phf_codegen 0.7.24", - "unicase 1.4.2", -] - -[[package]] -name = "mime_guess" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" -dependencies = [ - "mime 0.3.16", - "unicase 2.6.0", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1444,7 +1279,7 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log 0.4.17", + "log", "miow", "net2", "slab", @@ -1458,7 +1293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ "libc", - "log 0.4.17", + "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys", ] @@ -1470,7 +1305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", - "log 0.4.17", + "log", "mio 0.6.23", "slab", ] @@ -1487,12 +1322,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "modifier" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" - [[package]] name = "multer" version = "2.0.3" @@ -1504,45 +1333,13 @@ dependencies = [ "futures-util", "http", "httparse", - "log 0.4.17", + "log", "memchr", - "mime 0.3.16", + "mime", "spin 0.9.4", "tokio", "tokio-util", - "version_check 0.9.4", -] - -[[package]] -name = "multipart" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" -dependencies = [ - "buf_redux", - "httparse", - "hyper 0.10.16", - "iron", - "log 0.4.17", - "mime 0.3.16", - "mime_guess 2.0.4", - "nickel", - "quick-error", - "rand 0.7.3", - "safemem", - "tempfile", - "tiny_http", - "twoway", -] - -[[package]] -name = "mustache" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51956ef1c5d20a1384524d91e616fb44dfc7d8f249bf696d49c97dd3289ecab5" -dependencies = [ - "log 0.3.9", - "serde", + "version_check", ] [[package]] @@ -1553,7 +1350,7 @@ checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" dependencies = [ "lazy_static", "libc", - "log 0.4.17", + "log", "openssl", "openssl-probe", "openssl-sys", @@ -1574,27 +1371,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "nickel" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5061a832728db2dacb61cefe0ce303b58f85764ec680e71d9138229640a46d9" -dependencies = [ - "groupable", - "hyper 0.10.16", - "lazy_static", - "log 0.3.9", - "modifier", - "mustache", - "plugin", - "regex", - "serde", - "serde_json", - "time 0.1.44", - "typemap", - "url 1.7.2", -] - [[package]] name = "nom" version = "7.1.1" @@ -1638,7 +1414,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -1648,7 +1424,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -1726,7 +1502,7 @@ version = "0.9.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cc", "libc", "pkg-config", @@ -1797,7 +1573,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d791538a6dcc1e7cb7fe6f6b58aca40e7f79403c45b2bc274008b5e647af1d8" dependencies = [ "base64ct", - "rand_core 0.6.3", + "rand_core", "subtle", ] @@ -1830,12 +1606,6 @@ dependencies = [ "syn", ] -[[package]] -name = "percent-encoding" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" - [[package]] name = "percent-encoding" version = "2.1.0" @@ -1885,32 +1655,13 @@ dependencies = [ "sha-1 0.8.2", ] -[[package]] -name = "phf" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" -dependencies = [ - "phf_shared 0.7.24", -] - [[package]] name = "phf" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" dependencies = [ - "phf_shared 0.11.1", -] - -[[package]] -name = "phf_codegen" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" -dependencies = [ - "phf_generator 0.7.24", - "phf_shared 0.7.24", + "phf_shared", ] [[package]] @@ -1919,18 +1670,8 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770" dependencies = [ - "phf_generator 0.11.1", - "phf_shared 0.11.1", -] - -[[package]] -name = "phf_generator" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" -dependencies = [ - "phf_shared 0.7.24", - "rand 0.6.5", + "phf_generator", + "phf_shared", ] [[package]] @@ -1939,18 +1680,8 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" dependencies = [ - "phf_shared 0.11.1", - "rand 0.8.5", -] - -[[package]] -name = "phf_shared" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" -dependencies = [ - "siphasher 0.2.3", - "unicase 1.4.2", + "phf_shared", + "rand", ] [[package]] @@ -1959,7 +1690,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" dependencies = [ - "siphasher 0.3.10", + "siphasher", "uncased", ] @@ -2001,15 +1732,6 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" -[[package]] -name = "plugin" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" -dependencies = [ - "typemap", -] - [[package]] name = "polyval" version = "0.5.3" @@ -2052,16 +1774,10 @@ dependencies = [ "proc-macro2", "quote", "syn", - "version_check 0.9.4", + "version_check", "yansi", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.20" @@ -2071,38 +1787,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.9", -] - -[[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 0.2.0", -] - [[package]] name = "rand" version = "0.8.5" @@ -2110,28 +1794,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - -[[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", + "rand_chacha", + "rand_core", ] [[package]] @@ -2141,31 +1805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[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", + "rand_core", ] [[package]] @@ -2174,87 +1814,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.7", -] - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - -[[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 = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.9", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", + "getrandom", ] [[package]] @@ -2272,7 +1832,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.7", + "getrandom", "redox_syscall", "thiserror", ] @@ -2338,7 +1898,7 @@ version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" dependencies = [ - "base64 0.13.0", + "base64", "bytes", "encoding_rs", "futures-core", @@ -2346,15 +1906,15 @@ dependencies = [ "h2", "http", "http-body", - "hyper 0.14.20", + "hyper", "hyper-tls", "ipnet", "js-sys", "lazy_static", - "log 0.4.17", - "mime 0.3.16", + "log", + "mime", "native-tls", - "percent-encoding 2.1.0", + "percent-encoding", "pin-project-lite", "serde", "serde_json", @@ -2362,7 +1922,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tower-service", - "url 2.2.2", + "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -2400,13 +1960,13 @@ dependencies = [ "figment", "futures", "indexmap", - "log 0.4.17", + "log", "memchr", "multer", "num_cpus", "parking_lot 0.12.1", "pin-project-lite", - "rand 0.8.5", + "rand", "ref-cast", "rocket_codegen", "rocket_http", @@ -2419,7 +1979,7 @@ dependencies = [ "tokio-stream", "tokio-util", "ubyte", - "version_check 0.9.4", + "version_check", "yansi", ] @@ -2448,7 +2008,7 @@ dependencies = [ "rocket", "rocket_db_pools_codegen", "sqlx", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -2484,12 +2044,12 @@ dependencies = [ "either", "futures", "http", - "hyper 0.14.20", + "hyper", "indexmap", - "log 0.4.17", + "log", "memchr", "pear", - "percent-encoding 2.1.0", + "percent-encoding", "pin-project-lite", "ref-cast", "serde", @@ -2516,8 +2076,8 @@ version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64 0.13.0", - "log 0.4.17", + "base64", + "log", "ring", "sct", "webpki", @@ -2535,23 +2095,15 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" -[[package]] -name = "safemem" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" - [[package]] name = "sakubun" version = "0.1.0" dependencies = [ "argon2", "chrono", - "dotenv", - "log 0.4.17", - "multipart", + "log", "native-tls", - "rand 0.8.5", + "rand", "regex", "reqwest", "rocket", @@ -2753,12 +2305,6 @@ dependencies = [ "libc", ] -[[package]] -name = "siphasher" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" - [[package]] name = "siphasher" version = "0.3.10" @@ -2840,7 +2386,7 @@ checksum = "e48c61941ccf5ddcada342cd59e3e5173b007c509e1e8e990dafc830294d9dc5" dependencies = [ "ahash", "atoi", - "base64 0.13.0", + "base64", "bitflags", "byteorder", "bytes", @@ -2863,13 +2409,13 @@ dependencies = [ "itoa", "libc", "libsqlite3-sys", - "log 0.4.17", + "log", "md-5", "memchr", "once_cell", "paste", - "percent-encoding 2.1.0", - "rand 0.8.5", + "percent-encoding", + "rand", "rustls", "serde", "serde_json", @@ -2882,7 +2428,7 @@ dependencies = [ "thiserror", "time 0.2.27", "tokio-stream", - "url 2.2.2", + "url", "webpki", "webpki-roots", "whoami", @@ -2904,7 +2450,7 @@ dependencies = [ "sqlx-core", "sqlx-rt", "syn", - "url 2.2.2", + "url", ] [[package]] @@ -2933,7 +2479,7 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" dependencies = [ - "version_check 0.9.4", + "version_check", ] [[package]] @@ -3046,10 +2592,10 @@ dependencies = [ "globwalk", "humansize", "lazy_static", - "percent-encoding 2.1.0", + "percent-encoding", "pest", "pest_derive", - "rand 0.8.5", + "rand", "regex", "serde", "serde_json", @@ -3108,7 +2654,7 @@ dependencies = [ "standback", "stdweb", "time-macros 0.1.1", - "version_check 0.9.4", + "version_check", "winapi 0.3.9", ] @@ -3153,19 +2699,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tiny_http" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e22cb179b63e5fc2d0b5be237dc107da072e2407809ac70a8ce85b93fe8f562" -dependencies = [ - "ascii", - "chrono", - "chunked_transfer", - "log 0.4.17", - "url 1.7.2", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -3312,7 +2845,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" dependencies = [ "lazy_static", - "log 0.4.17", + "log", "tracing-core", ] @@ -3334,42 +2867,12 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "traitobject" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" - [[package]] name = "try-lock" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "twoway" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" -dependencies = [ - "memchr", -] - -[[package]] -name = "typeable" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" - -[[package]] -name = "typemap" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" -dependencies = [ - "unsafe-any", -] - [[package]] name = "typenum" version = "1.15.0" @@ -3398,7 +2901,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" dependencies = [ "serde", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -3451,24 +2954,6 @@ dependencies = [ "unic-common", ] -[[package]] -name = "unicase" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" -dependencies = [ - "version_check 0.1.5", -] - -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check 0.9.4", -] - [[package]] name = "unicode-bidi" version = "0.3.8" @@ -3518,32 +3003,12 @@ dependencies = [ "subtle", ] -[[package]] -name = "unsafe-any" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" -dependencies = [ - "traitobject", -] - [[package]] name = "untrusted" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" -[[package]] -name = "url" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -dependencies = [ - "idna 0.1.5", - "matches", - "percent-encoding 1.0.1", -] - [[package]] name = "url" version = "2.2.2" @@ -3551,9 +3016,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", - "idna 0.2.3", + "idna", "matches", - "percent-encoding 2.1.0", + "percent-encoding", ] [[package]] @@ -3562,7 +3027,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.7", + "getrandom", ] [[package]] @@ -3577,12 +3042,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" - [[package]] name = "version_check" version = "0.9.4" @@ -3606,16 +3065,10 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log 0.4.17", + "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" @@ -3646,7 +3099,7 @@ checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" dependencies = [ "bumpalo", "lazy_static", - "log 0.4.17", + "log", "proc-macro2", "quote", "syn", diff --git a/Cargo.toml b/Cargo.toml index b4ae2ce..335dc0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,9 @@ authors = ["aravk "] edition = "2021" [dependencies] -dotenv = "0.15" regex = "1.4" argon2 = "0.3" rand = "0.8.3" -multipart = "0.17.1" zip = { version = "0.5.9", default-features = false, features = ["deflate"] } native-tls = "0.2.7" chrono = "0.4" @@ -22,3 +20,6 @@ rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] } sqlx = { version = "0.5", features = ["postgres", "sqlite", "tls", "migrate", "macros", "time"] } rocket_db_pools = { version = "0.1.0-rc.2", features = ["sqlx_postgres", "sqlx_sqlite"] } log = "0.4" + +[profile.dev.package.sqlx-macros] +opt-level = 3 From b1327e1c89574608e6ba597475420154030337b9 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Mon, 29 Aug 2022 18:42:53 -0500 Subject: [PATCH 03/17] add default config --- Rocket.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Rocket.toml b/Rocket.toml index 58fd27c..4c53c8b 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -1,2 +1,9 @@ +[debug] +port = "8000" +secret_key = "dev key" + +[default.limits] +file = "4 MiB" + [default.databases.fixes] url = "host=localhost port=5432 dbname=sakubun connect_timeout=10" From a35adff5b174c333cc71da118363422e75186c38 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Mon, 29 Aug 2022 18:54:27 -0500 Subject: [PATCH 04/17] port anki import to rocket 0.5 --- src/actions.rs | 173 ++++++++++++++++++++++++++----------------------- src/main.rs | 94 ++++++++++----------------- 2 files changed, 125 insertions(+), 142 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index b5a35d0..de35738 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,16 +1,19 @@ -use sqlx::{Executor, query, query_as}; use crate::db::Db; +use sqlx::{query, query_as, Connection as _, Row, SqliteConnection}; -use super::{AdminReport, AdminOverride, OrderedImport, QuizSettings, Report, AddOverride, EditOverride}; +use super::{ + AddOverride, AdminOverride, AdminReport, EditOverride, OrderedImport, QuizSettings, Report, +}; use rand::prelude::*; use regex::Regex; -use rocket::{http::Status, form::Form, response::status::Custom}; +use rocket::{form::Form, http::Status, response::status::Custom}; use rocket_db_pools::Connection; use std::{ collections::{HashMap, HashSet}, error::Error, - fs, - io::{Cursor, Read, Write}, + fs::{self, File}, + io::{Read, Write}, + path::Path, }; use uuid::Uuid; @@ -401,94 +404,100 @@ pub async fn get_admin_stuff(mut db: Connection) -> (Vec, Vec>, +// TODO: error handling +pub async fn extract_kanji_from_anki_deck( + data: impl AsRef, only_learnt: bool, ) -> Result> { // An apkg file is just a zip file, so unzip it - if let Ok(mut zip) = zip::ZipArchive::new(data) { - // Randomly generated filename to temporarily save the database at - let file_name = format!("{}.db", Uuid::new_v4()); - let mut contents = Vec::new(); - // Get the database file - if let Ok(mut file) = zip.by_name("collection.anki21") { - // This deck uses the Anki 2.1 scheduler + let data = File::open(data.as_ref()).unwrap(); + let mut zip = zip::ZipArchive::new(data).map_err(|_| { + Custom( + Status::InternalServerError, + String::from("Failed to parse apkg file"), + ) + })?; + // Randomly generated filename to temporarily save the database at + let file_name = format!("{}.db", Uuid::new_v4()); + let mut contents = Vec::new(); + // Get the database file + if let Ok(mut file) = zip.by_name("collection.anki21") { + // This deck uses the Anki 2.1 scheduler + file.read_to_end(&mut contents).unwrap(); + } + if contents.len() == 0 { + if let Ok(mut file) = zip.by_name("collection.anki2") { + // This deck doesn't use the Anki 2.1 scheduler file.read_to_end(&mut contents).unwrap(); } - if contents.len() == 0 { - if let Ok(mut file) = zip.by_name("collection.anki2") { - // This deck doesn't use the Anki 2.1 scheduler - file.read_to_end(&mut contents).unwrap(); - } - } - if contents.len() > 0 { - // We now have the sqlite3 database with the notes - // Write the database to a file - let mut f = fs::File::create(&file_name).unwrap(); // FIXME: absolutely fucking not - f.write_all(&contents).unwrap(); - if let Ok(conn) = Connection::open(&file_name) { - // Create a variable to store the kanji - let mut kanji: HashSet = HashSet::new(); - // Regex to find kanji - let kanji_regex = Regex::new(r"[\p{Han}]").unwrap(); - /* - * In most decks I checked the kanji was in the sort field (sfld) column, but some - * decks have numbers there, and the kanji is in the fields (flds) column. In this - * case it's more complicated because there can be multiple fields and the kanji - * could be in any one of those fields. So we take the sfld column if it has kanji, - * otherwise as a secondary option we take the flds column. - * - * The queue column in the cards table tells us if the card is already learnt, is - * being learnt, or has never been seen before. if the only_learnt parameter is - * true, we should only consider cards that are in queue 2 (learnt). - * - * Despite the DISTINCT clause, it is still necessary to filter duplicates because - * different notes of the same kanji could be in different queues. - */ - let mut statement = conn - .prepare( - "SELECT DISTINCT cards.queue, notes.sfld, notes.flds + } + if contents.len() > 0 { + // We now have the sqlite3 database with the notes + // Write the database to a file + let mut f = fs::File::create(&file_name).unwrap(); // FIXME: absolutely fucking not + f.write_all(&contents).unwrap(); + let mut conn = SqliteConnection::connect(&file_name).await.unwrap(); + // Create a variable to store the kanji + let mut kanji: HashSet = HashSet::new(); + // Regex to find kanji + let kanji_regex = Regex::new(r"[\p{Han}]").unwrap(); + /* + * In most decks I checked the kanji was in the sort field (sfld) column, but + * some decks have numbers there, and the kanji is in the fields + * (flds) column. In this case it's more complicated because there + * can be multiple fields and the kanji could be in any one of those + * fields. So we take the sfld column if it has kanji, otherwise as a + * secondary option we take the flds column. + * + * The queue column in the cards table tells us if the card is already + * learnt, is being learnt, or has never been seen before. if the + * only_learnt parameter is true, we should only consider cards that + * are in queue 2 (learnt). + * + * Despite the DISTINCT clause, it is still necessary to filter duplicates + * because different notes of the same kanji could be in different + * queues. + */ + + let rows = query( + "SELECT DISTINCT cards.queue, notes.sfld, notes.flds FROM cards INNER JOIN notes on notes.id = cards.nid", - ) - .unwrap(); - let mut rows = statement.query(NO_PARAMS).unwrap(); - while let Some(row) = rows.next().unwrap() { - if !only_learnt || row.get::<_, i32>(0).unwrap() == 2 { - let mut no_kanji_found = true; - // Check for string type because it could also be integer - if let Ok(sfld) = row.get::<_, String>(1) { - // Insert all kanji found in the sfld column to the kanji set - for capture in kanji_regex.captures_iter(&sfld) { - kanji.insert(capture[0].to_string()); - no_kanji_found = false; - } - } - // If no kanji were found in the sfld column - if no_kanji_found { - let flds: String = row.get(2).unwrap(); - // Insert all kanji found in the flds column to the kanji set - for capture in kanji_regex.captures_iter(&flds) { - kanji.insert(capture[0].to_string()); - } - } + ) + .fetch_all(&mut conn) + .await + .unwrap(); + for row in rows { + if !only_learnt || row.try_get::(0).unwrap() == 2 { + let mut no_kanji_found = true; + // Check for string type because it could also be integer + if let Ok(sfld) = row.try_get::(1) { + // Insert all kanji found in the sfld column to the kanji set + for capture in kanji_regex.captures_iter(&sfld) { + kanji.insert(capture[0].to_string()); + no_kanji_found = false; + } + } + // If no kanji were found in the sfld column + if no_kanji_found { + let flds: String = row.try_get(2).unwrap(); + // Insert all kanji found in the flds column to the kanji set + for capture in kanji_regex.captures_iter(&flds) { + kanji.insert(capture[0].to_string()); } } - // Delete the database file - fs::remove_file(&file_name).unwrap(); - // Return all the extracted kanji - return Ok(kanji - .iter() - .map(|k| k.as_str()) - .collect::>() - .join("")); } } + // Delete the database file + fs::remove_file(&file_name).unwrap(); + // Return all the extracted kanji + return Ok(kanji + .iter() + .map(|k| k.as_str()) + .collect::>() + .join("")); + } else { + panic!("anki db empty") } - Err(Custom( - Status::InternalServerError, - String::from("Failed to parse apkg file"), - )) } pub fn kanji_from_wanikani(api_key: &str) -> Result> { diff --git a/src/main.rs b/src/main.rs index 4608294..00f1a59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,25 @@ -use io::Read; -use multipart::server::Multipart; +use argon2::{ + password_hash::{PasswordHash, PasswordVerifier}, + Argon2, +}; +use db::Db; use rocket::{ - fs::relative, - http::{ContentType, CookieJar, Cookie, Status}, - response::status::Custom, Data, FromForm, get, post, - form::Form, serde::json::Json, fs::FileServer, routes, launch, + form::Form, + fs::{relative, FileServer, TempFile}, + get, + http::{ContentType, Cookie, CookieJar}, + launch, post, + response::status::Custom, + routes, + serde::json::Json, + tokio::fs, + FromForm, fairing::AdHoc, }; use rocket_db_pools::Connection; use rocket_dyn_templates::Template; use serde::Serialize; -use argon2::{password_hash::{PasswordHash, PasswordVerifier}, Argon2}; -use std::{ - collections::HashMap, - env, - io::{self, Cursor}, -}; -use db::Db; +use std::{collections::HashMap, env}; +use uuid::Uuid; mod actions; mod db; @@ -48,6 +52,13 @@ pub struct OrderedImport { method: String, } +#[derive(FromForm)] +pub struct AnkiImport<'f> { + only_learnt: bool, + #[field(validate = ext(ContentType::ZIP))] + file: TempFile<'f>, +} + #[derive(FromForm)] pub struct AddOverride { report_id: i32, @@ -181,53 +192,16 @@ async fn post_report(db: Connection, report: Form) -> String { save_report(db, report).await } -#[post("/import_anki", data = "")] -fn post_import_anki(cont_type: &ContentType, data: Data) -> Result> { - // Validate data - if !cont_type.is_form_data() { - return Err(Custom( - Status::BadRequest, - "Content-Type not multipart/form-data".into(), - )); - } - - let (_, boundary) = cont_type - .params() - .find(|&(k, _)| k == "boundary") - .ok_or_else(|| { - Custom( - Status::BadRequest, - "`Content-Type: multipart/form-data` boundary param not provided".into(), - ) - })?; - - // TODO: fix form handling - // Read data - let mut only_learnt = String::new(); - let mut buf = Vec::new(); - let mut form_data = Multipart::with_body(data.open(), boundary); - form_data - .read_entry() - .unwrap() - .unwrap() - .data - .read_to_string(&mut only_learnt) - .unwrap(); - form_data - .read_entry() - .unwrap() - .unwrap() - .data - .read_to_end(&mut buf) - .unwrap(); - // The maximum allowed file size is 4 MiB - if buf.len() > 4194304 { - return Err(Custom( - Status::PayloadTooLarge, - String::from("File too large"), - )); - } - extract_kanji_from_anki_deck(Cursor::new(buf), only_learnt == "true") +#[post("/import_anki", data = "")] +async fn post_import_anki( + cont_type: &ContentType, + mut import_settings: Form>, +) -> Result> { + let path = Uuid::new_v4().to_string(); + import_settings.file.persist_to(&path).await.unwrap(); + extract_kanji_from_anki_deck(&path, import_settings.only_learnt); + fs::remove_file(path).await; + Ok("success".to_owned()) } // TODO: unify into heirarchical api From 7a604313ddc8835082fab39cb6421a9db3ad862a Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Mon, 29 Aug 2022 18:55:34 -0500 Subject: [PATCH 05/17] fmt and fix imports --- build.rs | 2 +- src/actions.rs | 137 +++++++++++++++++++++++++++++++++---------------- src/db.rs | 6 +-- src/main.rs | 74 +++++++++++++++----------- 4 files changed, 140 insertions(+), 79 deletions(-) diff --git a/build.rs b/build.rs index 7609593..d506869 100644 --- a/build.rs +++ b/build.rs @@ -2,4 +2,4 @@ fn main() { // trigger recompilation when a new migration is added println!("cargo:rerun-if-changed=migrations"); -} \ No newline at end of file +} diff --git a/src/actions.rs b/src/actions.rs index de35738..6246c87 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -65,7 +65,8 @@ impl Sentence for [String; 4] { } } -// (Sentence ID, Japanese sentence, English sentence, Reading, Kanji in sentence, Previous intersection) +// (Sentence ID, Japanese sentence, English sentence, Reading, Kanji in +// sentence, Previous intersection) impl Sentence for (String, String, String, String, HashSet, Option) { fn get_id(&self) -> i32 { self.0.parse().unwrap() @@ -126,7 +127,11 @@ impl Sentence for AdminOverride { } } -async fn fill_sentences(mut db: Connection, sentences: &mut Vec, add_overrides: bool) { +async fn fill_sentences( + mut db: Connection, + sentences: &mut Vec, + add_overrides: bool, +) { let mut queue: HashMap> = HashMap::new(); for (i, sentence) in sentences.iter().enumerate() { if queue.contains_key(&sentence.get_id()) { @@ -157,19 +162,19 @@ async fn fill_sentences(mut db: Connection, sentences: &mut Vec // Add the overrides let sentence_ids = queue.keys().copied().collect::>(); - for row in - query!( - "SELECT * FROM overrides WHERE sentence_id = ANY($1) ORDER BY primary_value DESC", - &sentence_ids - ) - .fetch_all(&mut *db) - .await.unwrap() + for row in query!( + "SELECT * FROM overrides WHERE sentence_id = ANY($1) ORDER BY primary_value DESC", + &sentence_ids + ) + .fetch_all(&mut *db) + .await + .unwrap() { let indices = queue.get(&row.sentence_id).unwrap(); // The concept of a primary value exists only for readings if row.override_type != "reading" || row.primary_value { - // This is either a primary reading or a non-reading override, so we can just set that - // property to the new value + // This is either a primary reading or a non-reading override, so we can just + // set that property to the new value for i in indices { sentences[*i].set(&row.override_type, row.value.clone()); } @@ -241,7 +246,8 @@ pub fn generate_essay( let sentence_records = fs::read_to_string("sentences.csv").unwrap(); let sentence_records: Vec<_> = sentence_records.lines().collect(); - // Filter the sentences so we're left with the ones that only have kanji the user knows + // Filter the sentences so we're left with the ones that only have kanji the + // user knows for result in sentence_records { // Parse the values let record: Vec<_> = result.split('\t').collect(); @@ -288,7 +294,8 @@ pub fn generate_essay( if intersection < max_intersection || intersection == 0 { continue; } else if intersection > max_intersection { - // If the current intersection is greater than the last recorded max intersection + // If the current intersection is greater than the last recorded max + // intersection max_intersection = intersection; // Reset the pairs vector tuples = Vec::new(); @@ -303,7 +310,12 @@ pub fn generate_essay( // Add a random sentence with a lot of known kanji to the essay let choice = tuples.choose(&mut rng).unwrap(); - essay.push([choice.0.to_owned(), choice.1.to_owned(), choice.2.to_owned(), choice.3.to_owned()]); + essay.push([ + choice.0.to_owned(), + choice.1.to_owned(), + choice.2.to_owned(), + choice.3.to_owned(), + ]); known_kanji = known_kanji.difference(&choice.4).map(|x| *x).collect(); } @@ -337,14 +349,15 @@ pub async fn save_report(mut db: Connection, report: Form) -> String } } // Save the report - query!( - "INSERT INTO reports VALUES (DEFAULT, $1, $2, $3, $4, DEFAULT)", - &report.sentence_id, - &report.report_type, - report.suggested.as_ref(), - report.comment.as_ref(), - ) - .execute(&mut *db).await; + query!( + "INSERT INTO reports VALUES (DEFAULT, $1, $2, $3, $4, DEFAULT)", + &report.sentence_id, + &report.report_type, + report.suggested.as_ref(), + report.comment.as_ref(), + ) + .execute(&mut *db) + .await; // TODO: use correct return for save_report String::from("success") } @@ -369,21 +382,26 @@ pub async fn get_admin_stuff(mut db: Connection) -> (Vec, Vec, table: String, id: i32) -> String { - sqlx::query(&format!("DELETE FROM {} WHERE id = $1", table)).bind(id).execute(&mut *db).await.unwrap(); + sqlx::query(&format!("DELETE FROM {} WHERE id = $1", table)) + .bind(id) + .execute(&mut *db) + .await + .unwrap(); // TODO: proper return type String::from("success") } pub async fn add_override(mut db: Connection, override_details: Form) -> String { - let row = query_as!(AdminReport, + let row = query_as!( + AdminReport, "SELECT sentence_id FROM reports WHERE id = $1", override_details.report_id - ).fetch_one(&mut *db).await.unwrap(); + ) + .fetch_one(&mut *db) + .await + .unwrap(); let sentence_id: i32 = row.sentence_id; let mut original_question = String::new(); let mut original_translation = String::new(); @@ -651,7 +677,11 @@ pub async fn add_override(mut db: Connection, override_details: Form, override_details: Form, override_details: Form, override_details: Form) -> String { query!( "UPDATE overrides SET value = $1, primary_value = $2 WHERE id = $3", - override_details.value, override_details.primary_value, override_details.override_id - ).execute(&mut *db).await.unwrap(); + override_details.value, + override_details.primary_value, + override_details.override_id + ) + .execute(&mut *db) + .await + .unwrap(); String::from("success") } diff --git a/src/db.rs b/src/db.rs index 5a40cd3..64d6fc1 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,8 +1,6 @@ use log::error; -use rocket::fairing::AdHoc; -use rocket::{fairing, Build, Rocket}; -use rocket_db_pools::sqlx; -use rocket_db_pools::Database; +use rocket::{fairing, fairing::AdHoc, Build, Rocket}; +use rocket_db_pools::{sqlx, Database}; #[derive(Database)] #[database("fixes")] diff --git a/src/main.rs b/src/main.rs index 00f1a59..d89e74f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use argon2::{ }; use db::Db; use rocket::{ + fairing::AdHoc, form::Form, fs::{relative, FileServer, TempFile}, get, @@ -13,7 +14,7 @@ use rocket::{ routes, serde::json::Json, tokio::fs, - FromForm, fairing::AdHoc, + FromForm, }; use rocket_db_pools::Connection; use rocket_dyn_templates::Template; @@ -37,7 +38,10 @@ pub struct QuizSettings { pub struct Report { sentence_id: i32, report_type: String, + // also uses bytes because 500 is db limit + #[field(validate = len(..=500))] suggested: Option, + #[field(validate = len(..=500))] comment: Option, } @@ -154,7 +158,7 @@ fn get_offline(cookies: &CookieJar<'_>) -> Template { } #[get("/admin")] -async fn get_admin(db: Connection, mut cookies: &CookieJar<'_>) -> Template { +async fn get_admin(db: Connection, cookies: &CookieJar<'_>) -> Template { let mut page = String::from("admin_signin"); if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { @@ -242,7 +246,10 @@ fn post_admin_signin(password: Form, mut cookies: &CookieJar<'_>) - let argon2 = Argon2::default(); let admin_hash = env::var("ADMIN_HASH").unwrap(); let parsed_hash = PasswordHash::new(&admin_hash).unwrap(); - if argon2.verify_password(password.value.as_bytes(), &parsed_hash).is_ok() { + if argon2 + .verify_password(password.value.as_bytes(), &parsed_hash) + .is_ok() + { cookies.add_private(Cookie::new("admin_hash", admin_hash)); String::from("success") } else { @@ -251,17 +258,30 @@ fn post_admin_signin(password: Form, mut cookies: &CookieJar<'_>) - } #[post("/delete_report", data = "")] -async fn post_delete_report(db: Connection, report_id: Form, mut cookies: &CookieJar<'_>) -> String { +async fn post_delete_report( + db: Connection, + report_id: Form, + cookies: &CookieJar<'_>, +) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { - return delete_from_table(db, String::from("reports"), report_id.value.parse().unwrap()).await; + return delete_from_table( + db, + String::from("reports"), + report_id.value.parse().unwrap(), + ) + .await; } } String::from("Error: not signed in") } #[post("/add_override", data = "")] -async fn post_add_override(db: Connection, override_details: Form, mut cookies: &CookieJar<'_>) -> String { +async fn post_add_override( + db: Connection, + override_details: Form, + cookies: &CookieJar<'_>, +) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { return add_override(db, override_details).await; @@ -271,20 +291,33 @@ async fn post_add_override(db: Connection, override_details: Form, override_id: Form, mut cookies: &CookieJar<'_>) -> String { +async fn post_delete_override( + db: Connection, + override_id: Form, + cookies: &CookieJar<'_>, +) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { - return delete_from_table(db, String::from("overrides"), override_id.value.parse().unwrap()).await; + return delete_from_table( + db, + String::from("overrides"), + override_id.value.parse().unwrap(), + ) + .await; } } String::from("Error: not signed in") } #[post("/edit_override", data = "")] -async fn post_edit_override(db: Connection, override_details: Form, mut cookies: &CookieJar<'_>) -> String { +async fn post_edit_override( + db: Connection, + override_details: Form, + cookies: &CookieJar<'_>, +) -> String { if let Some(hash) = cookies.get_private("admin_hash") { if hash.value() == env::var("ADMIN_HASH").unwrap() { - return edit_override(db, override_details).await + return edit_override(db, override_details).await; } } String::from("Error: not signed in") @@ -296,27 +329,10 @@ fn post_admin_signout(mut cookies: &CookieJar<'_>) -> String { String::from("success") } -//fn configure() -> Config { -// let mut config = Config::active().expect("could not load configuration"); -// // Add secret key -// config -// .set_secret_key(env::var("SECRET_KEY").expect("Env var SECRET_KEY not found")) -// .expect("Secret key could not be set"); -// // Configure Rocket to use the PORT env var or fall back to 8000 -// let port = if let Ok(port_str) = env::var("PORT") { -// port_str.parse().expect("could not parse PORT") -// } else { -// 8000 -// }; -// config.set_port(port); -// config -//} - #[launch] fn rocket() -> _ { rocket::build() .attach(db::stage()) - // TODO: configure .mount( "/", routes![ @@ -347,7 +363,3 @@ fn rocket() -> _ { .mount("/", FileServer::from(relative!("static")).rank(20)) .attach(Template::fairing()) } - - -// TODO: use figment for config -// TODO: sqlx client From 995c280b066464fc87eccb9b30f1e4073a3dfd67 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Mon, 29 Aug 2022 18:59:45 -0500 Subject: [PATCH 06/17] remove unused import --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d89e74f..d78662b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ use argon2::{ }; use db::Db; use rocket::{ - fairing::AdHoc, form::Form, fs::{relative, FileServer, TempFile}, get, From 2bc02f4e272fc72f1217121c5b266c4c36045552 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Mon, 29 Aug 2022 19:13:42 -0500 Subject: [PATCH 07/17] update config - remove unnecessary fields - fix data-form limit to adhere to 5 MiB anki file limit --- Rocket.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Rocket.toml b/Rocket.toml index 4c53c8b..c284ee3 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -1,8 +1,5 @@ -[debug] -port = "8000" -secret_key = "dev key" - [default.limits] +data-form = "7 MiB" file = "4 MiB" [default.databases.fixes] From ab60bc68632702065f84db97607e35b02855fde6 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 21:39:00 -0500 Subject: [PATCH 08/17] fix naming of db client in params --- src/actions.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index 6246c87..9c52085 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -188,7 +188,7 @@ async fn fill_sentences( } pub fn get_sentences( - client: Connection, + db: Connection, quiz_settings: Form, ) -> Result, Box> { let mut sentences = Vec::new(); @@ -228,14 +228,11 @@ pub fn get_sentences( } } // Fill the readings and overrides - fill_sentences(client, &mut sentences, true); + fill_sentences(db, &mut sentences, true); Ok(sentences) } -pub fn generate_essay( - client: Connection, - quiz_settings: Form, -) -> Vec<[String; 4]> { +pub fn generate_essay(db: Connection, quiz_settings: Form) -> Vec<[String; 4]> { let mut essay = Vec::new(); let mut sentences = Vec::new(); let mut rng = thread_rng(); @@ -273,7 +270,7 @@ pub fn generate_essay( } } // Fill the readings and overrides - fill_sentences(client, &mut sentences, true); + fill_sentences(db, &mut sentences, true); // As long as we have known kanji that aren't in the essay, keep iterating while known_kanji.len() != 0 { From e16cb4467fe11653c90190df213ce0798c31cbf1 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 23:45:35 -0500 Subject: [PATCH 09/17] fix override and report types --- src/actions.rs | 28 +++++++++++++++++++++------- src/main.rs | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index 9c52085..dc45efa 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,5 +1,5 @@ use crate::db::Db; -use sqlx::{query, query_as, Connection as _, Row, SqliteConnection}; +use sqlx::{query, Connection as _, Row, SqliteConnection, PgConnection}; use super::{ AddOverride, AdminOverride, AdminReport, EditOverride, OrderedImport, QuizSettings, Report, @@ -384,23 +384,38 @@ pub async fn get_admin_stuff(mut db: Connection) -> (Vec, Vec, table: String, id: i32) - } pub async fn add_override(mut db: Connection, override_details: Form) -> String { - let row = query_as!( - AdminReport, + let row = query!( "SELECT sentence_id FROM reports WHERE id = $1", override_details.report_id ) diff --git a/src/main.rs b/src/main.rs index d78662b..ea5de6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ pub struct EditOverride { primary_value: bool, } -#[derive(Serialize)] +#[derive(Serialize, Default)] pub struct AdminReport { report_id: i32, sentence_id: i32, @@ -91,7 +91,7 @@ pub struct AdminReport { reported_at: String, } -#[derive(Serialize)] +#[derive(Serialize, Default)] pub struct AdminOverride { override_id: i32, sentence_id: i32, From b82890822face5211b683310725c6f544315a94a Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 23:46:22 -0500 Subject: [PATCH 10/17] fix async types and uses --- src/actions.rs | 30 +++++++++++++++++------------- src/main.rs | 33 +++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index dc45efa..339ed2b 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,5 +1,5 @@ use crate::db::Db; -use sqlx::{query, Connection as _, Row, SqliteConnection, PgConnection}; +use sqlx::{query, Connection as _, PgConnection, Row, SqliteConnection}; use super::{ AddOverride, AdminOverride, AdminReport, EditOverride, OrderedImport, QuizSettings, Report, @@ -128,7 +128,7 @@ impl Sentence for AdminOverride { } async fn fill_sentences( - mut db: Connection, + db: &mut PgConnection, sentences: &mut Vec, add_overrides: bool, ) { @@ -166,7 +166,7 @@ async fn fill_sentences( "SELECT * FROM overrides WHERE sentence_id = ANY($1) ORDER BY primary_value DESC", &sentence_ids ) - .fetch_all(&mut *db) + .fetch_all(db) .await .unwrap() { @@ -187,12 +187,12 @@ async fn fill_sentences( } } -pub fn get_sentences( - db: Connection, +pub async fn get_sentences( + mut db: Connection, quiz_settings: Form, ) -> Result, Box> { let mut sentences = Vec::new(); - let mut rng = thread_rng(); + let mut rng = StdRng::from_entropy(); let known_kanji: HashSet<_> = quiz_settings.known_kanji.chars().collect(); // Read the sentences and shuffle the order @@ -228,14 +228,17 @@ pub fn get_sentences( } } // Fill the readings and overrides - fill_sentences(db, &mut sentences, true); + fill_sentences(&mut db, &mut sentences, true).await; Ok(sentences) } -pub fn generate_essay(db: Connection, quiz_settings: Form) -> Vec<[String; 4]> { +pub async fn generate_essay( + mut db: Connection, + quiz_settings: Form, +) -> Vec<[String; 4]> { let mut essay = Vec::new(); let mut sentences = Vec::new(); - let mut rng = thread_rng(); + let mut rng = StdRng::from_entropy(); // TODO: use unicode crate for this? let mut known_kanji: HashSet<_> = quiz_settings.known_kanji.chars().collect(); @@ -270,7 +273,7 @@ pub fn generate_essay(db: Connection, quiz_settings: Form) -> } } // Fill the readings and overrides - fill_sentences(db, &mut sentences, true); + fill_sentences(&mut db, &mut sentences, true).await; // As long as we have known kanji that aren't in the essay, keep iterating while known_kanji.len() != 0 { @@ -354,7 +357,8 @@ pub async fn save_report(mut db: Connection, report: Form) -> String report.comment.as_ref(), ) .execute(&mut *db) - .await; + .await + .unwrap(); // TODO: use correct return for save_report String::from("success") } @@ -429,8 +433,8 @@ pub async fn get_admin_stuff(mut db: Connection) -> (Vec, Vec(cookies: &'a CookieJar, page: &'a str) -> HashMap<&'a str, #[get("/")] fn get_index(cookies: &CookieJar<'_>) -> Template { - Template::render("index", create_context(&cookies, "/")) + Template::render("index", create_context(cookies, "/")) } #[get("/known_kanji")] fn get_known_kanji(cookies: &CookieJar<'_>) -> Template { - Template::render("known_kanji", create_context(&cookies, "known_kanji")) + Template::render("known_kanji", create_context(cookies, "known_kanji")) } #[get("/quiz")] fn get_quiz(cookies: &CookieJar<'_>) -> Template { - Template::render("quiz", create_context(&cookies, "quiz")) + Template::render("quiz", create_context(cookies, "quiz")) } #[get("/essay")] fn get_essay(cookies: &CookieJar<'_>) -> Template { - Template::render("essay", create_context(&cookies, "essay")) + Template::render("essay", create_context(cookies, "essay")) } #[get("/custom_text")] fn get_custom_text(cookies: &CookieJar<'_>) -> Template { - Template::render("custom_text", create_context(&cookies, "custom_text")) + Template::render("custom_text", create_context(cookies, "custom_text")) } #[get("/offline")] fn get_offline(cookies: &CookieJar<'_>) -> Template { - Template::render("offline", create_context(&cookies, "offline")) + Template::render("offline", create_context(cookies, "offline")) } #[get("/admin")] @@ -180,8 +180,9 @@ async fn get_admin(db: Connection, cookies: &CookieJar<'_>) -> Template { } #[post("/sentences", data = "")] -fn post_sentences(db: Connection, quiz_settings: Form) -> String { +async fn post_sentences(db: Connection, quiz_settings: Form) -> String { get_sentences(db, quiz_settings) + .await .unwrap() .iter() .map(|x| x.join("~")) @@ -197,13 +198,14 @@ async fn post_report(db: Connection, report: Form) -> String { #[post("/import_anki", data = "")] async fn post_import_anki( - cont_type: &ContentType, mut import_settings: Form>, ) -> Result> { let path = Uuid::new_v4().to_string(); import_settings.file.persist_to(&path).await.unwrap(); - extract_kanji_from_anki_deck(&path, import_settings.only_learnt); - fs::remove_file(path).await; + extract_kanji_from_anki_deck(&path, import_settings.only_learnt) + .await + .unwrap(); + fs::remove_file(path).await.unwrap(); Ok("success".to_owned()) } @@ -235,13 +237,16 @@ fn post_import_kanken(import_settings: Form) -> Result, quiz_settings: Form) -> Json> { +async fn post_essay( + db: Connection, + quiz_settings: Form, +) -> Json> { // TODO: do this in a separate thread - Json(generate_essay(db, quiz_settings)) + Json(generate_essay(db, quiz_settings).await) } #[post("/admin_signin", data = "")] -fn post_admin_signin(password: Form, mut cookies: &CookieJar<'_>) -> String { +fn post_admin_signin(password: Form, cookies: &CookieJar<'_>) -> String { let argon2 = Argon2::default(); let admin_hash = env::var("ADMIN_HASH").unwrap(); let parsed_hash = PasswordHash::new(&admin_hash).unwrap(); @@ -323,7 +328,7 @@ async fn post_edit_override( } #[post("/admin_signout")] -fn post_admin_signout(mut cookies: &CookieJar<'_>) -> String { +fn post_admin_signout(cookies: &CookieJar<'_>) -> String { cookies.remove_private(Cookie::named("admin_hash")); String::from("success") } From 559243bfbbc15b431fbf6d6f91877f5802d28f5a Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 23:50:19 -0500 Subject: [PATCH 11/17] use traditional url for postgres db url --- Rocket.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rocket.toml b/Rocket.toml index c284ee3..bda9d15 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -3,4 +3,4 @@ data-form = "7 MiB" file = "4 MiB" [default.databases.fixes] -url = "host=localhost port=5432 dbname=sakubun connect_timeout=10" +url = "postgres://postgres:password@localhost:5432/sakubun" From fc1c0d20be0aa020e5c840acc08722cc333d3665 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 23:58:21 -0500 Subject: [PATCH 12/17] make first migration idempotent since render db is already up, this prevents migration from failing --- migrations/20220829063159_initial_migration.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/20220829063159_initial_migration.sql b/migrations/20220829063159_initial_migration.sql index c4276c6..a18cfab 100644 --- a/migrations/20220829063159_initial_migration.sql +++ b/migrations/20220829063159_initial_migration.sql @@ -1,4 +1,4 @@ -CREATE TABLE overrides ( +CREATE TABLE IF NOT EXISTS overrides ( id serial PRIMARY KEY, sentence_id INTEGER NOT NULL, override_type VARCHAR NOT NULL, @@ -6,7 +6,7 @@ CREATE TABLE overrides ( primary_value BOOLEAN NOT NULL DEFAULT FALSE ); -CREATE TABLE reports ( +CREATE TABLE IF NOT EXISTS reports ( id serial PRIMARY KEY, sentence_id INTEGER NOT NULL, report_type VARCHAR NOT NULL, From ad1231a7d764fac9330c2d1bfe9d9ad7ec73bbe3 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Wed, 31 Aug 2022 00:02:16 -0500 Subject: [PATCH 13/17] remove unused result alias in db.rs it will probably be needed later when error handling is improved, but it is causing cargo to complain right now so it's better to just get rid of it for now. --- src/db.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/db.rs b/src/db.rs index 64d6fc1..06fdee9 100644 --- a/src/db.rs +++ b/src/db.rs @@ -6,8 +6,6 @@ use rocket_db_pools::{sqlx, Database}; #[database("fixes")] pub struct Db(sqlx::PgPool); -pub type Result> = std::result::Result; - pub async fn run_migrations(rocket: Rocket) -> fairing::Result { match Db::fetch(&rocket) { Some(db) => match sqlx::migrate!().run(&**db).await { From bfdc9a8e49b4c32ed1d206a5f1a3322bd3850214 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 22:10:32 -0500 Subject: [PATCH 14/17] add csv crate --- Cargo.lock | 44 ++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 1 + 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f93c822..1fc2e26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,7 +234,10 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ + "lazy_static", "memchr", + "regex-automata", + "serde", ] [[package]] @@ -428,6 +431,28 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +dependencies = [ + "bstr", + "csv-core", + "itoa 0.4.8", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + [[package]] name = "ctr" version = "0.8.0" @@ -941,7 +966,7 @@ checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes", "fnv", - "itoa", + "itoa 1.0.2", ] [[package]] @@ -988,7 +1013,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa", + "itoa 1.0.2", "pin-project-lite", "socket2", "tokio", @@ -1122,6 +1147,12 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + [[package]] name = "itoa" version = "1.0.2" @@ -2101,6 +2132,7 @@ version = "0.1.0" dependencies = [ "argon2", "chrono", + "csv", "log", "native-tls", "rand", @@ -2221,7 +2253,7 @@ version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ - "itoa", + "itoa 1.0.2", "ryu", "serde", ] @@ -2233,7 +2265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa", + "itoa 1.0.2", "ryu", "serde", ] @@ -2406,7 +2438,7 @@ dependencies = [ "hkdf", "hmac", "indexmap", - "itoa", + "itoa 1.0.2", "libc", "libsqlite3-sys", "log", @@ -2664,7 +2696,7 @@ version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b" dependencies = [ - "itoa", + "itoa 1.0.2", "libc", "num_threads", "time-macros 0.2.4", diff --git a/Cargo.toml b/Cargo.toml index 335dc0c..0544720 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] } sqlx = { version = "0.5", features = ["postgres", "sqlite", "tls", "migrate", "macros", "time"] } rocket_db_pools = { version = "0.1.0-rc.2", features = ["sqlx_postgres", "sqlx_sqlite"] } log = "0.4" +csv = "1.1.6" [profile.dev.package.sqlx-macros] opt-level = 3 From d4a5f9b9c5e35489ec4fb5cd488d1ef0d62b1237 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 22:10:48 -0500 Subject: [PATCH 15/17] use csv for `fill_sentences` --- src/actions.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index 339ed2b..e49a706 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,5 +1,6 @@ use crate::db::Db; use sqlx::{query, Connection as _, PgConnection, Row, SqliteConnection}; +use serde::Deserialize; use super::{ AddOverride, AdminOverride, AdminReport, EditOverride, OrderedImport, QuizSettings, Report, @@ -141,17 +142,23 @@ async fn fill_sentences( } } // Add the readings from the file - let kana_records = fs::read_to_string("kana_sentences.txt").unwrap(); - for result in kana_records.lines() { + #[derive(Deserialize)] + struct Record { + id: i32, + sentence: String, + } + let mut kana_records = csv::ReaderBuilder::new() + .has_headers(false) + .delimiter(b'\t') + .from_path("kana_sentences.txt") + .unwrap(); + for record in kana_records.deserialize() { // Parse the values - let record: Vec<_> = result.split('\t').collect(); - if record.len() != 2 { - continue; - } + let record: Record = record.unwrap(); // If this record is in the queue - if let Some(indices) = queue.get(&record[0].parse().unwrap()) { + if let Some(indices) = queue.get(&record.id) { for index in indices { - sentences[*index].set("reading", record[1].to_owned()); + sentences[*index].set("reading", record.sentence.clone()); } } } From d37139457e3ded658fadf477a6006638a9690e82 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Tue, 30 Aug 2022 22:29:02 -0500 Subject: [PATCH 16/17] use csv for `get_admin_stuff` --- src/actions.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index e49a706..0431d67 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -375,9 +375,9 @@ macro_rules! add_question_and_translation { ($vector:ident, $queue:ident, $record:ident) => { // We're doing a for loop because the ID could be there multiple times for (index, sentence_id) in $queue.iter().enumerate() { - if sentence_id == $record[0] { - $vector[index].question = $record[1].to_string(); - $vector[index].translation = $record[2].to_string(); + if *sentence_id == $record.id { + $vector[index].question = $record.jap_sentence; + $vector[index].translation = $record.eng_sentence; } } }; @@ -389,7 +389,11 @@ pub async fn get_admin_stuff(mut db: Connection) -> (Vec, Vec) -> (Vec, Vec = result.split('\t').collect(); - if record.len() != 4 { - continue; - } + let record: Record = record.unwrap(); // If this record's ID is in any of the sentence_ids vectors add_question_and_translation!(reports, reports_sentence_ids, record); add_question_and_translation!(overrides, overrides_sentence_ids, record); From 935f37cb00f7127dc5812b0d8419aefa6e021428 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Wed, 31 Aug 2022 16:55:10 -0500 Subject: [PATCH 17/17] fix csv usage in `get_admin_stuff` --- src/actions.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index 0431d67..c23f41f 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,6 +1,6 @@ use crate::db::Db; -use sqlx::{query, Connection as _, PgConnection, Row, SqliteConnection}; use serde::Deserialize; +use sqlx::{query, Connection as _, PgConnection, Row, SqliteConnection}; use super::{ AddOverride, AdminOverride, AdminReport, EditOverride, OrderedImport, QuizSettings, Report, @@ -376,8 +376,8 @@ macro_rules! add_question_and_translation { // We're doing a for loop because the ID could be there multiple times for (index, sentence_id) in $queue.iter().enumerate() { if *sentence_id == $record.id { - $vector[index].question = $record.jap_sentence; - $vector[index].translation = $record.eng_sentence; + $vector[index].question = $record.jap_sentence.clone(); + $vector[index].translation = $record.eng_sentence.clone(); } } }; @@ -389,7 +389,7 @@ pub async fn get_admin_stuff(mut db: Connection) -> (Vec, Vec) -> (Vec, Vec) -> (Vec, Vec) -> (Vec, Vec, override_details: Form = result.split('\t').collect(); + let record = record.unwrap(); if record[0] == sentence_id.to_string() { original_question = record[1].to_owned(); original_translation = record[2].to_owned(); @@ -689,11 +693,15 @@ pub async fn add_override(mut db: Connection, override_details: Form = result.split('\t').collect(); + let record = record.unwrap(); if record[0] == sentence_id.to_string() { original_reading = record[1].to_owned(); break;