From e364907d9b4ed9641356433c528052f66ddb2f5b Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Sat, 3 Sep 2022 06:35:15 -0400 Subject: [PATCH] serverino --- server/.gitignore | 2 + server/Cargo.lock | 1744 ++++++++++++++++++++++++++++++++ server/Cargo.toml | 18 + server/migrations/1_setup.sql | 27 + server/packs/dark-souls.yaml | 0 server/packs/elden-ring.yaml | 446 ++++++++ server/packs/ffxiv.yaml | 17 + server/src/main.rs | 95 ++ server/src/message.rs | 41 + server/src/pack.rs | 62 ++ server/src/util.rs | 8 + server/src/web.rs | 84 ++ server/src/web/erase.rs | 35 + server/src/web/get_location.rs | 45 + server/src/web/register.rs | 33 + server/src/web/unregister.rs | 31 + server/src/web/vote.rs | 44 + server/src/web/write.rs | 59 ++ 18 files changed, 2791 insertions(+) create mode 100644 server/.gitignore create mode 100644 server/Cargo.lock create mode 100644 server/Cargo.toml create mode 100644 server/migrations/1_setup.sql create mode 100644 server/packs/dark-souls.yaml create mode 100644 server/packs/elden-ring.yaml create mode 100644 server/packs/ffxiv.yaml create mode 100644 server/src/main.rs create mode 100644 server/src/message.rs create mode 100644 server/src/pack.rs create mode 100644 server/src/util.rs create mode 100644 server/src/web.rs create mode 100644 server/src/web/erase.rs create mode 100644 server/src/web/get_location.rs create mode 100644 server/src/web/register.rs create mode 100644 server/src/web/unregister.rs create mode 100644 server/src/web/vote.rs create mode 100644 server/src/web/write.rs diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..aa193d1 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,2 @@ +/target +/database.sqlite* diff --git a/server/Cargo.lock b/server/Cargo.lock new file mode 100644 index 0000000..88e5f5b --- /dev/null +++ b/server/Cargo.lock @@ -0,0 +1,1744 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a" + +[[package]] +name = "atoi" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" +dependencies = [ + "num-traits", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + +[[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.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +dependencies = [ + "iana-time-zone", + "num-integer", + "num-traits", + "winapi", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cpufeatures" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc948ebb96241bb40ab73effeb80d9f93afaad49359d159a5e61be51619fe813" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d0165d2900ae6778e36e80bbc4da3b5eefccee9ba939761f9c2882a5d9af3ff" + +[[package]] +name = "crossbeam-queue" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +dependencies = [ + "block-buffer 0.10.2", + "crypto-common", +] + +[[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", +] + +[[package]] +name = "dotenvy" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3db6fcad7c1fc4abdd99bf5276a4db30d6a819127903a709ed41e5ff016e84" +dependencies = [ + "dirs", +] + +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" + +[[package]] +name = "futures-executor" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62007592ac46aa7c2b6416f7deb9a8a8f63a01e0f1d6e1787d5630170db2b63e" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-sink" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" + +[[package]] +name = "futures-task" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" + +[[package]] +name = "futures-util" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "h2" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util 0.7.3", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d452c155cb93fecdfb02a73dd57b5d8e442c2063bd7aac72f1bc5e4263a43086" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "headers" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" +dependencies = [ + "base64", + "bitflags", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http", +] + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "js-sys", + "once_cell", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[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.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" + +[[package]] +name = "js-sys" +version = "0.3.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "keccak" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" + +[[package]] +name = "libc" +version = "0.2.132" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" + +[[package]] +name = "libsqlite3-sys" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "lock_api" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "multipart" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182" +dependencies = [ + "buf_redux", + "httparse", + "log", + "mime", + "mime_guess", + "quick-error", + "rand", + "safemem", + "tempfile", + "twoway", +] + +[[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 = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[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", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "paste" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[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]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro2" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +dependencies = [ + "unicode-ident", +] + +[[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.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[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", +] + +[[package]] +name = "rustls" +version = "0.20.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +dependencies = [ + "base64", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + +[[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.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "serde" +version = "1.0.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89f31df3f50926cdf2855da5fd8812295c34752cb20438dae42a67f79e021ac3" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "server" +version = "0.1.0" +dependencies = [ + "anyhow", + "base64", + "rand", + "serde", + "serde_yaml", + "sha3", + "sqlx", + "tokio", + "uuid", + "warp", +] + +[[package]] +name = "sha-1" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha1" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006769ba83e921b3085caa8334186b00cf92b4cb1a6cf4632fbccc8eff5c7549" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.3", +] + +[[package]] +name = "sha2" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9db03534dff993187064c4e0c05a5708d2a9728ace9a8959b77bedf415dac5" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.3", +] + +[[package]] +name = "sha3" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaedf34ed289ea47c2b741bb72e5357a209512d67bcd4bda44359e5bf0470f56" +dependencies = [ + "digest 0.10.3", + "keccak", +] + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[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.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "788841def501aabde58d3666fcea11351ec3962e6ea75dbcd05c84a71d68bcd1" +dependencies = [ + "sqlx-core", + "sqlx-macros", +] + +[[package]] +name = "sqlx-core" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c21d3b5e7cadfe9ba7cdc1295f72cc556c750b4419c27c219c0693198901f8e" +dependencies = [ + "ahash", + "atoi", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "dotenvy", + "either", + "event-listener", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "hashlink", + "hex", + "indexmap", + "itoa", + "libc", + "libsqlite3-sys", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "rustls", + "rustls-pemfile", + "sha2", + "smallvec", + "sqlformat", + "sqlx-rt", + "stringprep", + "thiserror", + "tokio-stream", + "url", + "webpki-roots", +] + +[[package]] +name = "sqlx-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4adfd2df3557bddd3b91377fc7893e8fa899e9b4061737cbade4e1bb85f1b45c" +dependencies = [ + "dotenvy", + "either", + "heck", + "once_cell", + "proc-macro2", + "quote", + "sha2", + "sqlx-core", + "sqlx-rt", + "syn", + "url", +] + +[[package]] +name = "sqlx-rt" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7be52fc7c96c136cedea840ed54f7d446ff31ad670c9dea95ebcb998530971a3" +dependencies = [ + "once_cell", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "stringprep" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "syn" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "once_cell", + "pin-project-lite", + "socket2", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "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", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511de3f85caf1c98983545490c3d09685fa8eb634e57eec22bb4db271f46cbd8" +dependencies = [ + "futures-util", + "log", + "pin-project", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "tungstenite" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0b2d8558abd2e276b0a8df5c05a2ec762609344191e5fd23e292c910e9165b5" +dependencies = [ + "base64", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "rand", + "sha-1", + "thiserror", + "url", + "utf-8", +] + +[[package]] +name = "twoway" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" +dependencies = [ + "memchr", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-ident" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" + +[[package]] +name = "unicode-normalization" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +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_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "uuid" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" +dependencies = [ + "getrandom", + "serde", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "warp" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cef4e1e9114a4b7f1ac799f16ce71c14de5778500c5450ec6b7b920c55b587e" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "headers", + "http", + "hyper", + "log", + "mime", + "mime_guess", + "multipart", + "percent-encoding", + "pin-project", + "scoped-tls", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-stream", + "tokio-tungstenite", + "tokio-util 0.6.10", + "tower-service", + "tracing", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" + +[[package]] +name = "web-sys" +version = "0.3.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" +dependencies = [ + "webpki", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[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.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[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.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" diff --git a/server/Cargo.toml b/server/Cargo.toml new file mode 100644 index 0000000..ef3e977 --- /dev/null +++ b/server/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "server" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1" +base64 = "0.13" +rand = "0.8" +serde = { version = "1", features = ["derive"] } +serde_yaml = "0.9" +sha3 = "0.10" +sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "sqlite", "chrono"] } +tokio = { version = "1", features = ["rt-multi-thread", "macros"] } +uuid = { version = "1", features = ["serde", "v4"] } +warp = "0.3" diff --git a/server/migrations/1_setup.sql b/server/migrations/1_setup.sql new file mode 100644 index 0000000..152ffde --- /dev/null +++ b/server/migrations/1_setup.sql @@ -0,0 +1,27 @@ +create table users +( + id integer not null primary key autoincrement, + auth text not null +); + +create table messages +( + id text not null primary key, + user text not null references users (id) on delete cascade, + created timestamp not null default current_timestamp, + territory integer not null, + x float not null, + y float not null, + z float not null, + message text not null +); + +create table votes +( + user text not null references users (id) on delete cascade, + message text not null references messages (id) on delete cascade, + vote tinyint not null, + primary key (user, message) +); + +create index votes_user_idx on votes (user); diff --git a/server/packs/dark-souls.yaml b/server/packs/dark-souls.yaml new file mode 100644 index 0000000..e69de29 diff --git a/server/packs/elden-ring.yaml b/server/packs/elden-ring.yaml new file mode 100644 index 0000000..10f95be --- /dev/null +++ b/server/packs/elden-ring.yaml @@ -0,0 +1,446 @@ +name: Elden Ring +id: 8169c792-3d7c-44eb-aeee-9823c8521ae6 + +templates: + - '{0} ahead' + - 'No {0} ahead' + - '{0} required ahead' + - 'Be wary of {0}' + - 'Try {0}' + - 'Likely {0}' + - 'First off, {0}' + - 'Seek {0}' + - 'Still no {0}...' + - 'Why is it always {0}?' + - 'If only I had a {0}...' + - 'Didn''t expect {0}...' + - 'Visions of {0}...' + - 'Could this be a {0}?' + - 'Time for {0}' + - '{0}, O {0}' + - 'Behold, {0}!' + - 'Offer {0}' + - 'Praise the {0}' + - 'Let there be {0}' + - 'Ahh, {0}...' + - '{0}' + - '{0}!' + - '{0}?' + - '{0}...' + +conjunctions: + - 'and then' + - 'or' + - 'but' + - 'therefore' + - 'in short' + - 'except' + - 'by the way' + - 'so to speak' + - 'all the more' + - ',' + +words: + - name: Enemies + words: + - 'enemy' + - 'weak foe' + - 'strong foe' + - 'monster' + - 'dragon' + - 'boss' + - 'sentry' + - 'group' + - 'pack' + - 'decoy' + - 'undead' + - 'soldier' + - 'knight' + - 'cavalier' + - 'archer' + - 'sniper' + - 'mage' + - 'ordnance' + - 'monarch' + - 'lord' + - 'demi-human' + - 'outsider' + - 'giant' + - 'horse' + - 'dog' + - 'wolf' + - 'rat' + - 'beast' + - 'bird' + - 'raptor' + - 'snake' + - 'crab' + - 'prawn' + - 'octopus' + - 'bug' + - 'scarab' + - 'slug' + - 'wraith' + - 'skeleton' + - 'monstrosity' + - 'ill-omened creature' + + - name: People + words: + - 'Tarnished' + - 'warrior' + - 'swordfighter' + - 'knight' + - 'samurai' + - 'sorcerer' + - 'cleric' + - 'sage' + - 'merchant' + - 'teacher' + - 'master' + - 'friend' + - 'lover' + - 'old dear' + - 'old codger' + - 'angel' + - 'fat coinpurse' + - 'pauper' + - 'good sort' + - 'wicked sort' + - 'plump sort' + - 'skinny sort' + - 'lovable sort' + - 'pathetic sort' + - 'strange sort' + - 'nimble sort' + - 'laggardly sort' + - 'invisible sort' + - 'unfathomable sort' + - 'giant sort' + - 'sinner' + - 'thief' + - 'liar' + - 'dastard' + - 'traitor' + - 'pair' + - 'trio' + - 'noble' + - 'aristocrat' + - 'hero' + - 'champion' + - 'monarch' + - 'lord' + - 'god' + + - name: Things + words: + - 'item' + - 'necessary item' + - 'precious item' + - 'something' + - 'something incredible' + - 'treasure chest' + - 'corpse' + - 'coffin' + - 'trap' + - 'armament' + - 'shield' + - 'bow' + - 'projectile weapon' + - 'armor' + - 'talisman' + - 'skill' + - 'sorcery' + - 'incantation' + - 'map' + - 'material' + - 'flower' + - 'grass' + - 'tree' + - 'fruit' + - 'seed' + - 'mushroom' + - 'tear' + - 'crystal' + - 'butterfly' + - 'bug' + - 'dung' + - 'grace' + - 'door' + - 'key' + - 'ladder' + - 'lever' + - 'lift' + - 'spiritspring' + - 'sending gate' + - 'stone astrolabe' + - 'Birdseye Telescope' + - 'message' + - 'bloodstain' + - 'Erdtree' + - 'Elden Ring' + + - name: Battle Tactics + words: + - 'close-quarters battle' + - 'ranged battle' + - 'horseback battle' + - 'luring out' + - 'defeating one-by-one' + - 'taking on all at once' + - 'rushing in' + - 'stealth' + - 'mimicry' + - 'confusion' + - 'pursuit' + - 'fleeing' + - 'summoning' + - 'circling around' + - 'jumping off' + - 'dashing through' + - 'brief respite' + + - name: Actions + words: + - 'attacking' + - 'jump attack' + - 'running attack' + - 'critical hit' + - 'two-handing' + - 'blocking' + - 'parrying' + - 'guard counter' + - 'sorcery' + - 'incantation' + - 'skill' + - 'summoning' + - 'throwing' + - 'healing' + - 'running' + - 'rolling' + - 'backstepping' + - 'jumping' + - 'crouching' + - 'target lock' + - 'item crafting' + - 'gesturing' + + - name: Situations + words: + - 'morning' + - 'noon' + - 'evening' + - 'night' + - 'clear sky' + - 'overcast' + - 'rain' + - 'storm' + - 'mist' + - 'snow' + - 'patrolling' + - 'procession' + - 'crowd' + - 'surprise attack' + - 'ambush' + - 'pincer attack' + - 'beating to a pulp' + - 'battle' + - 'reinforcements' + - 'ritual' + - 'explosion' + - 'high spot' + - 'defensible spot' + - 'climbable spot' + - 'bright spot' + - 'dark spot' + - 'open area' + - 'cramped area' + - 'hiding place' + - 'sniping spot' + - 'recon spot' + - 'safety' + - 'danger' + - 'gorgeous view' + - 'detour' + - 'hidden path' + - 'secret passage' + - 'shortcut' + - 'dead end' + - 'looking away' + - 'unnoticed' + - 'out of stamina' + + - name: Places + words: + - 'high road' + - 'checkpoint' + - 'bridge' + - 'castle' + - 'fort' + - 'city' + - 'ruins' + - 'church' + - 'tower' + - 'camp site' + - 'house' + - 'cemetery' + - 'underground tomb' + - 'tunnel' + - 'cave' + - 'evergaol' + - 'great tree' + - 'cellar' + - 'surface' + - 'underground' + - 'forest' + - 'river' + - 'lake' + - 'bog' + - 'mountain' + - 'valley' + - 'cliff' + - 'waterside' + - 'nest' + - 'hole' + + - name: Directions + words: + - 'east' + - 'west' + - 'south' + - 'north' + - 'ahead' + - 'behind' + - 'left' + - 'right' + - 'center' + - 'up' + - 'down' + - 'edge' + + - name: Body Parts + words: + - 'head' + - 'stomach' + - 'back' + - 'arms' + - 'legs' + - 'rump' + - 'tail' + - 'core' + - 'fingers' + + - name: Affinities + words: + - 'physical' + - 'standard' + - 'striking' + - 'slashing' + - 'piercing' + - 'fire' + - 'lightning' + - 'magic' + - 'holy' + - 'poison' + - 'toxic' + - 'scarlet rot' + - 'blood loss' + - 'frost' + - 'sleep' + - 'madness' + - 'death' + + - name: Concepts + words: + - 'life' + - 'Death' + - 'light' + - 'dark' + - 'stars' + - 'fire' + - 'Order' + - 'chaos' + - 'joy' + - 'wrath' + - 'suffering' + - 'sadness' + - 'comfort' + - 'bliss' + - 'misfortune' + - 'good fortune' + - 'bad luck' + - 'hope' + - 'despair' + - 'victory' + - 'defeat' + - 'research' + - 'faith' + - 'abundance' + - 'rot' + - 'loyalty' + - 'injustice' + - 'secret' + - 'opportunity' + - 'pickle' + - 'clue' + - 'friendship' + - 'love' + - 'bravery' + - 'vigor' + - 'fortitude' + - 'confidence' + - 'distracted' + - 'unguarded' + - 'introspection' + - 'regret' + - 'resignation' + - 'futility' + - 'on the brink' + - 'betrayal' + - 'revenge' + - 'destruction' + - 'recklessness' + - 'calmness' + - 'vigilance' + - 'tranquility' + - 'sound' + - 'tears' + - 'sleep' + - 'depths' + - 'dregs' + - 'fear' + - 'sacrifice' + - 'ruin' + + - name: Phrases + words: + - 'good luck' + - 'look carefully' + - 'listen carefully' + - 'think carefully' + - 'well done' + - 'I did it!' + - 'I''ve failed...' + - 'here!' + - 'not here!' + - 'don''t you dare!' + - 'do it!' + - 'I can''t take this...' + - 'don''t think' + - 'so lonely...' + - 'here again...' + - 'just getting started' + - 'stay calm' + - 'keep moving' + - 'turn back' + - 'give up' + - 'don''t give up' + - 'help me...' + - 'I don''t believe it...' + - 'too high up' + - 'I want to go home...' + - 'it''s like a dream...' + - 'seems familiar...' + - 'beautiful...' + - 'you don''t have the right' + - 'are you ready?' diff --git a/server/packs/ffxiv.yaml b/server/packs/ffxiv.yaml new file mode 100644 index 0000000..3eb3742 --- /dev/null +++ b/server/packs/ffxiv.yaml @@ -0,0 +1,17 @@ +name: FINAL FANTASY XIV +id: 7cd9e479-080a-4fec-9511-41a53034c2ad + +templates: + - '{0} ahead' + - 'Be wary of {0}' + - 'Try {0}' + - 'Need {0}' + - 'Imminent {0}...' + - 'Weakness: {0}' + - '{0}' + - '{0}?' + - 'Good Luck' + - 'I did it!' + - 'Here!' + - 'I can''t take this...' + - 'Praise the Sun!' diff --git a/server/src/main.rs b/server/src/main.rs new file mode 100644 index 0000000..70cea9a --- /dev/null +++ b/server/src/main.rs @@ -0,0 +1,95 @@ +#![feature(let_chains)] + +use std::collections::HashMap; +use std::net::SocketAddr; +use std::sync::Arc; + +use anyhow::{Context, Result}; +use sqlx::{Executor, Pool, Sqlite}; +use sqlx::migrate::Migrator; +use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; +use tokio::sync::RwLock; +use uuid::Uuid; + +use crate::pack::Pack; + +mod pack; +mod message; +mod web; +mod util; + +static MIGRATOR: Migrator = sqlx::migrate!(); + +pub struct State { + pub db: Pool, + pub packs: RwLock>, +} + +impl State { + pub async fn update_packs(&self) -> Result<()> { + let mut packs = HashMap::new(); + + let mut dir = tokio::fs::read_dir("packs").await?; + while let Ok(Some(entry)) = dir.next_entry().await { + if !entry.path().is_file() { + continue; + } + + match entry.path().extension().and_then(|x| x.to_str()) { + Some("yaml") | Some("yml") => {} + _ => continue, + } + + let text = match tokio::fs::read_to_string(entry.path()).await { + Ok(t) => t, + Err(e) => { + eprintln!("error reading pack: {:#?}", e); + continue; + } + }; + match serde_yaml::from_str::(&text) { + Ok(pack) => { + println!("added {}", pack.name); + packs.insert(pack.id, pack); + } + Err(e) => eprintln!("error parsing pack at {:?}: {:#?}", entry.path(), e), + } + } + + *self.packs.write().await = packs; + + Ok(()) + } +} + +#[tokio::main] +async fn main() -> Result<()> { + let options = SqliteConnectOptions::new(); + // options.log_statements(LevelFilter::Debug); + + let pool = SqlitePoolOptions::new() + .after_connect(|conn, _| Box::pin(async move { + conn.execute( + // language=sqlite + "PRAGMA foreign_keys = ON;" + ).await?; + Ok(()) + })) + // .connect_with(options.filename(&config.database.path)) + .connect_with(options.filename("./database.sqlite")) + .await + .context("could not connect to database")?; + MIGRATOR.run(&pool) + .await + .context("could not run database migrations")?; + + let state = Arc::new(State { + db: pool, + packs: Default::default(), + }); + + state.update_packs().await?; + + warp::serve(web::routes(state)).run("127.0.0.1:8080".parse::()?).await; + Ok(()) +} diff --git a/server/src/message.rs b/server/src/message.rs new file mode 100644 index 0000000..dff2c3f --- /dev/null +++ b/server/src/message.rs @@ -0,0 +1,41 @@ +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +#[derive(Debug, Deserialize)] +pub struct Message { + pub territory: u32, + pub x: f32, + pub y: f32, + pub z: f32, + + pub pack_id: Uuid, + pub template_1: usize, + pub word_1_list: Option, + pub word_1_word: Option, + pub conjugation: Option, + pub template_2: Option, + pub word_2_list: Option, + pub word_2_word: Option, +} + +#[derive(Debug, Deserialize)] +pub struct VoteMessage { + pub post_id: Uuid, + pub vote: u8, +} + +#[derive(Debug, Deserialize)] +pub struct DeleteMessage { + pub post_id: Uuid, +} + +#[derive(Debug, Serialize)] +pub struct RetrievedMessage { + pub id: String, + pub x: f64, + pub y: f64, + pub z: f64, + pub message: String, + pub positive_votes: i32, + pub negative_votes: i32, +} diff --git a/server/src/pack.rs b/server/src/pack.rs new file mode 100644 index 0000000..e616895 --- /dev/null +++ b/server/src/pack.rs @@ -0,0 +1,62 @@ +use serde::Deserialize; +use uuid::Uuid; + +#[derive(Debug, Deserialize)] +pub struct Pack { + pub name: String, + pub id: Uuid, + pub templates: Vec, + pub conjunctions: Vec, + pub words: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct WordList { + pub name: String, + pub words: Vec, +} + +impl Pack { + pub fn format(&self, template_1_idx: usize, word_1_idx: Option<(usize, usize)>, conjunction: Option, template_2_idx: Option, word_2_idx: Option<(usize, usize)>) -> Option { + let template_1 = self.templates.get(template_1_idx)?; + + if template_1.contains("{0}") && word_1_idx.is_none() { + return None; + } + + let mut formatted = if template_1.contains("{0}") && let Some((w1_list, w1_word)) = word_1_idx { + let word_1 = self.words.get(w1_list)?.words.get(w1_word)?; + template_1.replace("{0}", word_1) + } else { + template_1.clone() + }; + + if let Some(conj_idx) = conjunction { + if let Some(template_2_idx) = template_2_idx { + let conj = self.conjunctions.get(conj_idx)?; + if conj.len() > 1 || conj.chars().next().map(|x| !x.is_ascii_punctuation()).unwrap_or(false) { + formatted.push('\n'); + } + + formatted.push_str(conj); + formatted.push(' '); + + let template_2 = self.templates.get(template_2_idx)?; + if template_2.contains("{0}") && word_2_idx.is_none() { + return None; + } + + let append = if let Some((w2_list, w2_word)) = word_2_idx { + let word_2 = self.words.get(w2_list)?.words.get(w2_word)?; + template_2.replace("{0}", word_2) + } else { + template_2.clone() + }; + + formatted.push_str(&append); + } + } + + Some(formatted) + } +} diff --git a/server/src/util.rs b/server/src/util.rs new file mode 100644 index 0000000..3fb1694 --- /dev/null +++ b/server/src/util.rs @@ -0,0 +1,8 @@ +use sha3::{Digest, Sha3_384}; + +pub fn hash(input: &str) -> String { + let mut hasher = Sha3_384::default(); + hasher.update(input.as_bytes()); + let result = hasher.finalize(); + base64::encode(result) +} diff --git a/server/src/web.rs b/server/src/web.rs new file mode 100644 index 0000000..42326b7 --- /dev/null +++ b/server/src/web.rs @@ -0,0 +1,84 @@ +use std::convert::Infallible; +use std::sync::Arc; + +use warp::{Filter, Rejection, Reply}; +use warp::filters::BoxedFilter; +use warp::http::StatusCode; +use warp::reject::Reject; + +use crate::State; + +mod register; +mod unregister; +mod write; +mod erase; +mod get_location; +mod vote; + +pub fn routes(state: Arc) -> BoxedFilter<(impl Reply, )> { + register::register(Arc::clone(&state)) + .or(unregister::unregister(Arc::clone(&state))) + .or(write::write(Arc::clone(&state))) + .or(erase::erase(Arc::clone(&state))) + .or(get_location::get_location(Arc::clone(&state))) + .or(vote::vote(Arc::clone(&state))) + .recover(handle_rejection) + .boxed() +} + +pub fn get_id(state: Arc) -> BoxedFilter<(i64, )> { + warp::cookie("access_token") + .or(warp::header("x-api-key")) + .unify() + .and_then(move |access_token: String| { + let state = Arc::clone(&state); + async move { + let hashed = crate::util::hash(&access_token); + let id = sqlx::query!( + // language=sqlite + "select id from users where auth = ?", + hashed, + ) + .fetch_optional(&state.db) + .await; + match id { + Ok(Some(i)) => Ok(i.id), + Ok(None) => Err(warp::reject::custom(WebError::InvalidAuthToken)), + Err(e) => Err(warp::reject::custom(AnyhowRejection(e.into()))), + } + } + }) + .boxed() +} + +#[derive(Debug)] +pub enum WebError { + InvalidAuthToken, + InvalidPackId, + InvalidIndex, +} + +impl Reject for WebError {} + +#[derive(Debug)] +pub struct AnyhowRejection(anyhow::Error); + +impl Reject for AnyhowRejection {} + +async fn handle_rejection(err: Rejection) -> Result { + let status = if let Some(AnyhowRejection(e)) = err.find::() { + eprintln!("{:#?}", e); + StatusCode::INTERNAL_SERVER_ERROR + } else if let Some(e) = err.find::() { + match e { + WebError::InvalidAuthToken => StatusCode::BAD_REQUEST, + WebError::InvalidPackId => StatusCode::NOT_FOUND, + WebError::InvalidIndex => StatusCode::NOT_FOUND, + } + } else { + eprintln!("{:#?}", err); + StatusCode::INTERNAL_SERVER_ERROR + }; + + Ok(warp::reply::with_status(warp::reply(), status)) +} diff --git a/server/src/web/erase.rs b/server/src/web/erase.rs new file mode 100644 index 0000000..d5c2987 --- /dev/null +++ b/server/src/web/erase.rs @@ -0,0 +1,35 @@ +use std::sync::Arc; + +use anyhow::Context; +use uuid::Uuid; +use warp::{Filter, Rejection, Reply}; +use warp::filters::BoxedFilter; + +use crate::State; +use crate::web::AnyhowRejection; + +pub fn erase(state: Arc) -> BoxedFilter<(impl Reply, )> { + warp::delete() + .and(warp::path("messages")) + .and(warp::path::param()) + .and(warp::path::end()) + .and(super::get_id(Arc::clone(&state))) + .and_then(move |post_id: Uuid, id: i64| logic(Arc::clone(&state), id, post_id)) + .boxed() +} + +async fn logic(state: Arc, id: i64, post_id: Uuid) -> Result { + let post_id = post_id.simple().to_string(); + sqlx::query!( + // language=sqlite + "delete from messages where id = ? and user = ?", + post_id, + id, + ) + .execute(&state.db) + .await + .context("could not delete message from database") + .map_err(AnyhowRejection) + .map_err(warp::reject::custom)?; + Ok(warp::reply()) +} diff --git a/server/src/web/get_location.rs b/server/src/web/get_location.rs new file mode 100644 index 0000000..fa1f0bb --- /dev/null +++ b/server/src/web/get_location.rs @@ -0,0 +1,45 @@ +use std::sync::Arc; + +use anyhow::Context; +use warp::{Filter, Rejection, Reply}; +use warp::filters::BoxedFilter; + +use crate::message::RetrievedMessage; +use crate::State; +use crate::web::AnyhowRejection; + +pub fn get_location(state: Arc) -> BoxedFilter<(impl Reply, )> { + warp::get() + .and(warp::path("messages")) + .and(warp::path::param()) + .and(warp::path::end()) + .and_then(move |location: u32| logic(Arc::clone(&state), location)) + .boxed() +} + +async fn logic(state: Arc, location: u32) -> Result { + let id = location as i64; + let messages = sqlx::query_as!( + RetrievedMessage, + // language=sqlite + r#" + select m.id, + m.x, + m.y, + m.z, + m.message, + coalesce(sum(v.vote between 0 and 1), 0) as positive_votes, + coalesce(sum(v.vote between -1 and 0), 0) as negative_votes + from messages m + left join votes v on m.id = v.message + where m.territory = ? + group by m.id"#, + id, + ) + .fetch_all(&state.db) + .await + .context("could not get messages from database") + .map_err(AnyhowRejection) + .map_err(warp::reject::custom)?; + Ok(warp::reply::json(&messages)) +} diff --git a/server/src/web/register.rs b/server/src/web/register.rs new file mode 100644 index 0000000..31fd7f9 --- /dev/null +++ b/server/src/web/register.rs @@ -0,0 +1,33 @@ +use std::sync::Arc; + +use anyhow::{Context, Result}; +use rand::distributions::{Alphanumeric, DistString}; +use warp::{Filter, Rejection, Reply}; +use warp::filters::BoxedFilter; + +use crate::State; +use crate::web::AnyhowRejection; + +pub fn register(state: Arc) -> BoxedFilter<(impl Reply, )> { + warp::post() + .and(warp::path("account")) + .and(warp::path::end()) + .and_then(move || logic(Arc::clone(&state))) + .boxed() +} + +async fn logic(state: Arc) -> Result { + let auth = Alphanumeric.sample_string(&mut rand::thread_rng(), 32); + let hashed = crate::util::hash(&auth); + sqlx::query!( + // language=sqlite + "insert into users (auth) values (?)", + hashed, + ) + .execute(&state.db) + .await + .context("could not insert user into database") + .map_err(AnyhowRejection) + .map_err(warp::reject::custom)?; + Ok(auth) +} diff --git a/server/src/web/unregister.rs b/server/src/web/unregister.rs new file mode 100644 index 0000000..dd29544 --- /dev/null +++ b/server/src/web/unregister.rs @@ -0,0 +1,31 @@ +use std::sync::Arc; + +use anyhow::Context; +use warp::{Filter, Rejection, Reply}; +use warp::filters::BoxedFilter; + +use crate::State; +use crate::web::AnyhowRejection; + +pub fn unregister(state: Arc) -> BoxedFilter<(impl Reply, )> { + warp::delete() + .and(warp::path("account")) + .and(warp::path::end()) + .and(super::get_id(Arc::clone(&state))) + .and_then(move |id: i64| logic(Arc::clone(&state), id)) + .boxed() +} + +async fn logic(state: Arc, id: i64) -> Result { + sqlx::query!( + // language=sqlite + "delete from users where id = ?", + id, + ) + .execute(&state.db) + .await + .context("could not delete user from database") + .map_err(AnyhowRejection) + .map_err(warp::reject::custom)?; + Ok(warp::reply()) +} diff --git a/server/src/web/vote.rs b/server/src/web/vote.rs new file mode 100644 index 0000000..b7cd5be --- /dev/null +++ b/server/src/web/vote.rs @@ -0,0 +1,44 @@ +use std::sync::Arc; + +use anyhow::Context; +use uuid::Uuid; +use warp::{Filter, Rejection, Reply}; +use warp::filters::BoxedFilter; + +use crate::State; +use crate::web::AnyhowRejection; + +pub fn vote(state: Arc) -> BoxedFilter<(impl Reply, )> { + warp::patch() + .and(warp::path("messages")) + .and(warp::path::param()) + .and(warp::path("votes")) + .and(warp::path::end()) + .and(super::get_id(Arc::clone(&state))) + .and(warp::body::json()) + .and_then(move |message_id: Uuid, id: i64, vote: i8| logic(Arc::clone(&state), id, message_id, vote)) + .boxed() +} + +async fn logic(state: Arc, id: i64, message_id: Uuid, vote: i8) -> Result { + let message_id = message_id.simple().to_string(); + let vote = match vote.signum() { + -1 => -1, + 0 => 1, + 1 => 1, + _ => unreachable!(), + }; + sqlx::query!( + // language=sqlite + "insert or ignore into votes (user, message, vote) values (?, ?, ?)", + id, + message_id, + vote, + ) + .execute(&state.db) + .await + .context("could not insert vote into database") + .map_err(AnyhowRejection) + .map_err(warp::reject::custom)?; + Ok(warp::reply()) +} diff --git a/server/src/web/write.rs b/server/src/web/write.rs new file mode 100644 index 0000000..fe96ea8 --- /dev/null +++ b/server/src/web/write.rs @@ -0,0 +1,59 @@ +use std::sync::Arc; + +use anyhow::Context; +use uuid::Uuid; +use warp::{Filter, Rejection, Reply}; +use warp::filters::BoxedFilter; + +use crate::message::Message; +use crate::State; +use crate::web::{AnyhowRejection, WebError}; + +pub fn write(state: Arc) -> BoxedFilter<(impl Reply, )> { + warp::post() + .and(warp::path("messages")) + .and(warp::path::end()) + .and(super::get_id(Arc::clone(&state))) + .and(warp::body::json()) + .and_then(move |id: i64, message: Message| logic(Arc::clone(&state), id, message)) + .boxed() +} + +async fn logic(state: Arc, id: i64, message: Message) -> Result { + let text = { + let packs = state.packs.read().await; + let pack = packs.get(&message.pack_id) + .ok_or(WebError::InvalidPackId) + .map_err(warp::reject::custom)?; + pack.format( + message.template_1, + message.word_1_list.and_then(|list| message.word_1_word.map(|word| (list, word))), + message.conjugation, + message.template_2, + message.word_2_list.and_then(|list| message.word_2_word.map(|word| (list, word))), + ) + .ok_or(WebError::InvalidIndex) + .map_err(warp::reject::custom)? + }; + + let message_id = Uuid::new_v4().simple().to_string(); + let territory = message.territory as i64; + + sqlx::query!( + // language=sqlite + "insert into messages (id, user, territory, x, y, z, message) values (?, ?, ?, ?, ?, ?, ?)", + message_id, + id, + territory, + message.x, + message.y, + message.z, + text, + ) + .execute(&state.db) + .await + .context("could not insert message into database") + .map_err(AnyhowRejection) + .map_err(warp::reject::custom)?; + Ok(message_id) +}