From 072fa47129e6896e101f2a43195603019a468a23 Mon Sep 17 00:00:00 2001 From: Jai A Date: Tue, 24 Dec 2024 18:51:55 -0700 Subject: [PATCH] NTEX migration start --- Cargo.lock | 914 ++++++++---------- apps/labrinth/Cargo.toml | 34 +- apps/labrinth/src/auth/mod.rs | 10 +- apps/labrinth/src/auth/oauth/errors.rs | 12 +- apps/labrinth/src/auth/oauth/mod.rs | 66 +- apps/labrinth/src/auth/templates/mod.rs | 12 +- apps/labrinth/src/auth/validate.rs | 10 +- apps/labrinth/src/clickhouse/fetch.rs | 12 +- apps/labrinth/src/database/models/ids.rs | 2 +- .../src/database/models/organization_item.rs | 10 +- apps/labrinth/src/database/models/pat_item.rs | 10 +- .../src/database/models/project_item.rs | 528 +++++----- .../src/database/models/session_item.rs | 12 +- .../labrinth/src/database/models/team_item.rs | 4 +- .../labrinth/src/database/models/user_item.rs | 10 +- .../src/database/models/version_item.rs | 513 +++++----- apps/labrinth/src/database/redis.rs | 89 +- apps/labrinth/src/lib.rs | 123 +-- apps/labrinth/src/main.rs | 40 +- apps/labrinth/src/models/v2/projects.rs | 41 +- apps/labrinth/src/queue/socket.rs | 3 +- apps/labrinth/src/routes/analytics.rs | 36 +- apps/labrinth/src/routes/index.rs | 4 +- apps/labrinth/src/routes/internal/admin.rs | 38 +- apps/labrinth/src/routes/internal/billing.rs | 176 ++-- apps/labrinth/src/routes/internal/flows.rs | 192 ++-- apps/labrinth/src/routes/internal/gdpr.rs | 53 +- apps/labrinth/src/routes/internal/mod.rs | 7 +- .../src/routes/internal/moderation.rs | 48 +- apps/labrinth/src/routes/internal/pats.rs | 56 +- apps/labrinth/src/routes/internal/session.rs | 55 +- apps/labrinth/src/routes/internal/statuses.rs | 361 +++---- apps/labrinth/src/routes/maven.rs | 68 +- apps/labrinth/src/routes/mod.rs | 77 +- apps/labrinth/src/routes/not_found.rs | 4 +- apps/labrinth/src/routes/updates.rs | 22 +- apps/labrinth/src/routes/v2/mod.rs | 10 +- apps/labrinth/src/routes/v2/moderation.rs | 18 +- apps/labrinth/src/routes/v2/notifications.rs | 60 +- .../src/routes/v2/project_creation.rs | 19 +- apps/labrinth/src/routes/v2/projects.rs | 196 ++-- apps/labrinth/src/routes/v2/reports.rs | 66 +- apps/labrinth/src/routes/v2/statistics.rs | 6 +- apps/labrinth/src/routes/v2/tags.rs | 46 +- apps/labrinth/src/routes/v2/teams.rs | 86 +- apps/labrinth/src/routes/v2/threads.rs | 44 +- apps/labrinth/src/routes/v2/users.rs | 98 +- .../src/routes/v2/version_creation.rs | 34 +- apps/labrinth/src/routes/v2/version_file.rs | 107 +- apps/labrinth/src/routes/v2/versions.rs | 76 +- apps/labrinth/src/routes/v2_reroute.rs | 249 ++--- apps/labrinth/src/routes/v3/analytics_get.rs | 110 +-- apps/labrinth/src/routes/v3/collections.rs | 140 ++- apps/labrinth/src/routes/v3/friends.rs | 129 +-- apps/labrinth/src/routes/v3/images.rs | 41 +- apps/labrinth/src/routes/v3/mod.rs | 10 +- apps/labrinth/src/routes/v3/notifications.rs | 78 +- apps/labrinth/src/routes/v3/oauth_clients.rs | 147 ++- apps/labrinth/src/routes/v3/organizations.rs | 194 ++-- apps/labrinth/src/routes/v3/payouts.rs | 78 +- .../src/routes/v3/project_creation.rs | 60 +- apps/labrinth/src/routes/v3/projects.rs | 289 +++--- apps/labrinth/src/routes/v3/reports.rs | 87 +- apps/labrinth/src/routes/v3/statistics.rs | 14 +- apps/labrinth/src/routes/v3/tags.rs | 75 +- apps/labrinth/src/routes/v3/teams.rs | 174 ++-- apps/labrinth/src/routes/v3/threads.rs | 78 +- apps/labrinth/src/routes/v3/users.rs | 176 ++-- .../src/routes/v3/version_creation.rs | 45 +- apps/labrinth/src/routes/v3/version_file.rs | 148 +-- apps/labrinth/src/routes/v3/versions.rs | 145 ++- apps/labrinth/src/scheduler.rs | 60 +- apps/labrinth/src/search/indexing/mod.rs | 6 +- apps/labrinth/src/search/mod.rs | 10 +- apps/labrinth/src/util/actix.rs | 17 +- apps/labrinth/src/util/captcha.rs | 11 +- apps/labrinth/src/util/cors.rs | 9 +- apps/labrinth/src/util/guards.rs | 25 +- apps/labrinth/src/util/ratelimit.rs | 165 ++-- apps/labrinth/src/util/routes.rs | 37 +- apps/labrinth/src/validate/mod.rs | 6 +- apps/labrinth/tests/analytics.rs | 4 +- apps/labrinth/tests/common/api_common/mod.rs | 4 +- apps/labrinth/tests/common/api_v2/mod.rs | 2 +- apps/labrinth/tests/common/api_v3/mod.rs | 2 +- apps/labrinth/tests/common/api_v3/oauth.rs | 2 +- apps/labrinth/tests/common/dummy_data.rs | 2 +- apps/labrinth/tests/common/environment.rs | 2 +- apps/labrinth/tests/error.rs | 4 +- apps/labrinth/tests/games.rs | 2 +- apps/labrinth/tests/loader_fields.rs | 12 +- apps/labrinth/tests/notifications.rs | 6 +- apps/labrinth/tests/oauth.rs | 18 +- apps/labrinth/tests/oauth_clients.rs | 14 +- apps/labrinth/tests/organizations.rs | 30 +- apps/labrinth/tests/pats.rs | 6 +- apps/labrinth/tests/project.rs | 32 +- apps/labrinth/tests/scopes.rs | 24 +- apps/labrinth/tests/search.rs | 4 +- apps/labrinth/tests/tags.rs | 4 +- apps/labrinth/tests/teams.rs | 14 +- apps/labrinth/tests/user.rs | 8 +- apps/labrinth/tests/v2/error.rs | 4 +- apps/labrinth/tests/v2/notifications.rs | 2 +- apps/labrinth/tests/v2/project.rs | 14 +- apps/labrinth/tests/v2/scopes.rs | 4 +- apps/labrinth/tests/v2/search.rs | 2 +- apps/labrinth/tests/v2/tags.rs | 4 +- apps/labrinth/tests/v2/teams.rs | 2 +- apps/labrinth/tests/v2/version.rs | 10 +- apps/labrinth/tests/version.rs | 20 +- 111 files changed, 3694 insertions(+), 3895 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8859b55c2..98c5e3dcb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,44 +19,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "actix-cors" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9e772b3bcafe335042b5db010ab7c09013dad6eac4915c91d8d50902769f331" -dependencies = [ - "actix-utils", - "actix-web", - "derive_more", - "futures-util", - "log", - "once_cell", - "smallvec 1.13.2", -] - -[[package]] -name = "actix-files" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0773d59061dedb49a8aed04c67291b9d8cf2fe0b60130a381aab53c6dd86e9be" -dependencies = [ - "actix-http", - "actix-service", - "actix-utils", - "actix-web", - "bitflags 2.6.0", - "bytes 1.7.2", - "derive_more", - "futures-core", - "http-range", - "log", - "mime", - "mime_guess", - "percent-encoding", - "pin-project-lite", - "v_htmlescape", -] - [[package]] name = "actix-http" version = "3.9.0" @@ -68,96 +30,24 @@ dependencies = [ "actix-service", "actix-utils", "ahash 0.8.11", - "base64 0.22.1", "bitflags 2.6.0", - "brotli 6.0.0", "bytes 1.7.2", "bytestring", "derive_more", "encoding_rs", - "flate2", "futures-core", - "h2 0.3.26", "http 0.2.12", "httparse", "httpdate", "itoa 1.0.11", "language-tags", - "local-channel", "mime", "percent-encoding", "pin-project-lite", - "rand 0.8.5", - "sha1 0.10.6", "smallvec 1.13.2", "tokio 1.42.0", "tokio-util", "tracing", - "zstd 0.13.2", -] - -[[package]] -name = "actix-macros" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" -dependencies = [ - "quote", - "syn 2.0.90", -] - -[[package]] -name = "actix-multipart" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d974dd6c4f78d102d057c672dcf6faa618fafa9df91d44f9c466688fc1275a3a" -dependencies = [ - "actix-multipart-derive", - "actix-utils", - "actix-web", - "bytes 1.7.2", - "derive_more", - "futures-core", - "futures-util", - "httparse", - "local-waker", - "log", - "memchr", - "mime", - "rand 0.8.5", - "serde", - "serde_json", - "serde_plain", - "tempfile", - "tokio 1.42.0", -] - -[[package]] -name = "actix-multipart-derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a0a77f836d869f700e5b47ac7c3c8b9c8bc82e4aec861954c6198abee3ebd4d" -dependencies = [ - "darling 0.20.10", - "parse-size", - "proc-macro2", - "quote", - "syn 2.0.90", -] - -[[package]] -name = "actix-router" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" -dependencies = [ - "bytestring", - "cfg-if 1.0.0", - "http 0.2.12", - "regex", - "regex-lite", - "serde", - "tracing", ] [[package]] @@ -166,26 +56,8 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208" dependencies = [ - "actix-macros", - "futures-core", - "tokio 1.42.0", -] - -[[package]] -name = "actix-server" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca2549781d8dd6d75c40cf6b6051260a2cc2f3c62343d761a969a0640646894" -dependencies = [ - "actix-rt", - "actix-service", - "actix-utils", "futures-core", - "futures-util", - "mio 1.0.2", - "socket2", "tokio 1.42.0", - "tracing", ] [[package]] @@ -209,89 +81,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "actix-web" -version = "4.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9180d76e5cc7ccbc4d60a506f2c727730b154010262df5b910eb17dbe4b8cb38" -dependencies = [ - "actix-codec", - "actix-http", - "actix-macros", - "actix-router", - "actix-rt", - "actix-server", - "actix-service", - "actix-utils", - "actix-web-codegen", - "ahash 0.8.11", - "bytes 1.7.2", - "bytestring", - "cfg-if 1.0.0", - "cookie 0.16.2", - "derive_more", - "encoding_rs", - "futures-core", - "futures-util", - "impl-more", - "itoa 1.0.11", - "language-tags", - "log", - "mime", - "once_cell", - "pin-project-lite", - "regex", - "regex-lite", - "serde", - "serde_json", - "serde_urlencoded", - "smallvec 1.13.2", - "socket2", - "time", - "url", -] - -[[package]] -name = "actix-web-codegen" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f591380e2e68490b5dfaf1dd1aa0ebe78d84ba7067078512b4ea6e4492d622b8" -dependencies = [ - "actix-router", - "proc-macro2", - "quote", - "syn 2.0.90", -] - -[[package]] -name = "actix-web-prom" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76743e67d4e7efa9fc2ac7123de0dd7b2ca592668e19334f1d81a3b077afc6ac" -dependencies = [ - "actix-web", - "futures-core", - "log", - "pin-project-lite", - "prometheus", - "regex", - "strfmt", -] - -[[package]] -name = "actix-ws" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3a1fb4f9f2794b0aadaf2ba5f14a6f034c7e86957b458c506a8cb75953f2d99" -dependencies = [ - "actix-codec", - "actix-http", - "actix-web", - "bytestring", - "futures-core", - "tokio 1.42.0", -] - [[package]] name = "addr2line" version = "0.24.1" @@ -1494,17 +1283,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "cookie" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" -dependencies = [ - "percent-encoding", - "time", - "version_check", -] - [[package]] name = "cookie" version = "0.18.1" @@ -1809,6 +1587,16 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "ctrlc" +version = "3.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90eeab0aa92f3f9b4e87f258c72b139c207d251f9cbc1080a0086b86a8870dd3" +dependencies = [ + "nix", + "windows-sys 0.59.0", +] + [[package]] name = "curl" version = "0.4.47" @@ -2025,16 +1813,6 @@ dependencies = [ "tokio 1.42.0", ] -[[package]] -name = "debugid" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" -dependencies = [ - "serde", - "uuid 1.10.0", -] - [[package]] name = "deflate64" version = "0.1.9" @@ -2622,18 +2400,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "findshlibs" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b9e59cd0f7e0806cca4be089683ecb6434e602038df21fe6bf6711b2f07f64" -dependencies = [ - "cc", - "lazy_static", - "libc", - "winapi 0.3.9", -] - [[package]] name = "flate2" version = "1.0.34" @@ -2776,9 +2542,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -2786,9 +2552,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" @@ -2814,9 +2580,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" @@ -2848,9 +2614,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -2859,15 +2625,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -2877,9 +2643,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -3158,14 +2924,15 @@ dependencies = [ [[package]] name = "governor" -version = "0.6.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a7f542ee6b35af73b06abc0dad1c1bae89964e4e253bc4b587b91c9637867b" +checksum = "842dc78579ce01e6a1576ad896edc92fca002dd60c9c3746b7fc2bec6fb429d0" dependencies = [ "cfg-if 1.0.0", - "dashmap 5.5.3", - "futures 0.3.30", + "dashmap 6.1.0", + "futures-sink", "futures-timer", + "futures-util", "no-std-compat", "nonzero_ext", "parking_lot 0.12.3", @@ -3868,12 +3635,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "impl-more" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae21c3177a27788957044151cc2800043d127acaa460a47ebb9b84dfa2c6aa0" - [[package]] name = "indexmap" version = "1.9.3" @@ -4284,14 +4045,7 @@ dependencies = [ name = "labrinth" version = "2.7.0" dependencies = [ - "actix-cors", - "actix-files", "actix-http", - "actix-multipart", - "actix-rt", - "actix-web", - "actix-web-prom", - "actix-ws", "argon2", "async-stripe", "async-trait", @@ -4326,6 +4080,10 @@ dependencies = [ "maxminddb", "meilisearch-sdk", "murmur2", + "ntex", + "ntex-cors", + "ntex-files", + "ntex-multipart", "rand 0.8.5", "rand_chacha 0.3.1", "redis", @@ -4335,8 +4093,6 @@ dependencies = [ "rust_decimal", "rust_iso3166", "rusty-money", - "sentry", - "sentry-actix", "serde", "serde_json", "serde_with", @@ -4536,17 +4292,6 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" -[[package]] -name = "local-channel" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8" -dependencies = [ - "futures-core", - "futures-sink", - "local-waker", -] - [[package]] name = "local-waker" version = "0.1.4" @@ -4864,7 +4609,6 @@ checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ "hermit-abi 0.3.9", "libc", - "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.52.0", ] @@ -4918,6 +4662,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb585ade2549a017db2e35978b77c319214fa4b37cede841e27954dd6e8f3ca8" +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" + [[package]] name = "native-dialog" version = "0.7.0" @@ -5094,23 +4844,314 @@ dependencies = [ ] [[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi 0.3.9", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" +name = "ntex" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +checksum = "a1988f5a24be40f4cd06c5a1d66ff71da4dcf161f19a61013e6f967642c3c5bc" dependencies = [ - "num-integer", - "num-traits", + "base64 0.22.1", + "bitflags 2.6.0", + "bytes 1.7.2", + "encoding_rs", + "flate2", + "httparse", + "httpdate", + "log", + "mime", + "nanorand", + "ntex-bytes", + "ntex-codec", + "ntex-h2", + "ntex-http", + "ntex-io", + "ntex-macros", + "ntex-net", + "ntex-router", + "ntex-rt", + "ntex-server", + "ntex-service", + "ntex-tls", + "ntex-util", + "percent-encoding", + "pin-project-lite", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "sha-1", + "thiserror 1.0.64", +] + +[[package]] +name = "ntex-bytes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffd6ac357a3fd885753ddeb4130ec92474e79d013362532eba4778854466981" +dependencies = [ + "bitflags 2.6.0", + "bytes 1.7.2", + "futures-core", + "serde", +] + +[[package]] +name = "ntex-codec" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69a7e111d946bb915d712df496728ca2a120b1b5643f66c580f13023bce46fda" +dependencies = [ + "ntex-bytes", +] + +[[package]] +name = "ntex-cors" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5240350681b4dab9bcbdbafdb7b25c526c069a9e298f06de00331cd3442311bf" +dependencies = [ + "derive_more", + "futures 0.3.30", + "ntex", +] + +[[package]] +name = "ntex-files" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c37d129e1b93c30c12fe7f7ce3e1770ce7a9d11c5a7dcf1264a8ade8e254db41" +dependencies = [ + "bitflags 2.6.0", + "derive_more", + "futures 0.3.30", + "http 1.1.0", + "httpdate", + "language-tags", + "log", + "mime", + "mime_guess", + "ntex", + "ntex-http", + "percent-encoding", + "unicase", + "v_htmlescape", +] + +[[package]] +name = "ntex-h2" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b235208bb51db69da394f3c77361bed9b62dc50b424842952ff636b1b36f800" +dependencies = [ + "bitflags 2.6.0", + "fxhash", + "log", + "nanorand", + "ntex-bytes", + "ntex-codec", + "ntex-http", + "ntex-io", + "ntex-net", + "ntex-rt", + "ntex-service", + "ntex-util", + "pin-project-lite", + "thiserror 1.0.64", +] + +[[package]] +name = "ntex-http" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa914d2065138de8d3439a6221259fa810c04ded06ddbcc7e46accc52f6365de" +dependencies = [ + "futures-core", + "fxhash", + "http 1.1.0", + "itoa 1.0.11", + "log", + "ntex-bytes", + "serde", +] + +[[package]] +name = "ntex-io" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "857063bbe358ab1d9b49ce3fdcdaf39394aea018818d0bdae3add00ad6dc27c1" +dependencies = [ + "bitflags 2.6.0", + "log", + "ntex-bytes", + "ntex-codec", + "ntex-rt", + "ntex-service", + "ntex-util", + "pin-project-lite", +] + +[[package]] +name = "ntex-macros" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50a359f2a10c712b0446675070c22b1437d57a7cf08139f6a229e1e80817ed84" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ntex-multipart" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd0a3006402a1d1284ae45f489e4be6605d664cf2aeb1c187b1d3fe0b13fd94" +dependencies = [ + "derive_more", + "futures 0.3.30", + "httparse", + "log", + "mime", + "ntex", + "twoway", +] + +[[package]] +name = "ntex-net" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02f3d87616c8fc39c41d432402d98a118861e8e144df30037fe1400cdd29ac35" +dependencies = [ + "log", + "ntex-bytes", + "ntex-http", + "ntex-io", + "ntex-rt", + "ntex-service", + "ntex-tokio", + "ntex-util", + "thiserror 1.0.64", +] + +[[package]] +name = "ntex-router" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb9c68c26a87ffca54339be5f95223339db3e7bcc5d64733fef20812970a746f" +dependencies = [ + "http 1.1.0", + "log", + "ntex-bytes", + "regex", + "serde", +] + +[[package]] +name = "ntex-rt" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81c034a141eb612cd22f8699592a049ab528c812272b071484c13fbf6b6a4f3" +dependencies = [ + "async-channel 2.3.1", + "futures-core", + "log", + "oneshot", + "tokio 1.42.0", +] + +[[package]] +name = "ntex-server" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36cc0ec66ac03f7a76637a1264a57e3234bd95c478fc282ace88c3bde908dc5f" +dependencies = [ + "async-broadcast", + "async-channel 2.3.1", + "ctrlc", + "log", + "ntex-bytes", + "ntex-net", + "ntex-rt", + "ntex-service", + "ntex-util", + "oneshot", + "polling 3.7.3", + "signal-hook", + "socket2", +] + +[[package]] +name = "ntex-service" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07867c1db27ae44cc6c796a0995c08d76aac32dffde961677a3b1950a0008a54" +dependencies = [ + "slab", +] + +[[package]] +name = "ntex-tls" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b6df536ec6f8f2499f5e3a2e2893cfc1b775408ee0c917d0570821025dc22e3" +dependencies = [ + "log", + "ntex-bytes", + "ntex-io", + "ntex-net", + "ntex-service", + "ntex-util", +] + +[[package]] +name = "ntex-tokio" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41ff5282a2912445e9fcf0c751b8c71edefa803bf71478515c8600f4e3e8853" +dependencies = [ + "log", + "ntex-bytes", + "ntex-io", + "ntex-rt", + "ntex-util", + "tokio 1.42.0", +] + +[[package]] +name = "ntex-util" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73a7a68f2b6508ac7da46cc5b78cd9c997580473b3673a308c0f1e27c643a402" +dependencies = [ + "bitflags 2.6.0", + "futures-core", + "futures-sink", + "futures-timer", + "fxhash", + "log", + "ntex-rt", + "ntex-service", + "pin-project-lite", + "slab", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi 0.3.9", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", ] [[package]] @@ -5475,6 +5516,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d11de466f4a3006fe8a5e7ec84e93b79c70cb992ae0aa0eb631ad2df8abfe2" +[[package]] +name = "oneshot" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e296cf87e61c9cfc1a61c3c63a0f7f286ed4554e0e22be84e8a38e1d264a2a29" + [[package]] name = "opaque-debug" version = "0.3.1" @@ -5704,12 +5751,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "parse-size" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487f2ccd1e17ce8c1bfab3a65c89525af41cfad4c8659021a1e9a2aacd73b89b" - [[package]] name = "password-hash" version = "0.4.2" @@ -6170,45 +6211,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "procfs" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "731e0d9356b0c25f16f33b5be79b1c57b562f141ebfcdb0ad8ac2c13a24293b4" -dependencies = [ - "bitflags 2.6.0", - "hex", - "lazy_static", - "procfs-core", - "rustix", -] - -[[package]] -name = "procfs-core" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3554923a69f4ce04c4a754260c338f505ce22642d3830e049a399fc2059a29" -dependencies = [ - "bitflags 2.6.0", - "hex", -] - -[[package]] -name = "prometheus" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1" -dependencies = [ - "cfg-if 1.0.0", - "fnv", - "lazy_static", - "libc", - "memchr", - "parking_lot 0.12.3", - "procfs", - "thiserror 1.0.64", -] - [[package]] name = "psm" version = "0.1.23" @@ -6602,12 +6604,6 @@ dependencies = [ "regex-syntax 0.6.29", ] -[[package]] -name = "regex-lite" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" - [[package]] name = "regex-syntax" version = "0.6.29" @@ -6686,7 +6682,6 @@ dependencies = [ "base64 0.22.1", "bytes 1.7.2", "encoding_rs", - "futures-channel", "futures-core", "futures-util", "h2 0.4.6", @@ -7015,27 +7010,12 @@ dependencies = [ "sct", ] -[[package]] -name = "rustls" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" -dependencies = [ - "log", - "ring 0.17.8", - "rustls-pki-types", - "rustls-webpki 0.102.8", - "subtle", - "zeroize", -] - [[package]] name = "rustls" version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ - "log", "once_cell", "ring 0.17.8", "rustls-pki-types", @@ -7342,126 +7322,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -[[package]] -name = "sentry" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5484316556650182f03b43d4c746ce0e3e48074a21e2f51244b648b6542e1066" -dependencies = [ - "httpdate", - "reqwest 0.12.7", - "rustls 0.22.4", - "sentry-backtrace", - "sentry-contexts", - "sentry-core", - "sentry-debug-images", - "sentry-panic", - "sentry-tracing", - "tokio 1.42.0", - "ureq", - "webpki-roots 0.26.6", -] - -[[package]] -name = "sentry-actix" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e461c7d3a46d298b5ffc66127c1f16454dd11d3d89fcfb21023cd499d82b9a78" -dependencies = [ - "actix-web", - "futures-util", - "sentry-core", -] - -[[package]] -name = "sentry-backtrace" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40aa225bb41e2ec9d7c90886834367f560efc1af028f1c5478a6cce6a59c463a" -dependencies = [ - "backtrace", - "once_cell", - "regex", - "sentry-core", -] - -[[package]] -name = "sentry-contexts" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a8dd746da3d16cb8c39751619cefd4fcdbd6df9610f3310fd646b55f6e39910" -dependencies = [ - "hostname", - "libc", - "os_info", - "rustc_version 0.4.1", - "sentry-core", - "uname", -] - -[[package]] -name = "sentry-core" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161283cfe8e99c8f6f236a402b9ccf726b201f365988b5bb637ebca0abbd4a30" -dependencies = [ - "once_cell", - "rand 0.8.5", - "sentry-types", - "serde", - "serde_json", -] - -[[package]] -name = "sentry-debug-images" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc6b25e945fcaa5e97c43faee0267eebda9f18d4b09a251775d8fef1086238a" -dependencies = [ - "findshlibs", - "once_cell", - "sentry-core", -] - -[[package]] -name = "sentry-panic" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc74f229c7186dd971a9491ffcbe7883544aa064d1589bd30b83fb856cd22d63" -dependencies = [ - "sentry-backtrace", - "sentry-core", -] - -[[package]] -name = "sentry-tracing" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3c5faf2103cd01eeda779ea439b68c4ee15adcdb16600836e97feafab362ec" -dependencies = [ - "sentry-backtrace", - "sentry-core", - "tracing-core", - "tracing-subscriber", -] - -[[package]] -name = "sentry-types" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d68cdf6bc41b8ff3ae2a9c4671e97426dcdd154cc1d4b6b72813f285d6b163f" -dependencies = [ - "debugid", - "hex", - "rand 0.8.5", - "serde", - "serde_json", - "thiserror 1.0.64", - "time", - "url", - "uuid 1.10.0", -] - [[package]] name = "serde" version = "1.0.210" @@ -7560,15 +7420,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_plain" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1fc6db65a611022b23a0dec6975d63fb80a302cb3388835ff02c097258d50" -dependencies = [ - "serde", -] - [[package]] name = "serde_qs" version = "0.8.5" @@ -7697,6 +7548,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha1" version = "0.6.1" @@ -7762,6 +7624,16 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -8208,12 +8080,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strfmt" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8348af2d9fc3258c8733b8d9d8db2e56f54b2363a4b5b81585c7875ed65e65" - [[package]] name = "string_cache" version = "0.8.7" @@ -9692,6 +9558,16 @@ dependencies = [ "utf-8", ] +[[package]] +name = "twoway" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c57ffb460d7c24cd6eda43694110189030a3d1dfe418416d9468fd1c1d290b47" +dependencies = [ + "memchr", + "unchecked-index", +] + [[package]] name = "typeid" version = "1.0.2" @@ -9716,13 +9592,10 @@ dependencies = [ ] [[package]] -name = "uname" -version = "0.1.1" +name = "unchecked-index" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b72f89f0ca32e4db1c04e2a72f5345d59796d4866a1ee0609084569f73683dc8" -dependencies = [ - "libc", -] +checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c" [[package]] name = "unic-char-property" @@ -9831,21 +9704,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "ureq" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" -dependencies = [ - "base64 0.22.1", - "log", - "once_cell", - "rustls 0.23.13", - "rustls-pki-types", - "url", - "webpki-roots 0.26.6", -] - [[package]] name = "url" version = "2.5.2" @@ -10869,7 +10727,7 @@ source = "git+https://github.com/modrinth/wry?rev=e88d4a1#e88d4a10286f58902f50d5 dependencies = [ "base64 0.22.1", "block2", - "cookie 0.18.1", + "cookie", "crossbeam-channel", "dpi", "dunce", diff --git a/apps/labrinth/Cargo.toml b/apps/labrinth/Cargo.toml index 3f0b2a6d2..e4323e525 100644 --- a/apps/labrinth/Cargo.toml +++ b/apps/labrinth/Cargo.toml @@ -11,14 +11,14 @@ name = "labrinth" path = "src/main.rs" [dependencies] -actix-web = "4.4.1" -actix-rt = "2.9.0" -actix-multipart = "0.6.1" -actix-cors = "0.7.0" -actix-ws = "0.3.0" -actix-files = "0.6.5" -actix-web-prom = { version = "0.8.0", features = ["process"] } -governor = "0.6.3" +ntex = { version = "2.0", features = ["tokio", "compress"] } +# actix-rt = "2.9.0" +ntex-multipart = "2.0.0" +ntex-cors = "2.0.0" +# actix-ws = "0.3.0" +ntex-files = "2.0.0" +# actix-web-prom = { version = "0.8.0", features = ["process"] } +governor = "0.8.0" tokio = { version = "1.35.1", features = ["sync"] } tokio-stream = "0.1.14" @@ -97,15 +97,15 @@ maxminddb = "0.24.0" flate2 = "1.0.25" tar = "0.4.38" -sentry = { version = "0.34.0", default-features = false, features = [ - "backtrace", - "contexts", - "debug-images", - "panic", - "rustls", - "reqwest", -] } -sentry-actix = "0.34.0" +#sentry = { version = "0.34.0", default-features = false, features = [ +# "backtrace", +# "contexts", +# "debug-images", +# "panic", +# "rustls", +# "reqwest", +#] } +#sentry-actix = "0.34.0" image = "0.24.6" color-thief = "0.2.2" diff --git a/apps/labrinth/src/auth/mod.rs b/apps/labrinth/src/auth/mod.rs index 30eca4d15..ca7b5129b 100644 --- a/apps/labrinth/src/auth/mod.rs +++ b/apps/labrinth/src/auth/mod.rs @@ -15,8 +15,8 @@ pub use validate::{check_is_moderator_from_headers, get_user_from_headers}; use crate::file_hosting::FileHostingError; use crate::models::error::ApiError; -use actix_web::http::StatusCode; -use actix_web::HttpResponse; +use ntex::http::StatusCode; +use ntex::web::{HttpRequest, HttpResponse}; use thiserror::Error; #[derive(Error, Debug)] @@ -51,7 +51,7 @@ pub enum AuthenticationError { Url, } -impl actix_web::ResponseError for AuthenticationError { +impl ntex::web::WebResponseError for AuthenticationError { fn status_code(&self) -> StatusCode { match self { AuthenticationError::Env(..) => StatusCode::INTERNAL_SERVER_ERROR, @@ -77,8 +77,8 @@ impl actix_web::ResponseError for AuthenticationError { } } - fn error_response(&self) -> HttpResponse { - HttpResponse::build(self.status_code()).json(ApiError { + fn error_response(&self, _req: &HttpRequest) -> HttpResponse { + HttpResponse::build(self.status_code()).json(&ApiError { error: self.error_name(), description: self.to_string(), }) diff --git a/apps/labrinth/src/auth/oauth/errors.rs b/apps/labrinth/src/auth/oauth/errors.rs index dab6ff850..74afca490 100644 --- a/apps/labrinth/src/auth/oauth/errors.rs +++ b/apps/labrinth/src/auth/oauth/errors.rs @@ -2,8 +2,8 @@ use super::ValidatedRedirectUri; use crate::auth::AuthenticationError; use crate::models::error::ApiError; use crate::models::ids::DecodingError; -use actix_web::http::{header::LOCATION, StatusCode}; -use actix_web::HttpResponse; +use ntex::http::{header::LOCATION, StatusCode}; +use ntex::web::{HttpRequest, HttpResponse}; #[derive(thiserror::Error, Debug)] #[error("{}", .error_type)] @@ -55,7 +55,7 @@ impl OAuthError { } } -impl actix_web::ResponseError for OAuthError { +impl ntex::web::WebResponseError for OAuthError { fn status_code(&self) -> StatusCode { match self.error_type { OAuthErrorType::AuthenticationError(_) @@ -83,7 +83,7 @@ impl actix_web::ResponseError for OAuthError { } } - fn error_response(&self) -> HttpResponse { + fn error_response(&self, _req: &HttpRequest) -> HttpResponse { if let Some(ValidatedRedirectUri(mut redirect_uri)) = self.valid_redirect_uri.clone() { @@ -99,10 +99,10 @@ impl actix_web::ResponseError for OAuthError { } HttpResponse::Ok() - .append_header((LOCATION, redirect_uri.clone())) + .header(LOCATION, redirect_uri.clone()) .body(redirect_uri) } else { - HttpResponse::build(self.status_code()).json(ApiError { + HttpResponse::build(self.status_code()).json(&ApiError { error: &self.error_type.error_name(), description: self.error_type.to_string(), }) diff --git a/apps/labrinth/src/auth/oauth/mod.rs b/apps/labrinth/src/auth/oauth/mod.rs index bc0a53884..aa2ecec53 100644 --- a/apps/labrinth/src/auth/oauth/mod.rs +++ b/apps/labrinth/src/auth/oauth/mod.rs @@ -14,14 +14,14 @@ use crate::models; use crate::models::ids::OAuthClientId; use crate::models::pats::Scopes; use crate::queue::session::AuthQueue; -use actix_web::http::header::LOCATION; -use actix_web::web::{Data, Query, ServiceConfig}; -use actix_web::{get, post, web, HttpRequest, HttpResponse}; use chrono::Duration; +use ntex::http::header::LOCATION; +use ntex::http::header::{CACHE_CONTROL, PRAGMA}; +use ntex::web::ServiceConfig; +use ntex::web::{self, get, post, HttpRequest, HttpResponse}; use rand::distributions::Alphanumeric; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; -use reqwest::header::{CACHE_CONTROL, PRAGMA}; use serde::{Deserialize, Serialize}; use sqlx::postgres::PgPool; @@ -59,14 +59,14 @@ pub struct OAuthClientAccessRequest { #[get("authorize")] pub async fn init_oauth( req: HttpRequest, - Query(oauth_info): Query, - pool: Data, - redis: Data, - session_queue: Data, + web::types::Query(oauth_info): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_AUTH_WRITE]), @@ -75,7 +75,7 @@ pub async fn init_oauth( .1; let client_id = oauth_info.client_id.into(); - let client = DBOAuthClient::get(client_id, &**pool).await?; + let client = DBOAuthClient::get(client_id, &*pool).await?; if let Some(client) = client { let redirect_uri = ValidatedRedirectUri::validate( @@ -107,7 +107,7 @@ pub async fn init_oauth( } let existing_authorization = - OAuthClientAuthorization::get(client.id, user.id.into(), &**pool) + OAuthClientAuthorization::get(client.id, user.id.into(), &*pool) .await .map_err(|e| { OAuthError::redirect(e, &oauth_info.state, &redirect_uri) @@ -154,7 +154,7 @@ pub async fn init_oauth( flow_id, requested_scopes, }; - Ok(HttpResponse::Ok().json(access_request)) + Ok(HttpResponse::Ok().json(&access_request)) } } } else { @@ -172,10 +172,10 @@ pub struct RespondToOAuthClientScopes { #[post("accept")] pub async fn accept_client_scopes( req: HttpRequest, - accept_body: web::Json, - pool: Data, - redis: Data, - session_queue: Data, + accept_body: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { accept_or_reject_client_scopes( true, @@ -191,10 +191,10 @@ pub async fn accept_client_scopes( #[post("reject")] pub async fn reject_client_scopes( req: HttpRequest, - body: web::Json, - pool: Data, - redis: Data, - session_queue: Data, + body: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { accept_or_reject_client_scopes(false, req, body, pool, redis, session_queue) .await @@ -221,12 +221,12 @@ pub struct TokenResponse { /// Per IETF RFC6749 Section 4.1.3 (https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3) pub async fn request_token( req: HttpRequest, - req_params: web::Form, - pool: Data, - redis: Data, + req_params: web::types::Form, + pool: web::types::State, + redis: web::types::State, ) -> Result { let req_client_id = req_params.client_id; - let client = DBOAuthClient::get(req_client_id.into(), &**pool).await?; + let client = DBOAuthClient::get(req_client_id.into(), &*pool).await?; if let Some(client) = client { authenticate_client_token_request(&req, &client)?; @@ -294,9 +294,9 @@ pub async fn request_token( // IETF RFC6749 Section 5.1 (https://datatracker.ietf.org/doc/html/rfc6749#section-5.1) Ok(HttpResponse::Ok() - .append_header((CACHE_CONTROL, "no-store")) - .append_header((PRAGMA, "no-cache")) - .json(TokenResponse { + .header(CACHE_CONTROL, "no-store") + .header(PRAGMA, "no-cache") + .json(&TokenResponse { access_token: token, token_type: "Bearer".to_string(), expires_in: time_until_expiration.num_seconds(), @@ -314,14 +314,14 @@ pub async fn request_token( pub async fn accept_or_reject_client_scopes( accept: bool, req: HttpRequest, - body: web::Json, - pool: Data, - redis: Data, - session_queue: Data, + body: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -449,7 +449,7 @@ async fn init_oauth_code_flow( // IETF RFC 6749 Section 4.1.2 (https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2) Ok(HttpResponse::Ok() - .append_header((LOCATION, redirect_uri.clone())) + .header(LOCATION, redirect_uri.clone()) .body(redirect_uri)) } diff --git a/apps/labrinth/src/auth/templates/mod.rs b/apps/labrinth/src/auth/templates/mod.rs index f731fa2b4..26e3208e3 100644 --- a/apps/labrinth/src/auth/templates/mod.rs +++ b/apps/labrinth/src/auth/templates/mod.rs @@ -1,6 +1,6 @@ use crate::auth::AuthenticationError; -use actix_web::http::StatusCode; -use actix_web::{HttpResponse, ResponseError}; +use ntex::http::StatusCode; +use ntex::web::{HttpRequest, HttpResponse, WebResponseError}; use std::fmt::{Debug, Display, Formatter}; pub struct Success<'a> { @@ -13,7 +13,7 @@ impl Success<'_> { let html = include_str!("success.html"); HttpResponse::Ok() - .append_header(("Content-Type", "text/html; charset=utf-8")) + .header("Content-Type", "text/html; charset=utf-8") .body( html.replace("{{ icon }}", self.icon) .replace("{{ name }}", self.name), @@ -41,17 +41,17 @@ impl Display for ErrorPage { impl ErrorPage { pub fn render(&self) -> HttpResponse { HttpResponse::Ok() - .append_header(("Content-Type", "text/html; charset=utf-8")) + .header("Content-Type", "text/html; charset=utf-8") .body(self.to_string()) } } -impl actix_web::ResponseError for ErrorPage { +impl WebResponseError for ErrorPage { fn status_code(&self) -> StatusCode { self.code } - fn error_response(&self) -> HttpResponse { + fn error_response(&self, _req: &HttpRequest) -> HttpResponse { self.render() } } diff --git a/apps/labrinth/src/auth/validate.rs b/apps/labrinth/src/auth/validate.rs index 3f94a9a4d..ecdb154dd 100644 --- a/apps/labrinth/src/auth/validate.rs +++ b/apps/labrinth/src/auth/validate.rs @@ -6,9 +6,9 @@ use crate::models::pats::Scopes; use crate::models::users::User; use crate::queue::session::AuthQueue; use crate::routes::internal::session::get_session_metadata; -use actix_web::http::header::{HeaderValue, AUTHORIZATION}; -use actix_web::HttpRequest; use chrono::Utc; +use ntex::http::header::{HeaderValue, AUTHORIZATION}; +use ntex::web::HttpRequest; pub async fn get_user_from_headers<'a, E>( req: &HttpRequest, @@ -18,7 +18,7 @@ pub async fn get_user_from_headers<'a, E>( required_scopes: Option<&[Scopes]>, ) -> Result<(Scopes, User), AuthenticationError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync, { // Fetch DB user record and minos user from headers let (scopes, db_user) = get_user_record_from_bearer_token( @@ -52,7 +52,7 @@ pub async fn get_user_record_from_bearer_token<'a, 'b, E>( session_queue: &AuthQueue, ) -> Result, AuthenticationError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync, { let token = if let Some(token) = token { token @@ -174,7 +174,7 @@ pub async fn check_is_moderator_from_headers<'a, 'b, E>( required_scopes: Option<&[Scopes]>, ) -> Result where - E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync, { let user = get_user_from_headers( req, diff --git a/apps/labrinth/src/clickhouse/fetch.rs b/apps/labrinth/src/clickhouse/fetch.rs index b0245075b..9a5c52e27 100644 --- a/apps/labrinth/src/clickhouse/fetch.rs +++ b/apps/labrinth/src/clickhouse/fetch.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use crate::{models::ids::ProjectId, routes::ApiError}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -25,7 +23,7 @@ pub async fn fetch_playtimes( start_date: DateTime, end_date: DateTime, resolution_minute: u32, - client: Arc, + client: &clickhouse::Client, ) -> Result, ApiError> { let query = client .query( @@ -56,7 +54,7 @@ pub async fn fetch_views( start_date: DateTime, end_date: DateTime, resolution_minutes: u32, - client: Arc, + client: &clickhouse::Client, ) -> Result, ApiError> { let query = client .query( @@ -86,7 +84,7 @@ pub async fn fetch_downloads( start_date: DateTime, end_date: DateTime, resolution_minutes: u32, - client: Arc, + client: &clickhouse::Client, ) -> Result, ApiError> { let query = client .query( @@ -113,7 +111,7 @@ pub async fn fetch_countries_downloads( projects: Vec, start_date: DateTime, end_date: DateTime, - client: Arc, + client: &clickhouse::Client, ) -> Result, ApiError> { let query = client .query( @@ -140,7 +138,7 @@ pub async fn fetch_countries_views( projects: Vec, start_date: DateTime, end_date: DateTime, - client: Arc, + client: &clickhouse::Client, ) -> Result, ApiError> { let query = client .query( diff --git a/apps/labrinth/src/database/models/ids.rs b/apps/labrinth/src/database/models/ids.rs index aa1b99895..f1453320b 100644 --- a/apps/labrinth/src/database/models/ids.rs +++ b/apps/labrinth/src/database/models/ids.rs @@ -49,7 +49,7 @@ macro_rules! generate_bulk_ids { count: usize, con: &mut sqlx::Transaction<'_, sqlx::Postgres>, ) -> Result, DatabaseError> { - let mut rng = rand::thread_rng(); + let mut rng = ChaCha20Rng::from_entropy(); let mut retry_count = 0; // Check if ID is unique diff --git a/apps/labrinth/src/database/models/organization_item.rs b/apps/labrinth/src/database/models/organization_item.rs index b01052776..e0820523f 100644 --- a/apps/labrinth/src/database/models/organization_item.rs +++ b/apps/labrinth/src/database/models/organization_item.rs @@ -67,7 +67,7 @@ impl Organization { redis: &RedisPool, ) -> Result, super::DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { Self::get_many(&[string], exec, redis) .await @@ -80,7 +80,7 @@ impl Organization { redis: &RedisPool, ) -> Result, super::DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { Self::get_many_ids(&[id], exec, redis) .await @@ -93,7 +93,7 @@ impl Organization { redis: &RedisPool, ) -> Result, super::DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { let ids = organization_ids .iter() @@ -105,14 +105,14 @@ impl Organization { pub async fn get_many< 'a, E, - T: Display + Hash + Eq + PartialEq + Clone + Debug, + T: Display + Hash + Eq + PartialEq + Clone + Debug + Send, >( organization_strings: &[T], exec: E, redis: &RedisPool, ) -> Result, super::DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { let val = redis .get_cached_keys_with_slug( diff --git a/apps/labrinth/src/database/models/pat_item.rs b/apps/labrinth/src/database/models/pat_item.rs index 205a70e4b..e8f3013fc 100644 --- a/apps/labrinth/src/database/models/pat_item.rs +++ b/apps/labrinth/src/database/models/pat_item.rs @@ -58,14 +58,14 @@ impl PersonalAccessToken { pub async fn get< 'a, E, - T: Display + Hash + Eq + PartialEq + Clone + Debug, + T: Display + Hash + Eq + PartialEq + Clone + Debug + Send, >( id: T, exec: E, redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { Self::get_many(&[id], exec, redis) .await @@ -78,7 +78,7 @@ impl PersonalAccessToken { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { let ids = pat_ids .iter() @@ -90,14 +90,14 @@ impl PersonalAccessToken { pub async fn get_many< 'a, E, - T: Display + Hash + Eq + PartialEq + Clone + Debug, + T: Display + Hash + Eq + PartialEq + Clone + Debug + Send, >( pat_strings: &[T], exec: E, redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { let val = redis .get_cached_keys_with_slug( diff --git a/apps/labrinth/src/database/models/project_item.rs b/apps/labrinth/src/database/models/project_item.rs index 1bd07d224..af4fd8a04 100644 --- a/apps/labrinth/src/database/models/project_item.rs +++ b/apps/labrinth/src/database/models/project_item.rs @@ -14,6 +14,7 @@ use futures::TryStreamExt; use itertools::Itertools; use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Display}; +use std::future::Future; use std::hash::Hash; pub const PROJECTS_NAMESPACE: &str = "projects"; @@ -473,82 +474,102 @@ impl Project { } } - pub async fn get<'a, 'b, E>( - string: &str, + /// What's going on here? See: https://github.com/launchbadge/sqlx/issues/1015#issuecomment-767787777 + #[allow(clippy::manual_async_fn)] + pub fn get<'a, 'c, E>( + string: &'a str, executor: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + redis: &'a RedisPool, + ) -> impl Future, DatabaseError>> + Send + 'a where - E: sqlx::Acquire<'a, Database = sqlx::Postgres>, + E: sqlx::Acquire<'c, Database = sqlx::Postgres> + Send + 'a, { - Project::get_many(&[string], executor, redis) - .await - .map(|x| x.into_iter().next()) + async move { + Project::get_many(&[string], executor, redis) + .await + .map(|x| x.into_iter().next()) + } } - pub async fn get_id<'a, 'b, E>( + #[allow(clippy::manual_async_fn)] + pub fn get_id<'a, 'c, E>( id: ProjectId, executor: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + redis: &'a RedisPool, + ) -> impl Future, DatabaseError>> + Send + 'a where - E: sqlx::Acquire<'a, Database = sqlx::Postgres>, + E: sqlx::Acquire<'c, Database = sqlx::Postgres> + Send + 'a, { - Project::get_many( - &[crate::models::ids::ProjectId::from(id)], - executor, - redis, - ) - .await - .map(|x| x.into_iter().next()) + async move { + Project::get_many( + &[crate::models::ids::ProjectId::from(id)], + executor, + redis, + ) + .await + .map(|x| x.into_iter().next()) + } } - pub async fn get_many_ids<'a, E>( - project_ids: &[ProjectId], + #[allow(clippy::manual_async_fn)] + pub fn get_many_ids<'a, 'c, E>( + project_ids: &'a [ProjectId], exec: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + redis: &'a RedisPool, + ) -> impl Future, DatabaseError>> + Send + 'a where - E: sqlx::Acquire<'a, Database = sqlx::Postgres>, + E: sqlx::Acquire<'c, Database = sqlx::Postgres> + Send + 'a, { - let ids = project_ids - .iter() - .map(|x| crate::models::ids::ProjectId::from(*x)) - .collect::>(); - Project::get_many(&ids, exec, redis).await + async move { + let ids = project_ids + .iter() + .map(|x| crate::models::ids::ProjectId::from(*x)) + .collect::>(); + Project::get_many(&ids, exec, redis).await + } } - pub async fn get_many< + #[allow(clippy::manual_async_fn)] + pub fn get_many< 'a, + 'c, E, - T: Display + Hash + Eq + PartialEq + Clone + Debug, + T: Display + + Hash + + Eq + + PartialEq + + Clone + + Debug + + std::marker::Sync + + std::marker::Send, >( - project_strings: &[T], + project_strings: &'a [T], exec: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + redis: &'a RedisPool, + ) -> impl Future, DatabaseError>> + Send + 'a where - E: sqlx::Acquire<'a, Database = sqlx::Postgres>, + E: sqlx::Acquire<'c, Database = sqlx::Postgres> + Send + 'a, { - let val = redis.get_cached_keys_with_slug( - PROJECTS_NAMESPACE, - PROJECTS_SLUGS_NAMESPACE, - false, - project_strings, - |ids| async move { - let mut exec = exec.acquire().await?; - let project_ids_parsed: Vec = ids - .iter() - .flat_map(|x| parse_base62(&x.to_string()).ok()) - .map(|x| x as i64) - .collect(); - let slugs = ids - .into_iter() - .map(|x| x.to_string().to_lowercase()) - .collect::>(); - - let all_version_ids = DashSet::new(); - let versions: DashMap)>> = sqlx::query!( + async move { + let val = redis.get_cached_keys_with_slug( + PROJECTS_NAMESPACE, + PROJECTS_SLUGS_NAMESPACE, + false, + project_strings, + |ids| async move { + let mut exec = exec.acquire().await?; + let project_ids_parsed: Vec = ids + .iter() + .flat_map(|x| parse_base62(&x.to_string()).ok()) + .map(|x| x as i64) + .collect(); + let slugs = ids + .into_iter() + .map(|x| x.to_string().to_lowercase()) + .collect::>(); + + let all_version_ids = DashSet::new(); + let versions: DashMap)>> = sqlx::query!( " SELECT DISTINCT mod_id, v.id as id, date_published FROM mods m @@ -562,23 +583,23 @@ impl Project { .map(|x| x.to_string()) .collect::>() ) - .fetch(&mut *exec) - .try_fold( - DashMap::new(), - |acc: DashMap)>>, m| { - let version_id = VersionId(m.id); - let date_published = m.date_published; - all_version_ids.insert(version_id); - acc.entry(ProjectId(m.mod_id)) - .or_default() - .push((version_id, date_published)); - async move { Ok(acc) } - }, - ) - .await?; + .fetch(&mut *exec) + .try_fold( + DashMap::new(), + |acc: DashMap)>>, m| { + let version_id = VersionId(m.id); + let date_published = m.date_published; + all_version_ids.insert(version_id); + acc.entry(ProjectId(m.mod_id)) + .or_default() + .push((version_id, date_published)); + async move { Ok(acc) } + }, + ) + .await?; - let loader_field_enum_value_ids = DashSet::new(); - let version_fields: DashMap> = sqlx::query!( + let loader_field_enum_value_ids = DashSet::new(); + let version_fields: DashMap> = sqlx::query!( " SELECT DISTINCT mod_id, version_id, field_id, int_value, enum_value, string_value FROM versions v @@ -587,29 +608,29 @@ impl Project { ", &all_version_ids.iter().map(|x| x.0).collect::>() ) - .fetch(&mut *exec) - .try_fold( - DashMap::new(), - |acc: DashMap>, m| { - let qvf = QueryVersionField { - version_id: VersionId(m.version_id), - field_id: LoaderFieldId(m.field_id), - int_value: m.int_value, - enum_value: m.enum_value.map(LoaderFieldEnumValueId), - string_value: m.string_value, - }; - - if let Some(enum_value) = m.enum_value { - loader_field_enum_value_ids.insert(LoaderFieldEnumValueId(enum_value)); - } - - acc.entry(ProjectId(m.mod_id)).or_default().push(qvf); - async move { Ok(acc) } - }, - ) - .await?; + .fetch(&mut *exec) + .try_fold( + DashMap::new(), + |acc: DashMap>, m| { + let qvf = QueryVersionField { + version_id: VersionId(m.version_id), + field_id: LoaderFieldId(m.field_id), + int_value: m.int_value, + enum_value: m.enum_value.map(LoaderFieldEnumValueId), + string_value: m.string_value, + }; + + if let Some(enum_value) = m.enum_value { + loader_field_enum_value_ids.insert(LoaderFieldEnumValueId(enum_value)); + } + + acc.entry(ProjectId(m.mod_id)).or_default().push(qvf); + async move { Ok(acc) } + }, + ) + .await?; - let loader_field_enum_values: Vec = sqlx::query!( + let loader_field_enum_values: Vec = sqlx::query!( " SELECT DISTINCT id, enum_id, value, ordering, created, metadata FROM loader_field_enum_values lfev @@ -621,19 +642,19 @@ impl Project { .map(|x| x.0) .collect::>() ) - .fetch(&mut *exec) - .map_ok(|m| QueryLoaderFieldEnumValue { - id: LoaderFieldEnumValueId(m.id), - enum_id: LoaderFieldEnumId(m.enum_id), - value: m.value, - ordering: m.ordering, - created: m.created, - metadata: m.metadata, - }) - .try_collect() - .await?; - - let mods_gallery: DashMap> = sqlx::query!( + .fetch(&mut *exec) + .map_ok(|m| QueryLoaderFieldEnumValue { + id: LoaderFieldEnumValueId(m.id), + enum_id: LoaderFieldEnumId(m.enum_id), + value: m.value, + ordering: m.ordering, + created: m.created, + metadata: m.metadata, + }) + .try_collect() + .await?; + + let mods_gallery: DashMap> = sqlx::query!( " SELECT DISTINCT mod_id, mg.image_url, mg.raw_image_url, mg.featured, mg.name, mg.description, mg.created, mg.ordering FROM mods_gallery mg @@ -643,23 +664,23 @@ impl Project { &project_ids_parsed, &slugs ).fetch(&mut *exec) - .try_fold(DashMap::new(), |acc : DashMap>, m| { - acc.entry(ProjectId(m.mod_id)) - .or_default() - .push(GalleryItem { - image_url: m.image_url, - raw_image_url: m.raw_image_url, - featured: m.featured.unwrap_or(false), - name: m.name, - description: m.description, - created: m.created, - ordering: m.ordering, - }); - async move { Ok(acc) } - } - ).await?; + .try_fold(DashMap::new(), |acc : DashMap>, m| { + acc.entry(ProjectId(m.mod_id)) + .or_default() + .push(GalleryItem { + image_url: m.image_url, + raw_image_url: m.raw_image_url, + featured: m.featured.unwrap_or(false), + name: m.name, + description: m.description, + created: m.created, + ordering: m.ordering, + }); + async move { Ok(acc) } + } + ).await?; - let links: DashMap> = sqlx::query!( + let links: DashMap> = sqlx::query!( " SELECT DISTINCT joining_mod_id as mod_id, joining_platform_id as platform_id, lp.name as platform_name, url, lp.donation as donation FROM mods_links ml @@ -670,29 +691,29 @@ impl Project { &project_ids_parsed, &slugs ).fetch(&mut *exec) - .try_fold(DashMap::new(), |acc : DashMap>, m| { - acc.entry(ProjectId(m.mod_id)) - .or_default() - .push(LinkUrl { - platform_id: LinkPlatformId(m.platform_id), - platform_name: m.platform_name, - url: m.url, - donation: m.donation, - }); - async move { Ok(acc) } + .try_fold(DashMap::new(), |acc : DashMap>, m| { + acc.entry(ProjectId(m.mod_id)) + .or_default() + .push(LinkUrl { + platform_id: LinkPlatformId(m.platform_id), + platform_name: m.platform_name, + url: m.url, + donation: m.donation, + }); + async move { Ok(acc) } + } + ).await?; + + #[derive(Default)] + struct VersionLoaderData { + loaders: Vec, + project_types: Vec, + games: Vec, + loader_loader_field_ids: Vec, } - ).await?; - - #[derive(Default)] - struct VersionLoaderData { - loaders: Vec, - project_types: Vec, - games: Vec, - loader_loader_field_ids: Vec, - } - - let loader_field_ids = DashSet::new(); - let loaders_ptypes_games: DashMap = sqlx::query!( + + let loader_field_ids = DashSet::new(); + let loaders_ptypes_games: DashMap = sqlx::query!( " SELECT DISTINCT mod_id, ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders, @@ -712,29 +733,29 @@ impl Project { ", &all_version_ids.iter().map(|x| x.0).collect::>() ).fetch(&mut *exec) - .map_ok(|m| { - let project_id = ProjectId(m.mod_id); + .map_ok(|m| { + let project_id = ProjectId(m.mod_id); - // Add loader fields to the set we need to fetch - let loader_loader_field_ids = m.loader_fields.unwrap_or_default().into_iter().map(LoaderFieldId).collect::>(); - for loader_field_id in loader_loader_field_ids.iter() { - loader_field_ids.insert(*loader_field_id); - } + // Add loader fields to the set we need to fetch + let loader_loader_field_ids = m.loader_fields.unwrap_or_default().into_iter().map(LoaderFieldId).collect::>(); + for loader_field_id in loader_loader_field_ids.iter() { + loader_field_ids.insert(*loader_field_id); + } - // Add loader + loader associated data to the map - let version_loader_data = VersionLoaderData { - loaders: m.loaders.unwrap_or_default(), - project_types: m.project_types.unwrap_or_default(), - games: m.games.unwrap_or_default(), - loader_loader_field_ids, - }; + // Add loader + loader associated data to the map + let version_loader_data = VersionLoaderData { + loaders: m.loaders.unwrap_or_default(), + project_types: m.project_types.unwrap_or_default(), + games: m.games.unwrap_or_default(), + loader_loader_field_ids, + }; - (project_id, version_loader_data) + (project_id, version_loader_data) - } - ).try_collect().await?; + } + ).try_collect().await?; - let loader_fields: Vec = sqlx::query!( + let loader_fields: Vec = sqlx::query!( " SELECT DISTINCT id, field, field_type, enum_type, min_val, max_val, optional FROM loader_fields lf @@ -742,20 +763,20 @@ impl Project { ", &loader_field_ids.iter().map(|x| x.0).collect::>() ) - .fetch(&mut *exec) - .map_ok(|m| QueryLoaderField { - id: LoaderFieldId(m.id), - field: m.field, - field_type: m.field_type, - enum_type: m.enum_type.map(LoaderFieldEnumId), - min_val: m.min_val, - max_val: m.max_val, - optional: m.optional, - }) - .try_collect() - .await?; - - let projects = sqlx::query!( + .fetch(&mut *exec) + .map_ok(|m| QueryLoaderField { + id: LoaderFieldId(m.id), + field: m.field, + field_type: m.field_type, + enum_type: m.enum_type.map(LoaderFieldEnumId), + min_val: m.min_val, + max_val: m.max_val, + optional: m.optional, + }) + .try_collect() + .await?; + + let projects = sqlx::query!( " SELECT m.id id, m.name name, m.summary summary, m.downloads downloads, m.follows follows, m.icon_url icon_url, m.raw_icon_url raw_icon_url, m.description description, m.published published, @@ -776,87 +797,88 @@ impl Project { &project_ids_parsed, &slugs, ) - .fetch(&mut *exec) - .try_fold(DashMap::new(), |acc, m| { - let id = m.id; - let project_id = ProjectId(id); - let VersionLoaderData { - loaders, - project_types, - games, - loader_loader_field_ids, - } = loaders_ptypes_games.remove(&project_id).map(|x|x.1).unwrap_or_default(); - let mut versions = versions.remove(&project_id).map(|x| x.1).unwrap_or_default(); - let mut gallery = mods_gallery.remove(&project_id).map(|x| x.1).unwrap_or_default(); - let urls = links.remove(&project_id).map(|x| x.1).unwrap_or_default(); - let version_fields = version_fields.remove(&project_id).map(|x| x.1).unwrap_or_default(); - - let loader_fields = loader_fields.iter() - .filter(|x| loader_loader_field_ids.contains(&x.id)) - .collect::>(); - - let project = QueryProject { - inner: Project { - id: ProjectId(id), - team_id: TeamId(m.team_id), - organization_id: m.organization_id.map(OrganizationId), - name: m.name.clone(), - summary: m.summary.clone(), - downloads: m.downloads, - icon_url: m.icon_url.clone(), - raw_icon_url: m.raw_icon_url.clone(), - published: m.published, - updated: m.updated, - license_url: m.license_url.clone(), - status: ProjectStatus::from_string( - &m.status, - ), - requested_status: m.requested_status.map(|x| ProjectStatus::from_string( - &x, - )), - license: m.license.clone(), - slug: m.slug.clone(), - description: m.description.clone(), - follows: m.follows, - moderation_message: m.moderation_message, - moderation_message_body: m.moderation_message_body, - approved: m.approved, - webhook_sent: m.webhook_sent, - color: m.color.map(|x| x as u32), - queued: m.queued, - monetization_status: MonetizationStatus::from_string( - &m.monetization_status, - ), + .fetch(&mut *exec) + .try_fold(DashMap::new(), |acc, m| { + let id = m.id; + let project_id = ProjectId(id); + let VersionLoaderData { loaders, - }, - categories: m.categories.unwrap_or_default(), - additional_categories: m.additional_categories.unwrap_or_default(), - project_types, - games, - versions: { - // Each version is a tuple of (VersionId, DateTime) - versions.sort_by(|a, b| a.1.cmp(&b.1)); - versions.into_iter().map(|x| x.0).collect() - }, - gallery_items: { - gallery.sort_by(|a, b| a.ordering.cmp(&b.ordering)); - gallery - }, - urls, - aggregate_version_fields: VersionField::from_query_json(version_fields, &loader_fields, &loader_field_enum_values, true), - thread_id: ThreadId(m.thread_id), - }; - - acc.insert(m.id, (m.slug, project)); - async move { Ok(acc) } - }) - .await?; + project_types, + games, + loader_loader_field_ids, + } = loaders_ptypes_games.remove(&project_id).map(|x|x.1).unwrap_or_default(); + let mut versions = versions.remove(&project_id).map(|x| x.1).unwrap_or_default(); + let mut gallery = mods_gallery.remove(&project_id).map(|x| x.1).unwrap_or_default(); + let urls = links.remove(&project_id).map(|x| x.1).unwrap_or_default(); + let version_fields = version_fields.remove(&project_id).map(|x| x.1).unwrap_or_default(); + + let loader_fields = loader_fields.iter() + .filter(|x| loader_loader_field_ids.contains(&x.id)) + .collect::>(); + + let project = QueryProject { + inner: Project { + id: ProjectId(id), + team_id: TeamId(m.team_id), + organization_id: m.organization_id.map(OrganizationId), + name: m.name.clone(), + summary: m.summary.clone(), + downloads: m.downloads, + icon_url: m.icon_url.clone(), + raw_icon_url: m.raw_icon_url.clone(), + published: m.published, + updated: m.updated, + license_url: m.license_url.clone(), + status: ProjectStatus::from_string( + &m.status, + ), + requested_status: m.requested_status.map(|x| ProjectStatus::from_string( + &x, + )), + license: m.license.clone(), + slug: m.slug.clone(), + description: m.description.clone(), + follows: m.follows, + moderation_message: m.moderation_message, + moderation_message_body: m.moderation_message_body, + approved: m.approved, + webhook_sent: m.webhook_sent, + color: m.color.map(|x| x as u32), + queued: m.queued, + monetization_status: MonetizationStatus::from_string( + &m.monetization_status, + ), + loaders, + }, + categories: m.categories.unwrap_or_default(), + additional_categories: m.additional_categories.unwrap_or_default(), + project_types, + games, + versions: { + // Each version is a tuple of (VersionId, DateTime) + versions.sort_by(|a, b| a.1.cmp(&b.1)); + versions.into_iter().map(|x| x.0).collect() + }, + gallery_items: { + gallery.sort_by(|a, b| a.ordering.cmp(&b.ordering)); + gallery + }, + urls, + aggregate_version_fields: VersionField::from_query_json(version_fields, &loader_fields, &loader_field_enum_values, true), + thread_id: ThreadId(m.thread_id), + }; - Ok(projects) - }, - ).await?; + acc.insert(m.id, (m.slug, project)); + async move { Ok(acc) } + }) + .await?; - Ok(val) + Ok(projects) + }, + ).await?; + + Ok(val) + } } pub async fn get_dependencies<'a, E>( diff --git a/apps/labrinth/src/database/models/session_item.rs b/apps/labrinth/src/database/models/session_item.rs index adb1659ea..b41061833 100644 --- a/apps/labrinth/src/database/models/session_item.rs +++ b/apps/labrinth/src/database/models/session_item.rs @@ -85,14 +85,14 @@ impl Session { pub async fn get< 'a, E, - T: Display + Hash + Eq + PartialEq + Clone + Debug, + T: Display + Hash + Eq + PartialEq + Clone + Debug + Send, >( id: T, exec: E, redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { Self::get_many(&[id], exec, redis) .await @@ -105,7 +105,7 @@ impl Session { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { Session::get_many( &[crate::models::ids::SessionId::from(id)], @@ -122,7 +122,7 @@ impl Session { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { let ids = session_ids .iter() @@ -134,14 +134,14 @@ impl Session { pub async fn get_many< 'a, E, - T: Display + Hash + Eq + PartialEq + Clone + Debug, + T: Display + Hash + Eq + PartialEq + Clone + Debug + Send, >( session_strings: &[T], exec: E, redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { use futures::TryStreamExt; diff --git a/apps/labrinth/src/database/models/team_item.rs b/apps/labrinth/src/database/models/team_item.rs index 8f6f811ef..bdadcf03e 100644 --- a/apps/labrinth/src/database/models/team_item.rs +++ b/apps/labrinth/src/database/models/team_item.rs @@ -194,7 +194,7 @@ impl TeamMember { redis: &RedisPool, ) -> Result, super::DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync, { Self::get_from_team_full_many(&[id], executor, redis).await } @@ -205,7 +205,7 @@ impl TeamMember { redis: &RedisPool, ) -> Result, super::DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync, { if team_ids.is_empty() { return Ok(Vec::new()); diff --git a/apps/labrinth/src/database/models/user_item.rs b/apps/labrinth/src/database/models/user_item.rs index b42fc4651..7c27e7423 100644 --- a/apps/labrinth/src/database/models/user_item.rs +++ b/apps/labrinth/src/database/models/user_item.rs @@ -103,7 +103,7 @@ impl User { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { User::get_many(&[string], executor, redis) .await @@ -116,7 +116,7 @@ impl User { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { User::get_many(&[crate::models::ids::UserId::from(id)], executor, redis) .await @@ -129,7 +129,7 @@ impl User { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { let ids = user_ids .iter() @@ -141,14 +141,14 @@ impl User { pub async fn get_many< 'a, E, - T: Display + Hash + Eq + PartialEq + Clone + Debug, + T: Display + Hash + Eq + PartialEq + Clone + Debug + Send, >( users_strings: &[T], exec: E, redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres>, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Send + Sync, { use futures::TryStreamExt; diff --git a/apps/labrinth/src/database/models/version_item.rs b/apps/labrinth/src/database/models/version_item.rs index 792c9ac0e..e17b48d31 100644 --- a/apps/labrinth/src/database/models/version_item.rs +++ b/apps/labrinth/src/database/models/version_item.rs @@ -13,6 +13,7 @@ use itertools::Itertools; use serde::{Deserialize, Serialize}; use std::cmp::Ordering; use std::collections::HashMap; +use std::future::Future; use std::iter; pub const VERSIONS_NAMESPACE: &str = "versions"; @@ -455,35 +456,40 @@ impl Version { Ok(Some(())) } - pub async fn get<'a, 'b, E>( + #[allow(clippy::manual_async_fn)] + pub fn get<'a, 'c, E>( id: VersionId, executor: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + redis: &'a RedisPool, + ) -> impl Future, DatabaseError>> + Send + 'a where - E: sqlx::Acquire<'a, Database = sqlx::Postgres>, + E: sqlx::Acquire<'c, Database = sqlx::Postgres> + Send + 'a, { - Self::get_many(&[id], executor, redis) - .await - .map(|x| x.into_iter().next()) + async move { + Self::get_many(&[id], executor, redis) + .await + .map(|x| x.into_iter().next()) + } } - pub async fn get_many<'a, E>( - version_ids: &[VersionId], + #[allow(clippy::manual_async_fn)] + pub fn get_many<'a, 'c, E>( + version_ids: &'a [VersionId], exec: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + redis: &'a RedisPool, + ) -> impl Future, DatabaseError>> + Send + 'a where - E: sqlx::Acquire<'a, Database = sqlx::Postgres>, + E: sqlx::Acquire<'c, Database = sqlx::Postgres> + Send + 'a, { - let mut val = redis.get_cached_keys( - VERSIONS_NAMESPACE, - &version_ids.iter().map(|x| x.0).collect::>(), - |version_ids| async move { - let mut exec = exec.acquire().await?; - - let loader_field_enum_value_ids = DashSet::new(); - let version_fields: DashMap> = sqlx::query!( + async move { + let mut val = redis.get_cached_keys( + VERSIONS_NAMESPACE, + &version_ids.iter().map(|x| x.0).collect::>(), + |version_ids| async move { + let mut exec = exec.acquire().await?; + + let loader_field_enum_value_ids = DashSet::new(); + let version_fields: DashMap> = sqlx::query!( " SELECT version_id, field_id, int_value, enum_value, string_value FROM version_fields @@ -491,38 +497,38 @@ impl Version { ", &version_ids ) - .fetch(&mut *exec) - .try_fold( - DashMap::new(), - |acc: DashMap>, m| { - let qvf = QueryVersionField { - version_id: VersionId(m.version_id), - field_id: LoaderFieldId(m.field_id), - int_value: m.int_value, - enum_value: m.enum_value.map(LoaderFieldEnumValueId), - string_value: m.string_value, - }; - - if let Some(enum_value) = m.enum_value { - loader_field_enum_value_ids.insert(LoaderFieldEnumValueId(enum_value)); - } - - acc.entry(VersionId(m.version_id)).or_default().push(qvf); - async move { Ok(acc) } - }, - ) - .await?; - - #[derive(Default)] - struct VersionLoaderData { - loaders: Vec, - project_types: Vec, - games: Vec, - loader_loader_field_ids: Vec, - } + .fetch(&mut *exec) + .try_fold( + DashMap::new(), + |acc: DashMap>, m| { + let qvf = QueryVersionField { + version_id: VersionId(m.version_id), + field_id: LoaderFieldId(m.field_id), + int_value: m.int_value, + enum_value: m.enum_value.map(LoaderFieldEnumValueId), + string_value: m.string_value, + }; + + if let Some(enum_value) = m.enum_value { + loader_field_enum_value_ids.insert(LoaderFieldEnumValueId(enum_value)); + } + + acc.entry(VersionId(m.version_id)).or_default().push(qvf); + async move { Ok(acc) } + }, + ) + .await?; + + #[derive(Default)] + struct VersionLoaderData { + loaders: Vec, + project_types: Vec, + games: Vec, + loader_loader_field_ids: Vec, + } - let loader_field_ids = DashSet::new(); - let loaders_ptypes_games: DashMap = sqlx::query!( + let loader_field_ids = DashSet::new(); + let loaders_ptypes_games: DashMap = sqlx::query!( " SELECT DISTINCT version_id, ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders, @@ -542,29 +548,29 @@ impl Version { ", &version_ids ).fetch(&mut *exec) - .map_ok(|m| { - let version_id = VersionId(m.version_id); + .map_ok(|m| { + let version_id = VersionId(m.version_id); - // Add loader fields to the set we need to fetch - let loader_loader_field_ids = m.loader_fields.unwrap_or_default().into_iter().map(LoaderFieldId).collect::>(); - for loader_field_id in loader_loader_field_ids.iter() { - loader_field_ids.insert(*loader_field_id); - } + // Add loader fields to the set we need to fetch + let loader_loader_field_ids = m.loader_fields.unwrap_or_default().into_iter().map(LoaderFieldId).collect::>(); + for loader_field_id in loader_loader_field_ids.iter() { + loader_field_ids.insert(*loader_field_id); + } - // Add loader + loader associated data to the map - let version_loader_data = VersionLoaderData { - loaders: m.loaders.unwrap_or_default(), - project_types: m.project_types.unwrap_or_default(), - games: m.games.unwrap_or_default(), - loader_loader_field_ids, - }; - (version_id,version_loader_data) + // Add loader + loader associated data to the map + let version_loader_data = VersionLoaderData { + loaders: m.loaders.unwrap_or_default(), + project_types: m.project_types.unwrap_or_default(), + games: m.games.unwrap_or_default(), + loader_loader_field_ids, + }; + (version_id,version_loader_data) - } - ).try_collect().await?; + } + ).try_collect().await?; - // Fetch all loader fields from any version - let loader_fields: Vec = sqlx::query!( + // Fetch all loader fields from any version + let loader_fields: Vec = sqlx::query!( " SELECT DISTINCT id, field, field_type, enum_type, min_val, max_val, optional FROM loader_fields lf @@ -572,20 +578,20 @@ impl Version { ", &loader_field_ids.iter().map(|x| x.0).collect::>() ) - .fetch(&mut *exec) - .map_ok(|m| QueryLoaderField { - id: LoaderFieldId(m.id), - field: m.field, - field_type: m.field_type, - enum_type: m.enum_type.map(LoaderFieldEnumId), - min_val: m.min_val, - max_val: m.max_val, - optional: m.optional, - }) - .try_collect() - .await?; + .fetch(&mut *exec) + .map_ok(|m| QueryLoaderField { + id: LoaderFieldId(m.id), + field: m.field, + field_type: m.field_type, + enum_type: m.enum_type.map(LoaderFieldEnumId), + min_val: m.min_val, + max_val: m.max_val, + optional: m.optional, + }) + .try_collect() + .await?; - let loader_field_enum_values: Vec = sqlx::query!( + let loader_field_enum_values: Vec = sqlx::query!( " SELECT DISTINCT id, enum_id, value, ordering, created, metadata FROM loader_field_enum_values lfev @@ -597,38 +603,38 @@ impl Version { .map(|x| x.0) .collect::>() ) - .fetch(&mut *exec) - .map_ok(|m| QueryLoaderFieldEnumValue { - id: LoaderFieldEnumValueId(m.id), - enum_id: LoaderFieldEnumId(m.enum_id), - value: m.value, - ordering: m.ordering, - created: m.created, - metadata: m.metadata, - }) - .try_collect() - .await?; + .fetch(&mut *exec) + .map_ok(|m| QueryLoaderFieldEnumValue { + id: LoaderFieldEnumValueId(m.id), + enum_id: LoaderFieldEnumId(m.enum_id), + value: m.value, + ordering: m.ordering, + created: m.created, + metadata: m.metadata, + }) + .try_collect() + .await?; + + #[derive(Deserialize)] + struct Hash { + pub file_id: FileId, + pub algorithm: String, + pub hash: String, + } + + #[derive(Deserialize)] + struct File { + pub id: FileId, + pub url: String, + pub filename: String, + pub primary: bool, + pub size: u32, + pub file_type: Option, + } - #[derive(Deserialize)] - struct Hash { - pub file_id: FileId, - pub algorithm: String, - pub hash: String, - } - - #[derive(Deserialize)] - struct File { - pub id: FileId, - pub url: String, - pub filename: String, - pub primary: bool, - pub size: u32, - pub file_type: Option, - } - - let file_ids = DashSet::new(); - let reverse_file_map = DashMap::new(); - let files : DashMap> = sqlx::query!( + let file_ids = DashSet::new(); + let reverse_file_map = DashMap::new(); + let files : DashMap> = sqlx::query!( " SELECT DISTINCT version_id, f.id, f.url, f.filename, f.is_primary, f.size, f.file_type FROM files f @@ -636,27 +642,27 @@ impl Version { ", &version_ids ).fetch(&mut *exec) - .try_fold(DashMap::new(), |acc : DashMap>, m| { - let file = File { - id: FileId(m.id), - url: m.url, - filename: m.filename, - primary: m.is_primary, - size: m.size as u32, - file_type: m.file_type.map(|x| FileType::from_string(&x)), - }; - - file_ids.insert(FileId(m.id)); - reverse_file_map.insert(FileId(m.id), VersionId(m.version_id)); - - acc.entry(VersionId(m.version_id)) - .or_default() - .push(file); - async move { Ok(acc) } - } - ).await?; + .try_fold(DashMap::new(), |acc : DashMap>, m| { + let file = File { + id: FileId(m.id), + url: m.url, + filename: m.filename, + primary: m.is_primary, + size: m.size as u32, + file_type: m.file_type.map(|x| FileType::from_string(&x)), + }; + + file_ids.insert(FileId(m.id)); + reverse_file_map.insert(FileId(m.id), VersionId(m.version_id)); - let hashes: DashMap> = sqlx::query!( + acc.entry(VersionId(m.version_id)) + .or_default() + .push(file); + async move { Ok(acc) } + } + ).await?; + + let hashes: DashMap> = sqlx::query!( " SELECT DISTINCT file_id, algorithm, encode(hash, 'escape') hash FROM hashes @@ -664,24 +670,24 @@ impl Version { ", &file_ids.iter().map(|x| x.0).collect::>() ) - .fetch(&mut *exec) - .try_fold(DashMap::new(), |acc: DashMap>, m| { - if let Some(found_hash) = m.hash { - let hash = Hash { - file_id: FileId(m.file_id), - algorithm: m.algorithm, - hash: found_hash, - }; - - if let Some(version_id) = reverse_file_map.get(&FileId(m.file_id)) { - acc.entry(*version_id).or_default().push(hash); + .fetch(&mut *exec) + .try_fold(DashMap::new(), |acc: DashMap>, m| { + if let Some(found_hash) = m.hash { + let hash = Hash { + file_id: FileId(m.file_id), + algorithm: m.algorithm, + hash: found_hash, + }; + + if let Some(version_id) = reverse_file_map.get(&FileId(m.file_id)) { + acc.entry(*version_id).or_default().push(hash); + } } - } - async move { Ok(acc) } - }) - .await?; + async move { Ok(acc) } + }) + .await?; - let dependencies : DashMap> = sqlx::query!( + let dependencies : DashMap> = sqlx::query!( " SELECT DISTINCT dependent_id as version_id, d.mod_dependency_id as dependency_project_id, d.dependency_id as dependency_version_id, d.dependency_file_name as file_name, d.dependency_type as dependency_type FROM dependencies d @@ -689,22 +695,22 @@ impl Version { ", &version_ids ).fetch(&mut *exec) - .try_fold(DashMap::new(), |acc : DashMap<_,Vec>, m| { - let dependency = QueryDependency { - project_id: m.dependency_project_id.map(ProjectId), - version_id: m.dependency_version_id.map(VersionId), - file_name: m.file_name, - dependency_type: m.dependency_type, - }; - - acc.entry(VersionId(m.version_id)) - .or_default() - .push(dependency); - async move { Ok(acc) } - } - ).await?; + .try_fold(DashMap::new(), |acc : DashMap<_,Vec>, m| { + let dependency = QueryDependency { + project_id: m.dependency_project_id.map(ProjectId), + version_id: m.dependency_version_id.map(VersionId), + file_name: m.file_name, + dependency_type: m.dependency_type, + }; + + acc.entry(VersionId(m.version_id)) + .or_default() + .push(dependency); + async move { Ok(acc) } + } + ).await?; - let res = sqlx::query!( + let res = sqlx::query!( " SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number, v.changelog changelog, v.date_published date_published, v.downloads downloads, @@ -714,96 +720,97 @@ impl Version { ", &version_ids ) - .fetch(&mut *exec) - .try_fold(DashMap::new(), |acc, v| { - let version_id = VersionId(v.id); - let VersionLoaderData { - loaders, - project_types, - games, - loader_loader_field_ids, - } = loaders_ptypes_games.remove(&version_id).map(|x|x.1).unwrap_or_default(); - let files = files.remove(&version_id).map(|x|x.1).unwrap_or_default(); - let hashes = hashes.remove(&version_id).map(|x|x.1).unwrap_or_default(); - let version_fields = version_fields.remove(&version_id).map(|x|x.1).unwrap_or_default(); - let dependencies = dependencies.remove(&version_id).map(|x|x.1).unwrap_or_default(); - - let loader_fields = loader_fields.iter() - .filter(|x| loader_loader_field_ids.contains(&x.id)) - .collect::>(); - - let query_version = QueryVersion { - inner: Version { - id: VersionId(v.id), - project_id: ProjectId(v.mod_id), - author_id: UserId(v.author_id), - name: v.version_name, - version_number: v.version_number, - changelog: v.changelog, - date_published: v.date_published, - downloads: v.downloads, - version_type: v.version_type, - featured: v.featured, - status: VersionStatus::from_string(&v.status), - requested_status: v.requested_status - .map(|x| VersionStatus::from_string(&x)), - ordering: v.ordering, - }, - files: { - let mut files = files.into_iter().map(|x| { - let mut file_hashes = HashMap::new(); - - for hash in hashes.iter() { - if hash.file_id == x.id { - file_hashes.insert( - hash.algorithm.clone(), - hash.hash.clone(), - ); + .fetch(&mut *exec) + .try_fold(DashMap::new(), |acc, v| { + let version_id = VersionId(v.id); + let VersionLoaderData { + loaders, + project_types, + games, + loader_loader_field_ids, + } = loaders_ptypes_games.remove(&version_id).map(|x|x.1).unwrap_or_default(); + let files = files.remove(&version_id).map(|x|x.1).unwrap_or_default(); + let hashes = hashes.remove(&version_id).map(|x|x.1).unwrap_or_default(); + let version_fields = version_fields.remove(&version_id).map(|x|x.1).unwrap_or_default(); + let dependencies = dependencies.remove(&version_id).map(|x|x.1).unwrap_or_default(); + + let loader_fields = loader_fields.iter() + .filter(|x| loader_loader_field_ids.contains(&x.id)) + .collect::>(); + + let query_version = QueryVersion { + inner: Version { + id: VersionId(v.id), + project_id: ProjectId(v.mod_id), + author_id: UserId(v.author_id), + name: v.version_name, + version_number: v.version_number, + changelog: v.changelog, + date_published: v.date_published, + downloads: v.downloads, + version_type: v.version_type, + featured: v.featured, + status: VersionStatus::from_string(&v.status), + requested_status: v.requested_status + .map(|x| VersionStatus::from_string(&x)), + ordering: v.ordering, + }, + files: { + let mut files = files.into_iter().map(|x| { + let mut file_hashes = HashMap::new(); + + for hash in hashes.iter() { + if hash.file_id == x.id { + file_hashes.insert( + hash.algorithm.clone(), + hash.hash.clone(), + ); + } } - } - - QueryFile { - id: x.id, - url: x.url.clone(), - filename: x.filename.clone(), - hashes: file_hashes, - primary: x.primary, - size: x.size, - file_type: x.file_type, - } - }).collect::>(); - - files.sort_by(|a, b| { - if a.primary { - Ordering::Less - } else if b.primary { - Ordering::Greater - } else { - a.filename.cmp(&b.filename) - } - }); - - files - }, - version_fields: VersionField::from_query_json(version_fields, &loader_fields, &loader_field_enum_values, false), - loaders, - project_types, - games, - dependencies, - }; - - acc.insert(v.id, query_version); - async move { Ok(acc) } - }) - .await?; - Ok(res) - }, - ).await?; + QueryFile { + id: x.id, + url: x.url.clone(), + filename: x.filename.clone(), + hashes: file_hashes, + primary: x.primary, + size: x.size, + file_type: x.file_type, + } + }).collect::>(); + + files.sort_by(|a, b| { + if a.primary { + Ordering::Less + } else if b.primary { + Ordering::Greater + } else { + a.filename.cmp(&b.filename) + } + }); + + files + }, + version_fields: VersionField::from_query_json(version_fields, &loader_fields, &loader_field_enum_values, false), + loaders, + project_types, + games, + dependencies, + }; + + acc.insert(v.id, query_version); + async move { Ok(acc) } + }) + .await?; - val.sort(); + Ok(res) + }, + ).await?; - Ok(val) + val.sort(); + + Ok(val) + } } pub async fn get_file_from_hash<'a, 'b, E>( @@ -814,7 +821,7 @@ impl Version { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync, { Self::get_files_from_hash(algo, &[hash], executor, redis) .await @@ -831,7 +838,7 @@ impl Version { redis: &RedisPool, ) -> Result, DatabaseError> where - E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy, + E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync, { let val = redis.get_cached_keys( VERSION_FILES_NAMESPACE, diff --git a/apps/labrinth/src/database/redis.rs b/apps/labrinth/src/database/redis.rs index a7ccb5970..69d9bd9b1 100644 --- a/apps/labrinth/src/database/redis.rs +++ b/apps/labrinth/src/database/redis.rs @@ -67,9 +67,9 @@ impl RedisPool { closure: F, ) -> Result, DatabaseError> where - F: FnOnce(Vec) -> Fut, - Fut: Future, DatabaseError>>, - T: Serialize + DeserializeOwned, + F: FnOnce(Vec) -> Fut + Send, + Fut: Future, DatabaseError>> + Send, + T: Serialize + DeserializeOwned + Send, K: Display + Hash + Eq @@ -77,7 +77,8 @@ impl RedisPool { + Clone + DeserializeOwned + Serialize - + Debug, + + Debug + + Send, { Ok(self .get_cached_keys_raw(namespace, keys, closure) @@ -94,9 +95,9 @@ impl RedisPool { closure: F, ) -> Result, DatabaseError> where - F: FnOnce(Vec) -> Fut, - Fut: Future, DatabaseError>>, - T: Serialize + DeserializeOwned, + F: FnOnce(Vec) -> Fut + Send, + Fut: Future, DatabaseError>> + Send, + T: Serialize + DeserializeOwned + Send, K: Display + Hash + Eq @@ -104,7 +105,8 @@ impl RedisPool { + Clone + DeserializeOwned + Serialize - + Debug, + + Debug + + Send, { self.get_cached_keys_raw_with_slug( namespace, @@ -131,18 +133,20 @@ impl RedisPool { closure: F, ) -> Result, DatabaseError> where - F: FnOnce(Vec) -> Fut, - Fut: Future, T)>, DatabaseError>>, - T: Serialize + DeserializeOwned, - I: Display + Hash + Eq + PartialEq + Clone + Debug, + F: FnOnce(Vec) -> Fut + Send, + Fut: Future, T)>, DatabaseError>> + + Send, + T: Serialize + DeserializeOwned + Send, + I: Display + Hash + Eq + PartialEq + Clone + Debug + Send, K: Display + Hash + Eq + PartialEq + Clone + DeserializeOwned - + Serialize, - S: Display + Clone + DeserializeOwned + Serialize + Debug, + + Serialize + + Send, + S: Display + Clone + DeserializeOwned + Serialize + Debug + Send, { Ok(self .get_cached_keys_raw_with_slug( @@ -167,18 +171,20 @@ impl RedisPool { closure: F, ) -> Result, DatabaseError> where - F: FnOnce(Vec) -> Fut, - Fut: Future, T)>, DatabaseError>>, - T: Serialize + DeserializeOwned, - I: Display + Hash + Eq + PartialEq + Clone + Debug, + F: FnOnce(Vec) -> Fut + Send, + Fut: Future, T)>, DatabaseError>> + + Send, + T: Serialize + DeserializeOwned + Send, + I: Display + Hash + Eq + PartialEq + Clone + Debug + Send, K: Display + Hash + Eq + PartialEq + Clone + DeserializeOwned - + Serialize, - S: Display + Clone + DeserializeOwned + Serialize + Debug, + + Serialize + + Send, + S: Display + Clone + DeserializeOwned + Serialize + Debug + Send, { let connection = self.connect().await?.connection; @@ -338,11 +344,11 @@ impl RedisPool { Pin< Box< dyn Future< - Output = Result< - HashMap>, - DatabaseError, - >, - >, + Output = Result< + HashMap>, + DatabaseError, + >, + > + Send, >, >, > = Vec::new(); @@ -547,23 +553,6 @@ impl RedisConnection { Ok(res) } - pub async fn get_many( - &mut self, - namespace: &str, - ids: &[String], - ) -> Result>, DatabaseError> { - let mut cmd = cmd("MGET"); - redis_args( - &mut cmd, - ids.iter() - .map(|x| format!("{}_{}:{}", self.meta_namespace, namespace, x)) - .collect::>() - .as_slice(), - ); - let res = redis_execute(&mut cmd, &mut self.connection).await?; - Ok(res) - } - pub async fn get_deserialized_from_json( &mut self, namespace: &str, @@ -578,22 +567,6 @@ impl RedisConnection { .and_then(|x| serde_json::from_str(&x).ok())) } - pub async fn get_many_deserialized_from_json( - &mut self, - namespace: &str, - ids: &[String], - ) -> Result>, DatabaseError> - where - R: for<'a> serde::Deserialize<'a>, - { - Ok(self - .get_many(namespace, ids) - .await? - .into_iter() - .map(|x| x.and_then(|val| serde_json::from_str::(&val).ok())) - .collect::>()) - } - pub async fn delete( &mut self, namespace: &str, diff --git a/apps/labrinth/src/lib.rs b/apps/labrinth/src/lib.rs index f54494147..88d459ffc 100644 --- a/apps/labrinth/src/lib.rs +++ b/apps/labrinth/src/lib.rs @@ -2,9 +2,9 @@ use std::num::NonZeroU32; use std::sync::Arc; use std::time::Duration; -use actix_web::web; use database::redis::RedisPool; use log::{info, warn}; +use ntex::{web, ServiceFactory}; use queue::{ analytics::AnalyticsQueue, payouts::PayoutsQueue, session::AuthQueue, socket::ActiveSockets, @@ -15,9 +15,11 @@ extern crate clickhouse as clickhouse_crate; use clickhouse_crate::Client; use governor::middleware::StateInformationMiddleware; use governor::{Quota, RateLimiter}; +use ntex::web::{App, DefaultError, ErrorRenderer, WebRequest}; use util::cors::default_cors; use crate::queue::moderation::AutomatedModerationQueue; +use crate::scheduler::schedule; use crate::util::ratelimit::KeyedRateLimiter; use crate::{ queue::payouts::process_payout, @@ -49,14 +51,13 @@ pub struct LabrinthConfig { pub clickhouse: Client, pub file_host: Arc, pub maxmind: Arc, - pub scheduler: Arc, pub ip_salt: Pepper, pub search_config: search::SearchConfig, - pub session_queue: web::Data, - pub payouts_queue: web::Data, + pub session_queue: Arc, + pub payouts_queue: Arc, pub analytics_queue: Arc, - pub active_sockets: web::Data, - pub automated_moderation_queue: web::Data, + pub active_sockets: Arc, + pub automated_moderation_queue: Arc, pub rate_limiter: KeyedRateLimiter, pub stripe_client: stripe::Client, } @@ -75,27 +76,25 @@ pub fn app_setup( ); let automated_moderation_queue = - web::Data::new(AutomatedModerationQueue::default()); + Arc::new(AutomatedModerationQueue::default()); { let automated_moderation_queue_ref = automated_moderation_queue.clone(); let pool_ref = pool.clone(); let redis_pool_ref = redis_pool.clone(); - actix_rt::spawn(async move { + tokio::task::spawn(async move { automated_moderation_queue_ref .task(pool_ref, redis_pool_ref) .await; }); } - let mut scheduler = scheduler::Scheduler::new(); - let limiter: KeyedRateLimiter = Arc::new( RateLimiter::keyed(Quota::per_minute(NonZeroU32::new(300).unwrap())) .with_middleware::(), ); let limiter_clone = Arc::clone(&limiter); - scheduler.run(Duration::from_secs(60), move || { + schedule(Duration::from_secs(60), move || { info!( "Clearing ratelimiter, storage size: {}", limiter_clone.len() @@ -118,18 +117,15 @@ pub fn app_setup( let pool_ref = pool.clone(); let search_config_ref = search_config.clone(); let redis_pool_ref = redis_pool.clone(); - scheduler.run(local_index_interval, move || { + schedule(local_index_interval, move || { let pool_ref = pool_ref.clone(); let redis_pool_ref = redis_pool_ref.clone(); let search_config_ref = search_config_ref.clone(); async move { info!("Indexing local database"); - let result = index_projects( - pool_ref, - redis_pool_ref.clone(), - &search_config_ref, - ) - .await; + let result = + index_projects(&pool_ref, &redis_pool_ref, &search_config_ref) + .await; if let Err(e) = result { warn!("Local project indexing failed: {:?}", e); } @@ -140,7 +136,7 @@ pub fn app_setup( // Changes statuses of scheduled projects/versions let pool_ref = pool.clone(); // TODO: Clear cache when these are run - scheduler.run(std::time::Duration::from_secs(60 * 5), move || { + schedule(std::time::Duration::from_secs(60 * 5), move || { let pool_ref = pool_ref.clone(); info!("Releasing scheduled versions/projects!"); @@ -157,7 +153,10 @@ pub fn app_setup( .await; if let Err(e) = projects_results { - warn!("Syncing scheduled releases for projects failed: {:?}", e); + warn!( + "Syncing scheduled releases for projects failed: {:?}", + e + ); } let versions_results = sqlx::query!( @@ -172,25 +171,24 @@ pub fn app_setup( .await; if let Err(e) = versions_results { - warn!("Syncing scheduled releases for versions failed: {:?}", e); + warn!( + "Syncing scheduled releases for versions failed: {:?}", + e + ); } info!("Finished releasing scheduled versions/projects"); } }); - scheduler::schedule_versions( - &mut scheduler, - pool.clone(), - redis_pool.clone(), - ); + scheduler::schedule_versions(pool.clone(), redis_pool.clone()); - let session_queue = web::Data::new(AuthQueue::new()); + let session_queue = Arc::new(AuthQueue::new()); let pool_ref = pool.clone(); let redis_ref = redis_pool.clone(); let session_queue_ref = session_queue.clone(); - scheduler.run(std::time::Duration::from_secs(60 * 30), move || { + schedule(std::time::Duration::from_secs(60 * 30), move || { let pool_ref = pool_ref.clone(); let redis_ref = redis_ref.clone(); let session_queue_ref = session_queue_ref.clone(); @@ -208,7 +206,7 @@ pub fn app_setup( let reader = maxmind.clone(); { let reader_ref = reader; - scheduler.run(std::time::Duration::from_secs(60 * 60 * 24), move || { + schedule(std::time::Duration::from_secs(60 * 60 * 24), move || { let reader_ref = reader_ref.clone(); async move { @@ -232,7 +230,7 @@ pub fn app_setup( let analytics_queue_ref = analytics_queue.clone(); let pool_ref = pool.clone(); let redis_ref = redis_pool.clone(); - scheduler.run(std::time::Duration::from_secs(15), move || { + schedule(std::time::Duration::from_secs(15), move || { let client_ref = client_ref.clone(); let analytics_queue_ref = analytics_queue_ref.clone(); let pool_ref = pool_ref.clone(); @@ -254,7 +252,7 @@ pub fn app_setup( { let pool_ref = pool.clone(); let client_ref = clickhouse.clone(); - scheduler.run(std::time::Duration::from_secs(60 * 60 * 6), move || { + schedule(std::time::Duration::from_secs(60 * 60 * 6), move || { let pool_ref = pool_ref.clone(); let client_ref = client_ref.clone(); @@ -276,7 +274,7 @@ pub fn app_setup( let redis_ref = redis_pool.clone(); let stripe_client_ref = stripe_client.clone(); - actix_rt::spawn(async move { + tokio::task::spawn(async move { routes::internal::billing::task( stripe_client_ref, pool_ref, @@ -290,7 +288,7 @@ pub fn app_setup( let pool_ref = pool.clone(); let redis_ref = redis_pool.clone(); - actix_rt::spawn(async move { + tokio::task::spawn(async move { routes::internal::billing::subscription_task(pool_ref, redis_ref) .await; }); @@ -301,8 +299,8 @@ pub fn app_setup( .to_string(), }; - let payouts_queue = web::Data::new(PayoutsQueue::new()); - let active_sockets = web::Data::new(ActiveSockets::default()); + let payouts_queue = Arc::new(PayoutsQueue::new()); + let active_sockets = Arc::new(ActiveSockets::default()); LabrinthConfig { pool, @@ -310,7 +308,6 @@ pub fn app_setup( clickhouse: clickhouse.clone(), file_host, maxmind, - scheduler: Arc::new(scheduler), ip_salt, search_config, session_queue, @@ -323,41 +320,25 @@ pub fn app_setup( } } -pub fn app_config( - cfg: &mut web::ServiceConfig, - labrinth_config: LabrinthConfig, -) { - cfg.app_data(web::FormConfig::default().error_handler(|err, _req| { - routes::ApiError::Validation(err.to_string()).into() - })) - .app_data(web::PathConfig::default().error_handler(|err, _req| { - routes::ApiError::Validation(err.to_string()).into() - })) - .app_data(web::QueryConfig::default().error_handler(|err, _req| { - routes::ApiError::Validation(err.to_string()).into() - })) - .app_data(web::JsonConfig::default().error_handler(|err, _req| { - routes::ApiError::Validation(err.to_string()).into() - })) - .app_data(web::Data::new(labrinth_config.redis_pool.clone())) - .app_data(web::Data::new(labrinth_config.pool.clone())) - .app_data(web::Data::new(labrinth_config.file_host.clone())) - .app_data(web::Data::new(labrinth_config.search_config.clone())) - .app_data(labrinth_config.session_queue.clone()) - .app_data(labrinth_config.payouts_queue.clone()) - .app_data(web::Data::new(labrinth_config.ip_salt.clone())) - .app_data(web::Data::new(labrinth_config.analytics_queue.clone())) - .app_data(web::Data::new(labrinth_config.clickhouse.clone())) - .app_data(web::Data::new(labrinth_config.maxmind.clone())) - .app_data(labrinth_config.active_sockets.clone()) - .app_data(labrinth_config.automated_moderation_queue.clone()) - .app_data(web::Data::new(labrinth_config.stripe_client.clone())) - .configure(routes::v2::config) - .configure(routes::v3::config) - .configure(routes::internal::config) - .configure(routes::root_config) - .default_service(web::get().wrap(default_cors()).to(routes::not_found)); -} +// TODO: fix me +// pub fn app_config( +// mut app: App, +// labrinth_config: LabrinthConfig, +// ) -> App where F: ServiceFactory> { +// app /*.app_data(web::FormConfig::default().error_handler(|err, _req| { +// routes::ApiError::Validation(err.to_string()).into() +// })) +// .app_data(web::PathConfig::default().error_handler(|err, _req| { +// routes::ApiError::Validation(err.to_string()).into() +// })) +// .app_data(web::QueryConfig::default().error_handler(|err, _req| { +// routes::ApiError::Validation(err.to_string()).into() +// })) +// .app_data(web::JsonConfig::default().error_handler(|err, _req| { +// routes::ApiError::Validation(err.to_string()).into() +// }))*/ +// +// } // This is so that env vars not used immediately don't panic at runtime pub fn check_env_vars() -> bool { diff --git a/apps/labrinth/src/main.rs b/apps/labrinth/src/main.rs index 336150c8f..363a0f5ce 100644 --- a/apps/labrinth/src/main.rs +++ b/apps/labrinth/src/main.rs @@ -1,5 +1,5 @@ -use actix_web::{App, HttpServer}; -use actix_web_prom::PrometheusMetricsBuilder; +use ntex::web::{App, HttpServer}; +// use actix_web_prom::PrometheusMetricsBuilder; use env_logger::Env; use labrinth::database::redis::RedisPool; use labrinth::file_hosting::S3Host; @@ -18,7 +18,7 @@ pub struct Pepper { pub pepper: String, } -#[actix_rt::main] +#[ntex::main] async fn main() -> std::io::Result<()> { dotenvy::dotenv().ok(); env_logger::Builder::from_env(Env::default().default_filter_or("info")) @@ -90,10 +90,10 @@ async fn main() -> std::io::Result<()> { let maxmind_reader = Arc::new(queue::maxmind::MaxMindIndexer::new().await.unwrap()); - let prometheus = PrometheusMetricsBuilder::new("labrinth") - .endpoint("/metrics") - .build() - .expect("Failed to create prometheus metrics middleware"); + // let prometheus = PrometheusMetricsBuilder::new("labrinth") + // .endpoint("/metrics") + // .build() + // .expect("Failed to create prometheus metrics middleware"); let search_config = search::SearchConfig::new(None); @@ -111,11 +111,29 @@ async fn main() -> std::io::Result<()> { // Init App HttpServer::new(move || { App::new() - .wrap(prometheus.clone()) + // .wrap(prometheus.clone()) .wrap(RateLimit(Arc::clone(&labrinth_config.rate_limiter))) - .wrap(actix_web::middleware::Compress::default()) - .wrap(sentry_actix::Sentry::new()) - .configure(|cfg| labrinth::app_config(cfg, labrinth_config.clone())) + .wrap(ntex::web::middleware::Compress::default()) + // .wrap(sentry_actix::Sentry::new()) + .state(labrinth_config.redis_pool.clone()) + .state(labrinth_config.pool.clone()) + .state(labrinth_config.file_host.clone()) + .state(labrinth_config.search_config.clone()) + .state(labrinth_config.session_queue.clone()) + .state(labrinth_config.payouts_queue.clone()) + .state(labrinth_config.ip_salt.clone()) + .state(labrinth_config.analytics_queue.clone()) + .state(labrinth_config.clickhouse.clone()) + .state(labrinth_config.maxmind.clone()) + .state(labrinth_config.active_sockets.clone()) + .state(labrinth_config.automated_moderation_queue.clone()) + .state(labrinth_config.stripe_client.clone()) + .configure(labrinth::routes::v2::config) + .configure(labrinth::routes::v3::config) + .configure(labrinth::routes::internal::config) + .configure(labrinth::routes::root_config) + // // TODO: fix me + .default_service(ntex::web::get()/*.wrap(default_cors())*/.to(labrinth::routes::not_found)) }) .bind(dotenvy::var("BIND_ADDR").unwrap())? .run() diff --git a/apps/labrinth/src/models/v2/projects.rs b/apps/labrinth/src/models/v2/projects.rs index a96d51707..84bd85ec4 100644 --- a/apps/labrinth/src/models/v2/projects.rs +++ b/apps/labrinth/src/models/v2/projects.rs @@ -1,7 +1,7 @@ use std::convert::TryFrom; use std::collections::HashMap; - +use std::future::Future; use super::super::ids::OrganizationId; use super::super::teams::TeamId; use super::super::users::UserId; @@ -226,30 +226,33 @@ impl LegacyProject { } // Because from needs a version_item, this is a helper function to get many from one db query. - pub async fn from_many<'a, E>( + #[allow(clippy::manual_async_fn)] + pub fn from_many<'a, 'c, E>( data: Vec, exec: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + redis: &'a RedisPool, + ) -> impl Future, DatabaseError>> + Send + 'a where - E: sqlx::Acquire<'a, Database = sqlx::Postgres>, + E: sqlx::Acquire<'c, Database = sqlx::Postgres> + Send + 'a, { - let version_ids: Vec<_> = data - .iter() - .filter_map(|p| p.versions.first().map(|i| (*i).into())) - .collect(); - let example_versions = - version_item::Version::get_many(&version_ids, exec, redis).await?; - let mut legacy_projects = Vec::new(); - for project in data { - let version_item = example_versions + async move { + let version_ids: Vec<_> = data .iter() - .find(|v| v.inner.project_id == project.id.into()) - .cloned(); - let project = LegacyProject::from(project, version_item); - legacy_projects.push(project); + .filter_map(|p| p.versions.first().map(|i| (*i).into())) + .collect(); + let example_versions = + version_item::Version::get_many(&version_ids, exec, redis).await?; + let mut legacy_projects = Vec::new(); + for project in data { + let version_item = example_versions + .iter() + .find(|v| v.inner.project_id == project.id.into()) + .cloned(); + let project = LegacyProject::from(project, version_item); + legacy_projects.push(project); + } + Ok(legacy_projects) } - Ok(legacy_projects) } } diff --git a/apps/labrinth/src/queue/socket.rs b/apps/labrinth/src/queue/socket.rs index c39c16b8c..9efaf5e4c 100644 --- a/apps/labrinth/src/queue/socket.rs +++ b/apps/labrinth/src/queue/socket.rs @@ -1,10 +1,9 @@ //! "Database" for Hydra use crate::models::users::{UserId, UserStatus}; -use actix_ws::Session; use dashmap::DashMap; pub struct ActiveSockets { - pub auth_sockets: DashMap, + pub auth_sockets: DashMap, } impl Default for ActiveSockets { diff --git a/apps/labrinth/src/routes/analytics.rs b/apps/labrinth/src/routes/analytics.rs index c8709d9e0..ec2898bf8 100644 --- a/apps/labrinth/src/routes/analytics.rs +++ b/apps/labrinth/src/routes/analytics.rs @@ -8,8 +8,8 @@ use crate::queue::session::AuthQueue; use crate::routes::ApiError; use crate::util::date::get_current_tenths_of_ms; use crate::util::env::parse_strings_from_var; -use actix_web::{post, web}; -use actix_web::{HttpRequest, HttpResponse}; +use ntex::web; +use ntex::web::{post, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; use std::collections::HashMap; @@ -48,18 +48,18 @@ pub struct UrlInput { #[post("view")] pub async fn page_view_ingest( req: HttpRequest, - maxmind: web::Data>, - analytics_queue: web::Data>, - session_queue: web::Data, - url_input: web::Json, - pool: web::Data, - redis: web::Data, + maxmind: web::types::State>, + analytics_queue: web::types::State>, + session_queue: web::types::State, + url_input: web::types::Json, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user = - get_user_from_headers(&req, &**pool, &redis, &session_queue, None) + get_user_from_headers(&req, &*pool, &redis, &session_queue, None) .await .ok(); - let conn_info = req.connection_info().peer_addr().map(|x| x.to_string()); + let conn_info = req.peer_addr().map(|x| x.to_string()); let url = Url::parse(&url_input.url).map_err(|_| { ApiError::InvalidInput("invalid page view URL specified!".to_string()) @@ -132,7 +132,7 @@ pub async fn page_view_ingest( if PROJECT_TYPES.contains(&segments_vec[0]) { let project = crate::database::models::Project::get( segments_vec[1], - &**pool, + &*pool, &redis, ) .await?; @@ -164,17 +164,17 @@ pub struct PlaytimeInput { #[post("playtime")] pub async fn playtime_ingest( req: HttpRequest, - analytics_queue: web::Data>, - session_queue: web::Data, - playtime_input: web::Json< + analytics_queue: web::types::State>, + session_queue: web::types::State, + playtime_input: web::types::Json< HashMap, >, - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { let (_, user) = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PERFORM_ANALYTICS]), @@ -191,7 +191,7 @@ pub async fn playtime_ingest( let versions = crate::database::models::Version::get_many( &playtimes.iter().map(|x| (*x.0).into()).collect::>(), - &**pool, + &*pool, &redis, ) .await?; diff --git a/apps/labrinth/src/routes/index.rs b/apps/labrinth/src/routes/index.rs index 8e332fe33..921573153 100644 --- a/apps/labrinth/src/routes/index.rs +++ b/apps/labrinth/src/routes/index.rs @@ -1,4 +1,4 @@ -use actix_web::{get, HttpResponse}; +use ntex::web::{get, HttpResponse}; use serde_json::json; #[get("/")] @@ -10,5 +10,5 @@ pub async fn index_get() -> HttpResponse { "about": "Welcome traveler!" }); - HttpResponse::Ok().json(data) + HttpResponse::Ok().json(&data) } diff --git a/apps/labrinth/src/routes/internal/admin.rs b/apps/labrinth/src/routes/internal/admin.rs index 68987d1da..01d468347 100644 --- a/apps/labrinth/src/routes/internal/admin.rs +++ b/apps/labrinth/src/routes/internal/admin.rs @@ -9,8 +9,8 @@ use crate::queue::session::AuthQueue; use crate::routes::ApiError; use crate::search::SearchConfig; use crate::util::date::get_current_tenths_of_ms; -use crate::util::guards::admin_key_guard; -use actix_web::{patch, post, web, HttpRequest, HttpResponse}; +// use crate::util::guards::admin_key_guard; +use ntex::web::{self, patch, post, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; use std::collections::HashMap; @@ -36,16 +36,18 @@ pub struct DownloadBody { } // This is an internal route, cannot be used without key -#[patch("/_count-download", guard = "admin_key_guard")] +#[patch("/_count-download")] +// TODO: fix me +// #[patch("/_count-download", guard = "admin_key_guard")] #[allow(clippy::too_many_arguments)] pub async fn count_download( req: HttpRequest, - pool: web::Data, - redis: web::Data, - maxmind: web::Data>, - analytics_queue: web::Data>, - session_queue: web::Data, - download_body: web::Json, + pool: web::types::State, + redis: web::types::State, + maxmind: web::types::State>, + analytics_queue: web::types::State>, + session_queue: web::types::State, + download_body: web::types::Json, ) -> Result { let token = download_body .headers @@ -56,7 +58,7 @@ pub async fn count_download( let user = get_user_record_from_bearer_token( &req, token, - &**pool, + &*pool, &redis, &session_queue, ) @@ -81,7 +83,7 @@ pub async fn count_download( ", download_body.url, ) - .fetch_optional(pool.as_ref()) + .fetch_optional(&*pool) .await? { (version.id, version.mod_id) @@ -94,7 +96,7 @@ pub async fn count_download( project_id as crate::database::models::ids::ProjectId, id_option ) - .fetch_optional(pool.as_ref()) + .fetch_optional(&*pool) .await? { (version.id, version.mod_id) @@ -147,14 +149,16 @@ pub async fn count_download( Ok(HttpResponse::NoContent().body("")) } -#[post("/_force_reindex", guard = "admin_key_guard")] +#[post("/_force_reindex")] +// TODO: fix me +// #[post("/_force_reindex", guard = "admin_key_guard")] pub async fn force_reindex( - pool: web::Data, - redis: web::Data, - config: web::Data, + pool: web::types::State, + redis: web::types::State, + config: web::types::State, ) -> Result { use crate::search::indexing::index_projects; let redis = redis.get_ref(); - index_projects(pool.as_ref().clone(), redis.clone(), &config).await?; + index_projects(&*pool, &redis, &config).await?; Ok(HttpResponse::NoContent().finish()) } diff --git a/apps/labrinth/src/routes/internal/billing.rs b/apps/labrinth/src/routes/internal/billing.rs index 38a130c59..9236590df 100644 --- a/apps/labrinth/src/routes/internal/billing.rs +++ b/apps/labrinth/src/routes/internal/billing.rs @@ -15,9 +15,9 @@ use crate::models::pats::Scopes; use crate::models::users::Badges; use crate::queue::session::AuthQueue; use crate::routes::ApiError; -use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse}; use chrono::Utc; use log::{info, warn}; +use ntex::web::{self, delete, get, patch, post, HttpRequest, HttpResponse}; use rust_decimal::prelude::ToPrimitive; use rust_decimal::Decimal; use serde::Serialize; @@ -56,10 +56,10 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("products")] pub async fn products( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { - let products = product_item::QueryProduct::list(&**pool, &redis).await?; + let products = product_item::QueryProduct::list(&*pool, &redis).await?; let products = products .into_iter() @@ -80,19 +80,19 @@ pub async fn products( }) .collect::>(); - Ok(HttpResponse::Ok().json(products)) + Ok(HttpResponse::Ok().json(&products)) } #[get("subscriptions")] pub async fn subscriptions( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -103,14 +103,14 @@ pub async fn subscriptions( let subscriptions = user_subscription_item::UserSubscriptionItem::get_all_user( user.id.into(), - &**pool, + &*pool, ) .await? .into_iter() .map(UserSubscription::from) .collect::>(); - Ok(HttpResponse::Ok().json(subscriptions)) + Ok(HttpResponse::Ok().json(&subscriptions)) } #[derive(Deserialize)] @@ -130,16 +130,16 @@ pub struct ChargeRefund { #[post("charge/{id}/refund")] pub async fn refund_charge( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - info: web::Path<(crate::models::ids::ChargeId,)>, - body: web::Json, - stripe_client: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + info: web::types::Path<(crate::models::ids::ChargeId,)>, + body: web::types::Json, + stripe_client: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -155,8 +155,8 @@ pub async fn refund_charge( )); } - if let Some(charge) = ChargeItem::get(id.into(), &**pool).await? { - let refunds = ChargeItem::get_children(id.into(), &**pool).await?; + if let Some(charge) = ChargeItem::get(id.into(), &*pool).await? { + let refunds = ChargeItem::get_children(id.into(), &*pool).await?; let refunds = -refunds .into_iter() .filter_map(|x| match x.status { @@ -259,7 +259,7 @@ pub async fn refund_charge( if body.0.unprovision.unwrap_or(false) { if let Some(subscription_id) = charge.subscription_id { let open_charge = - ChargeItem::get_open_subscription(subscription_id, &**pool) + ChargeItem::get_open_subscription(subscription_id, &*pool) .await?; if let Some(mut open_charge) = open_charge { open_charge.status = ChargeStatus::Cancelled; @@ -287,16 +287,16 @@ pub struct SubscriptionEdit { #[patch("subscription/{id}")] pub async fn edit_subscription( req: HttpRequest, - info: web::Path<(crate::models::ids::UserSubscriptionId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - edit_subscription: web::Json, - stripe_client: web::Data, + info: web::types::Path<(crate::models::ids::UserSubscriptionId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + edit_subscription: web::types::Json, + stripe_client: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -307,7 +307,7 @@ pub async fn edit_subscription( let (id,) = info.into_inner(); if let Some(subscription) = - user_subscription_item::UserSubscriptionItem::get(id.into(), &**pool) + user_subscription_item::UserSubscriptionItem::get(id.into(), &*pool) .await? { if subscription.user_id != user.id.into() && !user.role.is_admin() { @@ -526,7 +526,7 @@ pub async fn edit_subscription( transaction.commit().await?; if let Some((amount, tax, payment_intent)) = intent { - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "payment_intent_id": payment_intent.id, "client_secret": payment_intent.client_secret, "tax": tax, @@ -543,14 +543,14 @@ pub async fn edit_subscription( #[get("customer")] pub async fn user_customer( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - stripe_client: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + stripe_client: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -570,19 +570,19 @@ pub async fn user_customer( let customer = stripe::Customer::retrieve(&stripe_client, &customer_id, &[]).await?; - Ok(HttpResponse::Ok().json(customer)) + Ok(HttpResponse::Ok().json(&customer)) } #[get("payments")] pub async fn charges( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -593,12 +593,12 @@ pub async fn charges( let charges = crate::database::models::charge_item::ChargeItem::get_from_user( user.id.into(), - &**pool, + &*pool, ) .await?; Ok(HttpResponse::Ok().json( - charges + &charges .into_iter() .map(|x| Charge { id: x.id.into(), @@ -621,14 +621,14 @@ pub async fn charges( #[post("payment_method")] pub async fn add_payment_method_flow( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - stripe_client: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + stripe_client: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -661,7 +661,7 @@ pub async fn add_payment_method_flow( ) .await?; - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "client_secret": intent.client_secret }))) } @@ -674,15 +674,15 @@ pub struct EditPaymentMethod { #[patch("payment_method/{id}")] pub async fn edit_payment_method( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - stripe_client: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + stripe_client: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -743,15 +743,15 @@ pub async fn edit_payment_method( #[delete("payment_method/{id}")] pub async fn remove_payment_method( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - stripe_client: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + stripe_client: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -787,7 +787,7 @@ pub async fn remove_payment_method( let user_subscriptions = user_subscription_item::UserSubscriptionItem::get_all_user( user.id.into(), - &**pool, + &*pool, ) .await?; @@ -831,14 +831,14 @@ pub async fn remove_payment_method( #[get("payment_methods")] pub async fn payment_methods( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - stripe_client: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + stripe_client: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -861,7 +861,7 @@ pub async fn payment_methods( ) .await?; - Ok(HttpResponse::Ok().json(methods.data)) + Ok(HttpResponse::Ok().json(&methods.data)) } else { Ok(HttpResponse::NoContent().finish()) } @@ -875,8 +875,8 @@ pub struct ActiveServersQuery { #[get("active_servers")] pub async fn active_servers( req: HttpRequest, - pool: web::Data, - query: web::Query, + pool: web::types::State, + query: web::types::Query, ) -> Result { let master_key = dotenvy::var("PYRO_API_KEY")?; @@ -894,7 +894,7 @@ pub async fn active_servers( let servers = user_subscription_item::UserSubscriptionItem::get_all_servers( query.subscription_status, - &**pool, + &*pool, ) .await?; @@ -918,7 +918,7 @@ pub async fn active_servers( }) .collect::>(); - Ok(HttpResponse::Ok().json(server_ids)) + Ok(HttpResponse::Ok().json(&server_ids)) } #[derive(Deserialize)] @@ -1021,15 +1021,15 @@ fn infer_currency_code(country: &str) -> String { #[post("payment")] pub async fn initiate_payment( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - stripe_client: web::Data, - payment_request: web::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + stripe_client: web::types::State, + payment_request: web::types::Json, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -1109,7 +1109,7 @@ pub async fn initiate_payment( let charge = crate::database::models::charge_item::ChargeItem::get( id.into(), - &**pool, + &*pool, ) .await? .ok_or_else(|| { @@ -1131,7 +1131,7 @@ pub async fn initiate_payment( interval, } => { let product = - product_item::ProductItem::get(product_id.into(), &**pool) + product_item::ProductItem::get(product_id.into(), &*pool) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -1142,7 +1142,7 @@ pub async fn initiate_payment( let mut product_prices = product_item::ProductPriceItem::get_all_product_prices( - product.id, &**pool, + product.id, &*pool, ) .await?; @@ -1184,7 +1184,7 @@ pub async fn initiate_payment( let user_subscriptions = user_subscription_item::UserSubscriptionItem::get_all_user( user.id.into(), - &**pool, + &*pool, ) .await?; @@ -1198,7 +1198,7 @@ pub async fn initiate_payment( }) .map(|x| x.price_id) .collect::>(), - &**pool, + &*pool, ) .await?; @@ -1259,7 +1259,7 @@ pub async fn initiate_payment( ) .await?; - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "price_id": to_base62(price_id.0 as u64), "tax": 0, "total": price, @@ -1325,7 +1325,7 @@ pub async fn initiate_payment( let payment_intent = stripe::PaymentIntent::create(&stripe_client, intent).await?; - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "payment_intent_id": payment_intent.id, "client_secret": payment_intent.client_secret, "price_id": to_base62(price_id.0 as u64), @@ -1340,9 +1340,9 @@ pub async fn initiate_payment( pub async fn stripe_webhook( req: HttpRequest, payload: String, - pool: web::Data, - redis: web::Data, - stripe_client: web::Data, + pool: web::types::State, + redis: web::types::State, + stripe_client: web::types::State, ) -> Result { let stripe_signature = req .headers() @@ -1716,7 +1716,7 @@ pub async fn stripe_webhook( let minecraft_versions = crate::database::models::legacy_loader_fields::MinecraftGameVersion::list( Some("release"), None, - &**pool, + &*pool, &redis, ).await?; diff --git a/apps/labrinth/src/routes/internal/flows.rs b/apps/labrinth/src/routes/internal/flows.rs index d0f830609..e41ce3775 100644 --- a/apps/labrinth/src/routes/internal/flows.rs +++ b/apps/labrinth/src/routes/internal/flows.rs @@ -16,12 +16,12 @@ use crate::util::env::parse_strings_from_var; use crate::util::ext::get_image_ext; use crate::util::img::upload_image_optimized; use crate::util::validate::{validation_errors_to_string, RE_URL_SAFE}; -use actix_web::web::{scope, Data, Query, ServiceConfig}; -use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse}; use argon2::password_hash::SaltString; use argon2::{Argon2, PasswordHash, PasswordHasher, PasswordVerifier}; use base64::Engine; use chrono::{Duration, Utc}; +use ntex::web::{self, delete, get, patch, post, HttpRequest, HttpResponse}; +use ntex::web::{scope, ServiceConfig}; use rand_chacha::rand_core::SeedableRng; use rand_chacha::ChaCha20Rng; use reqwest::header::AUTHORIZATION; @@ -1052,10 +1052,10 @@ pub struct Authorization { #[get("init")] pub async fn init( req: HttpRequest, - Query(info): Query, // callback url - client: Data, - redis: Data, - session_queue: Data, + web::types::Query(info): web::types::Query, // callback url + client: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let url = url::Url::parse(&info.url).map_err(|_| AuthenticationError::Url)?; @@ -1073,7 +1073,7 @@ pub async fn init( let (_, user) = get_user_record_from_bearer_token( &req, Some(&token), - &**client, + &*client, &redis, &session_queue, ) @@ -1095,17 +1095,17 @@ pub async fn init( let url = info.provider.get_redirect_url(state)?; Ok(HttpResponse::TemporaryRedirect() - .append_header(("Location", &*url)) - .json(serde_json::json!({ "url": url }))) + .header("Location", &*url) + .json(&serde_json::json!({ "url": url }))) } #[get("callback")] pub async fn auth_callback( req: HttpRequest, - Query(query): Query>, - client: Data, - file_host: Data>, - redis: Data, + web::types::Query(query): web::types::Query>, + client: web::types::State, + file_host: web::types::State>, + redis: web::types::State, ) -> Result { let state_string = query .get("state") @@ -1128,7 +1128,7 @@ pub async fn auth_callback( let token = provider.get_token(query).await?; let oauth_user = provider.get_user(&token).await?; - let user_id_opt = provider.get_user_id(&oauth_user.id, &**client).await?; + let user_id_opt = provider.get_user_id(&oauth_user.id, &*client).await?; let mut transaction = client.begin().await?; if let Some(id) = user_id { @@ -1140,7 +1140,7 @@ pub async fn auth_callback( .update_user_id(id, Some(&oauth_user.id), &mut transaction) .await?; - let user = crate::database::models::User::get_id(id, &**client, &redis).await?; + let user = crate::database::models::User::get_id(id, &*client, &redis).await?; if provider == AuthProvider::PayPal { sqlx::query!( @@ -1170,11 +1170,11 @@ pub async fn auth_callback( crate::database::models::User::clear_caches(&[(id, None)], &redis).await?; Ok(HttpResponse::TemporaryRedirect() - .append_header(("Location", &*url)) - .json(serde_json::json!({ "url": url }))) + .header("Location", &*url) + .json(&serde_json::json!({ "url": url }))) } else { let user_id = if let Some(user_id) = user_id_opt { - let user = crate::database::models::User::get_id(user_id, &**client, &redis) + let user = crate::database::models::User::get_id(user_id, &*client, &redis) .await? .ok_or_else(|| AuthenticationError::InvalidCredentials)?; @@ -1191,8 +1191,8 @@ pub async fn auth_callback( ); return Ok(HttpResponse::TemporaryRedirect() - .append_header(("Location", &*redirect_url)) - .json(serde_json::json!({ "url": redirect_url }))); + .header("Location", &*redirect_url) + .json(&serde_json::json!({ "url": redirect_url }))); } user_id @@ -1216,8 +1216,8 @@ pub async fn auth_callback( ); Ok(HttpResponse::TemporaryRedirect() - .append_header(("Location", &*redirect_url)) - .json(serde_json::json!({ "url": redirect_url }))) + .header("Location", &*redirect_url) + .json(&serde_json::json!({ "url": redirect_url }))) } } else { Err::(AuthenticationError::InvalidCredentials) @@ -1235,14 +1235,14 @@ pub struct DeleteAuthProvider { #[delete("provider")] pub async fn delete_auth_provider( req: HttpRequest, - pool: Data, - redis: Data, - delete_provider: web::Json, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + delete_provider: web::types::Json, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_AUTH_WRITE]), @@ -1328,9 +1328,9 @@ pub struct NewAccount { #[post("create")] pub async fn create_account_with_password( req: HttpRequest, - pool: Data, - redis: Data, - new_account: web::Json, + pool: web::types::State, + redis: web::types::State, + new_account: web::types::Json, ) -> Result { new_account.0.validate().map_err(|err| { ApiError::InvalidInput(validation_errors_to_string(err, None)) @@ -1340,13 +1340,9 @@ pub async fn create_account_with_password( return Err(ApiError::Turnstile); } - if crate::database::models::User::get( - &new_account.username, - &**pool, - &redis, - ) - .await? - .is_some() + if crate::database::models::User::get(&new_account.username, &*pool, &redis) + .await? + .is_some() { return Err(ApiError::InvalidInput("Username is taken!".to_string())); } @@ -1381,7 +1377,7 @@ pub async fn create_account_with_password( .hash_password(new_account.password.as_bytes(), &salt)? .to_string(); - if crate::database::models::User::get_email(&new_account.email, &**pool) + if crate::database::models::User::get_email(&new_account.email, &*pool) .await? .is_some() { @@ -1441,7 +1437,7 @@ pub async fn create_account_with_password( transaction.commit().await?; - Ok(HttpResponse::Ok().json(res)) + Ok(HttpResponse::Ok().json(&res)) } #[derive(Deserialize, Validate)] @@ -1454,26 +1450,26 @@ pub struct Login { #[post("login")] pub async fn login_password( req: HttpRequest, - pool: Data, - redis: Data, - login: web::Json, + pool: web::types::State, + redis: web::types::State, + login: web::types::Json, ) -> Result { if !check_hcaptcha(&req, &login.challenge).await? { return Err(ApiError::Turnstile); } let user = if let Some(user) = - crate::database::models::User::get(&login.username, &**pool, &redis) + crate::database::models::User::get(&login.username, &*pool, &redis) .await? { user } else { let user = - crate::database::models::User::get_email(&login.username, &**pool) + crate::database::models::User::get_email(&login.username, &*pool) .await? .ok_or_else(|| AuthenticationError::InvalidCredentials)?; - crate::database::models::User::get_id(user, &**pool, &redis) + crate::database::models::User::get_id(user, &*pool, &redis) .await? .ok_or_else(|| AuthenticationError::InvalidCredentials)? }; @@ -1495,7 +1491,7 @@ pub async fn login_password( .insert(Duration::minutes(30), &redis) .await?; - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "error": "2fa_required", "description": "2FA is required to complete this operation.", "flow": flow, @@ -1507,7 +1503,7 @@ pub async fn login_password( let res = crate::models::sessions::Session::from(session, true, None); transaction.commit().await?; - Ok(HttpResponse::Ok().json(res)) + Ok(HttpResponse::Ok().json(&res)) } } @@ -1599,9 +1595,9 @@ async fn validate_2fa_code( #[post("login/2fa")] pub async fn login_2fa( req: HttpRequest, - pool: Data, - redis: Data, - login: web::Json, + pool: web::types::State, + redis: web::types::State, + login: web::types::Json, ) -> Result { let flow = Flow::get(&login.flow, &redis) .await? @@ -1609,7 +1605,7 @@ pub async fn login_2fa( if let Flow::Login2FA { user_id } = flow { let user = - crate::database::models::User::get_id(user_id, &**pool, &redis) + crate::database::models::User::get_id(user_id, &*pool, &redis) .await? .ok_or_else(|| AuthenticationError::InvalidCredentials)?; @@ -1637,7 +1633,7 @@ pub async fn login_2fa( let res = crate::models::sessions::Session::from(session, true, None); transaction.commit().await?; - Ok(HttpResponse::Ok().json(res)) + Ok(HttpResponse::Ok().json(&res)) } else { Err(ApiError::Authentication( AuthenticationError::InvalidCredentials, @@ -1648,13 +1644,13 @@ pub async fn login_2fa( #[post("2fa/get_secret")] pub async fn begin_2fa_flow( req: HttpRequest, - pool: Data, - redis: Data, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_AUTH_WRITE]), @@ -1673,7 +1669,7 @@ pub async fn begin_2fa_flow( .insert(Duration::minutes(30), &redis) .await?; - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "secret": encoded.to_string(), "flow": flow, }))) @@ -1687,10 +1683,10 @@ pub async fn begin_2fa_flow( #[post("2fa")] pub async fn finish_2fa_flow( req: HttpRequest, - pool: Data, - redis: Data, - login: web::Json, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + login: web::types::Json, + session_queue: web::types::State, ) -> Result { let flow = Flow::get(&login.flow, &redis) .await? @@ -1699,7 +1695,7 @@ pub async fn finish_2fa_flow( if let Flow::Initialize2FA { user_id, secret } = flow { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_AUTH_WRITE]), @@ -1796,7 +1792,7 @@ pub async fn finish_2fa_flow( ) .await?; - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "backup_codes": codes, }))) } else { @@ -1814,15 +1810,15 @@ pub struct Remove2FA { #[delete("2fa")] pub async fn remove_2fa( req: HttpRequest, - pool: Data, - redis: Data, - login: web::Json, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + login: web::types::Json, + session_queue: web::types::State, ) -> Result { let (scopes, user) = get_user_record_from_bearer_token( &req, None, - &**pool, + &*pool, &redis, &session_queue, ) @@ -1904,9 +1900,9 @@ pub struct ResetPassword { #[post("password/reset")] pub async fn reset_password_begin( req: HttpRequest, - pool: Data, - redis: Data, - reset_password: web::Json, + pool: web::types::State, + redis: web::types::State, + reset_password: web::types::Json, ) -> Result { if !check_hcaptcha(&req, &reset_password.challenge).await? { return Err(ApiError::Turnstile); @@ -1914,15 +1910,15 @@ pub async fn reset_password_begin( let user = if let Some(user_id) = crate::database::models::User::get_email( &reset_password.username, - &**pool, + &*pool, ) .await? { - crate::database::models::User::get_id(user_id, &**pool, &redis).await? + crate::database::models::User::get_id(user_id, &*pool, &redis).await? } else { crate::database::models::User::get( &reset_password.username, - &**pool, + &*pool, &redis, ) .await? @@ -1957,17 +1953,17 @@ pub struct ChangePassword { #[patch("password")] pub async fn change_password( req: HttpRequest, - pool: Data, - redis: Data, - change_password: web::Json, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + change_password: web::types::Json, + session_queue: web::types::State, ) -> Result { let user = if let Some(flow) = &change_password.flow { let flow = Flow::get(flow, &redis).await?; if let Some(Flow::ForgotPassword { user_id }) = flow { let user = - crate::database::models::User::get_id(user_id, &**pool, &redis) + crate::database::models::User::get_id(user_id, &*pool, &redis) .await? .ok_or_else(|| AuthenticationError::InvalidCredentials)?; @@ -1985,7 +1981,7 @@ pub async fn change_password( let (scopes, user) = get_user_record_from_bearer_token( &req, None, - &**pool, + &*pool, &redis, &session_queue, ) @@ -2108,11 +2104,11 @@ pub struct SetEmail { #[patch("email")] pub async fn set_email( req: HttpRequest, - pool: Data, - redis: Data, - email: web::Json, - session_queue: Data, - stripe_client: Data, + pool: web::types::State, + redis: web::types::State, + email: web::types::Json, + session_queue: web::types::State, + stripe_client: web::types::State, ) -> Result { email.0.validate().map_err(|err| { ApiError::InvalidInput(validation_errors_to_string(err, None)) @@ -2120,7 +2116,7 @@ pub async fn set_email( let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_AUTH_WRITE]), @@ -2194,13 +2190,13 @@ pub async fn set_email( #[post("email/resend_verify")] pub async fn resend_verify_email( req: HttpRequest, - pool: Data, - redis: Data, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_AUTH_WRITE]), @@ -2243,9 +2239,9 @@ pub struct VerifyEmail { #[post("email/verify")] pub async fn verify_email( - pool: Data, - redis: Data, - email: web::Json, + pool: web::types::State, + redis: web::types::State, + email: web::types::Json, ) -> Result { let flow = Flow::get(&email.flow, &redis).await?; @@ -2255,7 +2251,7 @@ pub async fn verify_email( }) = flow { let user = - crate::database::models::User::get_id(user_id, &**pool, &redis) + crate::database::models::User::get_id(user_id, &*pool, &redis) .await? .ok_or_else(|| AuthenticationError::InvalidCredentials)?; @@ -2296,13 +2292,13 @@ pub async fn verify_email( #[post("email/subscribe")] pub async fn subscribe_newsletter( req: HttpRequest, - pool: Data, - redis: Data, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_AUTH_WRITE]), diff --git a/apps/labrinth/src/routes/internal/gdpr.rs b/apps/labrinth/src/routes/internal/gdpr.rs index 6f1d3e611..a709a461c 100644 --- a/apps/labrinth/src/routes/internal/gdpr.rs +++ b/apps/labrinth/src/routes/internal/gdpr.rs @@ -3,7 +3,7 @@ use crate::database::redis::RedisPool; use crate::models::pats::Scopes; use crate::queue::session::AuthQueue; use crate::routes::ApiError; -use actix_web::{post, web, HttpRequest, HttpResponse}; +use ntex::web::{self, post, HttpRequest, HttpResponse}; use sqlx::PgPool; pub fn config(cfg: &mut web::ServiceConfig) { @@ -13,13 +13,13 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[post("/export")] pub async fn export( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -30,11 +30,10 @@ pub async fn export( let user_id = user.id.into(); let collection_ids = - crate::database::models::User::get_collections(user_id, &**pool) - .await?; + crate::database::models::User::get_collections(user_id, &*pool).await?; let collections = crate::database::models::Collection::get_many( &collection_ids, - &**pool, + &*pool, &redis, ) .await? @@ -42,25 +41,25 @@ pub async fn export( .map(crate::models::collections::Collection::from) .collect::>(); - let follows = crate::database::models::User::get_follows(user_id, &**pool) + let follows = crate::database::models::User::get_follows(user_id, &*pool) .await? .into_iter() .map(crate::models::ids::ProjectId::from) .collect::>(); let projects = - crate::database::models::User::get_projects(user_id, &**pool, &redis) + crate::database::models::User::get_projects(user_id, &*pool, &redis) .await? .into_iter() .map(crate::models::ids::ProjectId::from) .collect::>(); let org_ids = - crate::database::models::User::get_organizations(user_id, &**pool) + crate::database::models::User::get_organizations(user_id, &*pool) .await?; let orgs = crate::database::models::organization_item::Organization::get_many_ids( - &org_ids, &**pool, &redis, + &org_ids, &*pool, &redis, ) .await? .into_iter() @@ -69,7 +68,7 @@ pub async fn export( .collect::>(); let notifs = crate::database::models::notification_item::Notification::get_many_user( - user_id, &**pool, &redis, + user_id, &*pool, &redis, ) .await? .into_iter() @@ -78,7 +77,7 @@ pub async fn export( let oauth_clients = crate::database::models::oauth_client_item::OAuthClient::get_all_user_clients( - user_id, &**pool, + user_id, &*pool, ) .await? .into_iter() @@ -86,7 +85,7 @@ pub async fn export( .collect::>(); let oauth_authorizations = crate::database::models::oauth_client_authorization_item::OAuthClientAuthorization::get_all_for_user( - user_id, &**pool, + user_id, &*pool, ) .await? .into_iter() @@ -95,12 +94,12 @@ pub async fn export( let pat_ids = crate::database::models::pat_item::PersonalAccessToken::get_user_pats( - user_id, &**pool, &redis, + user_id, &*pool, &redis, ) .await?; let pats = crate::database::models::pat_item::PersonalAccessToken::get_many_ids( - &pat_ids, &**pool, &redis, + &pat_ids, &*pool, &redis, ) .await? .into_iter() @@ -109,13 +108,13 @@ pub async fn export( let payout_ids = crate::database::models::payout_item::Payout::get_all_for_user( - user_id, &**pool, + user_id, &*pool, ) .await?; let payouts = crate::database::models::payout_item::Payout::get_many( &payout_ids, - &**pool, + &*pool, ) .await? .into_iter() @@ -123,11 +122,11 @@ pub async fn export( .collect::>(); let report_ids = - crate::database::models::user_item::User::get_reports(user_id, &**pool) + crate::database::models::user_item::User::get_reports(user_id, &*pool) .await?; let reports = crate::database::models::report_item::Report::get_many( &report_ids, - &**pool, + &*pool, ) .await? .into_iter() @@ -140,7 +139,7 @@ pub async fn export( ", user_id.0 ) - .fetch_all(pool.as_ref()) + .fetch_all(&*pool) .await? .into_iter() .map(|x| crate::database::models::ids::ThreadMessageId(x.id)) @@ -149,7 +148,7 @@ pub async fn export( let messages = crate::database::models::thread_item::ThreadMessage::get_many( &message_ids, - &**pool, + &*pool, ) .await? .into_iter() @@ -160,7 +159,7 @@ pub async fn export( "SELECT id FROM uploaded_images WHERE owner_id = $1", user_id.0 ) - .fetch_all(pool.as_ref()) + .fetch_all(&*pool) .await? .into_iter() .map(|x| crate::database::models::ids::ImageId(x.id)) @@ -168,7 +167,7 @@ pub async fn export( let uploaded_images = crate::database::models::image_item::Image::get_many( &uploaded_images_ids, - &**pool, + &*pool, &redis, ) .await? @@ -178,14 +177,14 @@ pub async fn export( let subscriptions = crate::database::models::user_subscription_item::UserSubscriptionItem::get_all_user( - user_id, &**pool, + user_id, &*pool, ) .await? .into_iter() .map(crate::models::billing::UserSubscription::from) .collect::>(); - Ok(HttpResponse::Ok().json(serde_json::json!({ + Ok(HttpResponse::Ok().json(&serde_json::json!({ "user": user, "collections": collections, "follows": follows, diff --git a/apps/labrinth/src/routes/internal/mod.rs b/apps/labrinth/src/routes/internal/mod.rs index 7e61fe798..da450e0f0 100644 --- a/apps/labrinth/src/routes/internal/mod.rs +++ b/apps/labrinth/src/routes/internal/mod.rs @@ -12,9 +12,9 @@ use super::v3::oauth_clients; pub use super::ApiError; use crate::util::cors::default_cors; -pub fn config(cfg: &mut actix_web::web::ServiceConfig) { +pub fn config(cfg: &mut ntex::web::ServiceConfig) { cfg.service( - actix_web::web::scope("_internal") + ntex::web::scope("_internal") .wrap(default_cors()) .configure(admin::config) .configure(oauth_clients::config) @@ -23,7 +23,6 @@ pub fn config(cfg: &mut actix_web::web::ServiceConfig) { .configure(pats::config) .configure(moderation::config) .configure(billing::config) - .configure(gdpr::config) - .configure(statuses::config), + .configure(gdpr::config), // .configure(statuses::config), ); } diff --git a/apps/labrinth/src/routes/internal/moderation.rs b/apps/labrinth/src/routes/internal/moderation.rs index 9f59e738e..1755a493a 100644 --- a/apps/labrinth/src/routes/internal/moderation.rs +++ b/apps/labrinth/src/routes/internal/moderation.rs @@ -6,7 +6,7 @@ use crate::models::projects::ProjectStatus; use crate::queue::moderation::{ApprovalType, IdentifiedFile, MissingMetadata}; use crate::queue::session::AuthQueue; use crate::{auth::check_is_moderator_from_headers, models::pats::Scopes}; -use actix_web::{web, HttpRequest, HttpResponse}; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; use std::collections::HashMap; @@ -29,14 +29,14 @@ fn default_count() -> i16 { pub async fn get_projects( req: HttpRequest, - pool: web::Data, - redis: web::Data, - count: web::Query, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + count: web::types::Query, + session_queue: web::types::State, ) -> Result { check_is_moderator_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -55,31 +55,31 @@ pub async fn get_projects( ProjectStatus::Processing.as_str(), count.count as i64 ) - .fetch(&**pool) + .fetch(&*pool) .map_ok(|m| database::models::ProjectId(m.id)) .try_collect::>() .await?; let projects: Vec<_> = - database::Project::get_many_ids(&project_ids, &**pool, &redis) + database::Project::get_many_ids(&project_ids, &*pool, &redis) .await? .into_iter() .map(crate::models::projects::Project::from) .collect(); - Ok(HttpResponse::Ok().json(projects)) + Ok(HttpResponse::Ok().json(&projects)) } pub async fn get_project_meta( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - info: web::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + info: web::types::Path<(String,)>, ) -> Result { check_is_moderator_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -88,7 +88,7 @@ pub async fn get_project_meta( let project_id = info.into_inner().0; let project = - database::models::Project::get(&project_id, &**pool, &redis).await?; + database::models::Project::get(&project_id, &*pool, &redis).await?; if let Some(project) = project { let rows = sqlx::query!( @@ -101,7 +101,7 @@ pub async fn get_project_meta( ", project.inner.id.0 ) - .fetch_all(&**pool) + .fetch_all(&*pool) .await?; let mut merged = MissingMetadata { @@ -141,7 +141,7 @@ pub async fn get_project_meta( .map(|x| x.as_bytes().to_vec()) .collect::>() ) - .fetch_all(&**pool) + .fetch_all(&*pool) .await?; for row in rows { @@ -176,7 +176,7 @@ pub async fn get_project_meta( ", &check_flames, ) - .fetch_all(&**pool) + .fetch_all(&*pool) .await?; for row in rows { @@ -199,7 +199,7 @@ pub async fn get_project_meta( } } - Ok(HttpResponse::Ok().json(merged)) + Ok(HttpResponse::Ok().json(&merged)) } else { Err(ApiError::NotFound) } @@ -224,14 +224,14 @@ pub enum Judgement { pub async fn set_project_meta( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - judgements: web::Json>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + judgements: web::types::Json>, ) -> Result { check_is_moderator_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), diff --git a/apps/labrinth/src/routes/internal/pats.rs b/apps/labrinth/src/routes/internal/pats.rs index 818d1ca85..1c46820fa 100644 --- a/apps/labrinth/src/routes/internal/pats.rs +++ b/apps/labrinth/src/routes/internal/pats.rs @@ -5,9 +5,8 @@ use crate::auth::get_user_from_headers; use crate::routes::ApiError; use crate::database::redis::RedisPool; -use actix_web::web::{self, Data}; -use actix_web::{delete, get, patch, post, HttpRequest, HttpResponse}; use chrono::{DateTime, Utc}; +use ntex::web::{self, delete, get, patch, post, HttpRequest, HttpResponse}; use rand::distributions::Alphanumeric; use rand::Rng; use rand_chacha::rand_core::SeedableRng; @@ -30,13 +29,13 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("pat")] pub async fn get_pats( req: HttpRequest, - pool: Data, - redis: Data, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAT_READ]), @@ -47,17 +46,18 @@ pub async fn get_pats( let pat_ids = database::models::pat_item::PersonalAccessToken::get_user_pats( user.id.into(), - &**pool, + &*pool, &redis, ) .await?; let pats = database::models::pat_item::PersonalAccessToken::get_many_ids( - &pat_ids, &**pool, &redis, + &pat_ids, &*pool, &redis, ) .await?; Ok(HttpResponse::Ok().json( - pats.into_iter() + &pats + .into_iter() .map(|x| PersonalAccessToken::from(x, false)) .collect::>(), )) @@ -74,10 +74,10 @@ pub struct NewPersonalAccessToken { #[post("pat")] pub async fn create_pat( req: HttpRequest, - info: web::Json, - pool: Data, - redis: Data, - session_queue: Data, + info: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { info.0.validate().map_err(|err| { ApiError::InvalidInput(validation_errors_to_string(err, None)) @@ -96,7 +96,7 @@ pub async fn create_pat( let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAT_CREATE]), @@ -136,7 +136,7 @@ pub async fn create_pat( ) .await?; - Ok(HttpResponse::Ok().json(PersonalAccessToken { + Ok(HttpResponse::Ok().json(&PersonalAccessToken { id: id.into(), name, access_token: Some(token), @@ -159,11 +159,11 @@ pub struct ModifyPersonalAccessToken { #[patch("pat/{id}")] pub async fn edit_pat( req: HttpRequest, - id: web::Path<(String,)>, - info: web::Json, - pool: Data, - redis: Data, - session_queue: Data, + id: web::types::Path<(String,)>, + info: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { info.0.validate().map_err(|err| { ApiError::InvalidInput(validation_errors_to_string(err, None)) @@ -171,7 +171,7 @@ pub async fn edit_pat( let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAT_WRITE]), @@ -181,7 +181,7 @@ pub async fn edit_pat( let id = id.into_inner().0; let pat = database::models::pat_item::PersonalAccessToken::get( - &id, &**pool, &redis, + &id, &*pool, &redis, ) .await?; @@ -256,14 +256,14 @@ pub async fn edit_pat( #[delete("pat/{id}")] pub async fn delete_pat( req: HttpRequest, - id: web::Path<(String,)>, - pool: Data, - redis: Data, - session_queue: Data, + id: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAT_DELETE]), @@ -272,7 +272,7 @@ pub async fn delete_pat( .1; let id = id.into_inner().0; let pat = database::models::pat_item::PersonalAccessToken::get( - &id, &**pool, &redis, + &id, &*pool, &redis, ) .await?; diff --git a/apps/labrinth/src/routes/internal/session.rs b/apps/labrinth/src/routes/internal/session.rs index b7f638faf..7e22ec9ee 100644 --- a/apps/labrinth/src/routes/internal/session.rs +++ b/apps/labrinth/src/routes/internal/session.rs @@ -8,10 +8,10 @@ use crate::models::sessions::Session; use crate::queue::session::AuthQueue; use crate::routes::ApiError; use crate::util::env::parse_var; -use actix_web::http::header::AUTHORIZATION; -use actix_web::web::{scope, Data, ServiceConfig}; -use actix_web::{delete, get, post, web, HttpRequest, HttpResponse}; use chrono::Utc; +use ntex::http::header::AUTHORIZATION; +use ntex::web::{self, delete, get, post, HttpRequest, HttpResponse}; +use ntex::web::{scope, ServiceConfig}; use rand::distributions::Alphanumeric; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; @@ -22,7 +22,7 @@ pub fn config(cfg: &mut ServiceConfig) { cfg.service( scope("session") .service(list) - .service(delete) + .service(delete_session) .service(refresh), ); } @@ -40,15 +40,14 @@ pub struct SessionMetadata { pub async fn get_session_metadata( req: &HttpRequest, ) -> Result { - let conn_info = req.connection_info().clone(); let ip_addr = if parse_var("CLOUDFLARE_INTEGRATION").unwrap_or(false) { if let Some(header) = req.headers().get("CF-Connecting-IP") { - header.to_str().ok() + header.to_str().map(|x| x.to_string()).ok() } else { - conn_info.peer_addr() + req.peer_addr().map(|x| x.to_string()) } } else { - conn_info.peer_addr() + req.peer_addr().map(|x| x.to_string()) }; let country = req @@ -132,13 +131,13 @@ pub async fn issue_session( #[get("list")] pub async fn list( req: HttpRequest, - pool: Data, - redis: Data, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_READ]), @@ -153,29 +152,29 @@ pub async fn list( .ok_or_else(|| AuthenticationError::InvalidCredentials)?; let session_ids = - DBSession::get_user_sessions(current_user.id.into(), &**pool, &redis) + DBSession::get_user_sessions(current_user.id.into(), &*pool, &redis) .await?; - let sessions = DBSession::get_many_ids(&session_ids, &**pool, &redis) + let sessions = DBSession::get_many_ids(&session_ids, &*pool, &redis) .await? .into_iter() .filter(|x| x.expires > Utc::now()) .map(|x| Session::from(x, false, Some(session))) .collect::>(); - Ok(HttpResponse::Ok().json(sessions)) + Ok(HttpResponse::Ok().json(&sessions)) } #[delete("{id}")] -pub async fn delete( - info: web::Path<(String,)>, +pub async fn delete_session( + info: web::types::Path<(String,)>, req: HttpRequest, - pool: Data, - redis: Data, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_DELETE]), @@ -183,7 +182,7 @@ pub async fn delete( .await? .1; - let session = DBSession::get(info.into_inner().0, &**pool, &redis).await?; + let session = DBSession::get(info.into_inner().0, &*pool, &redis).await?; if let Some(session) = session { if session.user_id == current_user.id.into() { @@ -208,12 +207,12 @@ pub async fn delete( #[post("refresh")] pub async fn refresh( req: HttpRequest, - pool: Data, - redis: Data, - session_queue: Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = - get_user_from_headers(&req, &**pool, &redis, &session_queue, None) + get_user_from_headers(&req, &*pool, &redis, &session_queue, None) .await? .1; let session = req @@ -224,7 +223,7 @@ pub async fn refresh( ApiError::Authentication(AuthenticationError::InvalidCredentials) })?; - let session = DBSession::get(session, &**pool, &redis).await?; + let session = DBSession::get(session, &*pool, &redis).await?; if let Some(session) = session { if current_user.id != session.user_id.into() @@ -252,7 +251,7 @@ pub async fn refresh( ) .await?; - Ok(HttpResponse::Ok().json(Session::from(new_session, true, None))) + Ok(HttpResponse::Ok().json(&Session::from(new_session, true, None))) } else { Err(ApiError::Authentication( AuthenticationError::InvalidCredentials, diff --git a/apps/labrinth/src/routes/internal/statuses.rs b/apps/labrinth/src/routes/internal/statuses.rs index b54af1869..ce69dea26 100644 --- a/apps/labrinth/src/routes/internal/statuses.rs +++ b/apps/labrinth/src/routes/internal/statuses.rs @@ -8,17 +8,16 @@ use crate::models::users::{User, UserStatus}; use crate::queue::session::AuthQueue; use crate::queue::socket::ActiveSockets; use crate::routes::ApiError; -use actix_web::web::{Data, Payload}; -use actix_web::{get, web, HttpRequest, HttpResponse}; -use actix_ws::AggregatedMessage; +use ntex::web::{self, get, HttpRequest, HttpResponse}; +// use actix_ws::AggregatedMessage; use chrono::Utc; use futures_util::StreamExt; use serde::{Deserialize, Serialize}; use sqlx::PgPool; -pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(ws_init); -} +// pub fn config(cfg: &mut web::ServiceConfig) { +// cfg.service(ws_init); +// } #[derive(Deserialize)] #[serde(tag = "type", rename_all = "snake_case")] @@ -41,161 +40,161 @@ struct LauncherHeartbeatInit { code: String, } -#[get("launcher_socket")] -pub async fn ws_init( - req: HttpRequest, - pool: Data, - web::Query(auth): web::Query, - body: Payload, - db: Data, - redis: Data, - session_queue: Data, -) -> Result { - let (scopes, db_user) = get_user_record_from_bearer_token( - &req, - Some(&auth.code), - &**pool, - &redis, - &session_queue, - ) - .await? - .ok_or_else(|| { - ApiError::Authentication(AuthenticationError::InvalidCredentials) - })?; - - if !scopes.contains(Scopes::SESSION_ACCESS) { - return Err(ApiError::Authentication( - AuthenticationError::InvalidCredentials, - )); - } - - let user = User::from_full(db_user); - - if let Some((_, (_, session))) = db.auth_sockets.remove(&user.id) { - let _ = session.close(None).await; - } - - let (res, mut session, msg_stream) = match actix_ws::handle(&req, body) { - Ok(x) => x, - Err(e) => return Ok(e.error_response()), - }; - - let status = UserStatus { - user_id: user.id, - profile_name: None, - last_update: Utc::now(), - }; - - let friends = - FriendItem::get_user_friends(user.id.into(), Some(true), &**pool) - .await?; - - let friend_statuses = if !friends.is_empty() { - friends - .iter() - .filter_map(|x| { - db.auth_sockets.get( - &if x.user_id == user.id.into() { - x.friend_id - } else { - x.user_id - } - .into(), - ) - }) - .map(|x| x.value().0.clone()) - .collect::>() - } else { - Vec::new() - }; - - let _ = session - .text(serde_json::to_string( - &ServerToClientMessage::FriendStatuses { - statuses: friend_statuses, - }, - )?) - .await; - - db.auth_sockets.insert(user.id, (status.clone(), session)); - - broadcast_friends( - user.id, - ServerToClientMessage::StatusUpdate { status }, - &pool, - &db, - Some(friends), - ) - .await?; - - let mut stream = msg_stream.aggregate_continuations(); - - actix_web::rt::spawn(async move { - // receive messages from websocket - while let Some(msg) = stream.next().await { - match msg { - Ok(AggregatedMessage::Text(text)) => { - if let Ok(message) = - serde_json::from_str::(&text) - { - match message { - ClientToServerMessage::StatusUpdate { - profile_name, - } => { - if let Some(mut pair) = - db.auth_sockets.get_mut(&user.id) - { - let (status, _) = pair.value_mut(); - - if status - .profile_name - .as_ref() - .map(|x| x.len() > 64) - .unwrap_or(false) - { - continue; - } - - status.profile_name = profile_name; - status.last_update = Utc::now(); - - let _ = broadcast_friends( - user.id, - ServerToClientMessage::StatusUpdate { - status: status.clone(), - }, - &pool, - &db, - None, - ) - .await; - } - } - } - } - } - - Ok(AggregatedMessage::Close(_)) => { - let _ = close_socket(user.id, &pool, &db).await; - } - - Ok(AggregatedMessage::Ping(msg)) => { - if let Some(mut socket) = db.auth_sockets.get_mut(&user.id) - { - let (_, socket) = socket.value_mut(); - let _ = socket.pong(&msg).await; - } - } - - _ => {} - } - } - - let _ = close_socket(user.id, &pool, &db).await; - }); - - Ok(res) -} +// #[get("launcher_socket")] +// pub async fn ws_init( +// req: HttpRequest, +// pool: web::types::State, +// web::types::Query(auth): web::types::Query, +// body: Payload, +// db: web::types::State, +// redis: web::types::State, +// session_queue: web::types::State, +// ) -> Result { +// let (scopes, db_user) = get_user_record_from_bearer_token( +// &req, +// Some(&auth.code), +// &*pool, +// &redis, +// &session_queue, +// ) +// .await? +// .ok_or_else(|| { +// ApiError::Authentication(AuthenticationError::InvalidCredentials) +// })?; +// +// if !scopes.contains(Scopes::SESSION_ACCESS) { +// return Err(ApiError::Authentication( +// AuthenticationError::InvalidCredentials, +// )); +// } +// +// let user = User::from_full(db_user); +// +// if let Some((_, (_, session))) = db.auth_sockets.remove(&user.id) { +// let _ = session.close(None).await; +// } +// +// let (res, mut session, msg_stream) = match actix_ws::handle(&req, body) { +// Ok(x) => x, +// Err(e) => return Ok(e.error_response()), +// }; +// +// let status = UserStatus { +// user_id: user.id, +// profile_name: None, +// last_update: Utc::now(), +// }; +// +// let friends = +// FriendItem::get_user_friends(user.id.into(), Some(true), &*pool) +// .await?; +// +// let friend_statuses = if !friends.is_empty() { +// friends +// .iter() +// .filter_map(|x| { +// db.auth_sockets.get( +// &if x.user_id == user.id.into() { +// x.friend_id +// } else { +// x.user_id +// } +// .into(), +// ) +// }) +// .map(|x| x.value().0.clone()) +// .collect::>() +// } else { +// Vec::new() +// }; +// +// let _ = session +// .text(serde_json::to_string( +// &ServerToClientMessage::FriendStatuses { +// statuses: friend_statuses, +// }, +// )?) +// .await; +// +// db.auth_sockets.insert(user.id, (status.clone(), session)); +// +// broadcast_friends( +// user.id, +// ServerToClientMessage::StatusUpdate { status }, +// &pool, +// &db, +// Some(friends), +// ) +// .await?; +// +// let mut stream = msg_stream.aggregate_continuations(); +// +// ntex::rt::spawn(async move { +// // receive messages from websocket +// while let Some(msg) = stream.next().await { +// match msg { +// Ok(AggregatedMessage::Text(text)) => { +// if let Ok(message) = +// serde_json::from_str::(&text) +// { +// match message { +// ClientToServerMessage::StatusUpdate { +// profile_name, +// } => { +// if let Some(mut pair) = +// db.auth_sockets.get_mut(&user.id) +// { +// let (status, _) = pair.value_mut(); +// +// if status +// .profile_name +// .as_ref() +// .map(|x| x.len() > 64) +// .unwrap_or(false) +// { +// continue; +// } +// +// status.profile_name = profile_name; +// status.last_update = Utc::now(); +// +// let _ = broadcast_friends( +// user.id, +// ServerToClientMessage::StatusUpdate { +// status: status.clone(), +// }, +// &pool, +// &db, +// None, +// ) +// .await; +// } +// } +// } +// } +// } +// +// Ok(AggregatedMessage::Close(_)) => { +// let _ = close_socket(user.id, &pool, &db).await; +// } +// +// Ok(AggregatedMessage::Ping(msg)) => { +// if let Some(mut socket) = db.auth_sockets.get_mut(&user.id) +// { +// let (_, socket) = socket.value_mut(); +// let _ = socket.pong(&msg).await; +// } +// } +// +// _ => {} +// } +// } +// +// let _ = close_socket(user.id, &pool, &db).await; +// }); +// +// Ok(res) +// } pub async fn broadcast_friends( user_id: UserId, @@ -218,13 +217,14 @@ pub async fn broadcast_friends( }; if friend.accepted { - if let Some(mut socket) = - sockets.auth_sockets.get_mut(&friend_id.into()) - { - let (_, socket) = socket.value_mut(); - - let _ = socket.text(serde_json::to_string(&message)?).await; - } + // TODO: FIX ME + // if let Some(mut socket) = + // sockets.auth_sockets.get_mut(&friend_id.into()) + // { + // let (_, socket) = socket.value_mut(); + // + // let _ = socket.text(serde_json::to_string(&message)?).await; + // } } } @@ -236,18 +236,19 @@ pub async fn close_socket( pool: &PgPool, sockets: &ActiveSockets, ) -> Result<(), crate::database::models::DatabaseError> { - if let Some((_, (_, socket))) = sockets.auth_sockets.remove(&id) { - let _ = socket.close(None).await; - - broadcast_friends( - id, - ServerToClientMessage::UserOffline { id }, - pool, - sockets, - None, - ) - .await?; - } + // TODO: FIX ME + // if let Some((_, (_, socket))) = sockets.auth_sockets.remove(&id) { + // let _ = socket.close(None).await; + // + // broadcast_friends( + // id, + // ServerToClientMessage::UserOffline { id }, + // pool, + // sockets, + // None, + // ) + // .await?; + // } Ok(()) } diff --git a/apps/labrinth/src/routes/maven.rs b/apps/labrinth/src/routes/maven.rs index 193b5b0f9..cb4015271 100644 --- a/apps/labrinth/src/routes/maven.rs +++ b/apps/labrinth/src/routes/maven.rs @@ -9,7 +9,8 @@ use crate::models::projects::{ProjectId, VersionId}; use crate::queue::session::AuthQueue; use crate::routes::ApiError; use crate::{auth::get_user_from_headers, database}; -use actix_web::{get, route, web, HttpRequest, HttpResponse}; +use ntex::web; +use ntex::web::{get, HttpRequest, HttpResponse}; use sqlx::PgPool; use std::collections::HashSet; use yaserde_derive::YaSerialize; @@ -18,7 +19,7 @@ pub fn config(cfg: &mut web::ServiceConfig) { cfg.service(maven_metadata); cfg.service(version_file_sha512); cfg.service(version_file_sha1); - cfg.service(version_file); + // cfg.service(version_file); } #[derive(Default, Debug, Clone, YaSerialize)] @@ -69,21 +70,21 @@ pub struct MavenPom { #[get("maven/modrinth/{id}/maven-metadata.xml")] pub async fn maven_metadata( req: HttpRequest, - params: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + params: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let project_id = params.into_inner().0; let Some(project) = - database::models::Project::get(&project_id, &**pool, &redis).await? + database::models::Project::get(&project_id, &*pool, &redis).await? else { return Err(ApiError::NotFound); }; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -109,7 +110,7 @@ pub async fn maven_metadata( .map(|x| x.to_string()) .collect::>(), ) - .fetch_all(&**pool) + .fetch_all(&*pool) .await?; let mut new_versions = Vec::new(); @@ -268,28 +269,29 @@ fn find_file<'a>( None } -#[route( - "maven/modrinth/{id}/{versionnum}/{file}", - method = "GET", - method = "HEAD" -)] +// TODO: fix me +// #[route( +// "maven/modrinth/{id}/{versionnum}/{file}", +// method = "GET", +// method = "HEAD" +// )] pub async fn version_file( req: HttpRequest, - params: web::Path<(String, String, String)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + params: web::types::Path<(String, String, String)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let (project_id, vnum, file) = params.into_inner(); let Some(project) = - database::models::Project::get(&project_id, &**pool, &redis).await? + database::models::Project::get(&project_id, &*pool, &redis).await? else { return Err(ApiError::NotFound); }; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -331,7 +333,7 @@ pub async fn version_file( find_file(&project_id, &vnum, &version, &file) { return Ok(HttpResponse::TemporaryRedirect() - .append_header(("location", &*selected_file.url)) + .header("location", &*selected_file.url) .body("")); } @@ -341,21 +343,21 @@ pub async fn version_file( #[get("maven/modrinth/{id}/{versionnum}/{file}.sha1")] pub async fn version_file_sha1( req: HttpRequest, - params: web::Path<(String, String, String)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + params: web::types::Path<(String, String, String)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let (project_id, vnum, file) = params.into_inner(); let Some(project) = - database::models::Project::get(&project_id, &**pool, &redis).await? + database::models::Project::get(&project_id, &*pool, &redis).await? else { return Err(ApiError::NotFound); }; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -386,21 +388,21 @@ pub async fn version_file_sha1( #[get("maven/modrinth/{id}/{versionnum}/{file}.sha512")] pub async fn version_file_sha512( req: HttpRequest, - params: web::Path<(String, String, String)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + params: web::types::Path<(String, String, String)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let (project_id, vnum, file) = params.into_inner(); let Some(project) = - database::models::Project::get(&project_id, &**pool, &redis).await? + database::models::Project::get(&project_id, &*pool, &redis).await? else { return Err(ApiError::NotFound); }; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), diff --git a/apps/labrinth/src/routes/mod.rs b/apps/labrinth/src/routes/mod.rs index 79d2cc4c6..e452fb344 100644 --- a/apps/labrinth/src/routes/mod.rs +++ b/apps/labrinth/src/routes/mod.rs @@ -2,11 +2,11 @@ use crate::file_hosting::FileHostingError; use crate::routes::analytics::{page_view_ingest, playtime_ingest}; use crate::util::cors::default_cors; use crate::util::env::parse_strings_from_var; -use actix_cors::Cors; -use actix_files::Files; -use actix_web::http::StatusCode; -use actix_web::{web, HttpResponse}; use futures::FutureExt; +use ntex::http::StatusCode; +use ntex::web::{self, HttpRequest, HttpResponse}; +use ntex_cors::Cors; +use ntex_files::Files; pub mod internal; pub mod v2; @@ -35,45 +35,42 @@ pub fn root_config(cfg: &mut web::ServiceConfig) { ); cfg.service( web::scope("analytics") - .wrap( - Cors::default() - .allowed_origin_fn(|origin, _req_head| { - let allowed_origins = - parse_strings_from_var("ANALYTICS_ALLOWED_ORIGINS") - .unwrap_or_default(); + .wrap({ + let mut cors = Cors::new(); - allowed_origins.contains(&"*".to_string()) - || allowed_origins.contains( - &origin - .to_str() - .unwrap_or_default() - .to_string(), - ) - }) - .allowed_methods(vec!["GET", "POST"]) + for origin in + parse_strings_from_var("ANALYTICS_ALLOWED_ORIGINS") + .unwrap_or_default() + { + cors = cors.allowed_origin(&*origin); + } + + cors.allowed_methods(vec!["GET", "POST"]) .allowed_headers(vec![ - actix_web::http::header::AUTHORIZATION, - actix_web::http::header::ACCEPT, - actix_web::http::header::CONTENT_TYPE, + ntex::http::header::AUTHORIZATION, + ntex::http::header::ACCEPT, + ntex::http::header::CONTENT_TYPE, ]) - .max_age(3600), - ) + .max_age(3600) + .finish() + }) .service(page_view_ingest) .service(playtime_ingest), ); - cfg.service( - web::scope("api/v1") - .wrap(default_cors()) - .wrap_fn(|req, _srv| { - async { - Ok(req.into_response( - HttpResponse::Gone() - .content_type("application/json") - .body(r#"{"error":"api_deprecated","description":"You are using an application that uses an outdated version of Modrinth's API. Please either update it or switch to another application. For developers: https://docs.modrinth.com/api/#versioning"}"#) - )) - }.boxed_local() - }) - ); + // TODO: FIX ME + // cfg.service( + // web::scope("api/v1") + // .wrap(default_cors()) + // .wrap_fn(|req, _srv| { + // async { + // Ok(req.into_response( + // HttpResponse::Gone() + // .content_type("application/json") + // .body(r#"{"error":"api_deprecated","description":"You are using an application that uses an outdated version of Modrinth's API. Please either update it or switch to another application. For developers: https://docs.modrinth.com/api/#versioning"}"#) + // )) + // }.boxed_local() + // }) + // ); cfg.service( web::scope("") .wrap(default_cors()) @@ -177,7 +174,7 @@ impl ApiError { } } -impl actix_web::ResponseError for ApiError { +impl ntex::web::WebResponseError for ApiError { fn status_code(&self) -> StatusCode { match self { ApiError::Env(..) => StatusCode::INTERNAL_SERVER_ERROR, @@ -210,7 +207,7 @@ impl actix_web::ResponseError for ApiError { } } - fn error_response(&self) -> HttpResponse { - HttpResponse::build(self.status_code()).json(self.as_api_error()) + fn error_response(&self, _req: &HttpRequest) -> HttpResponse { + HttpResponse::build(self.status_code()).json(&self.as_api_error()) } } diff --git a/apps/labrinth/src/routes/not_found.rs b/apps/labrinth/src/routes/not_found.rs index 2da930bd7..887753604 100644 --- a/apps/labrinth/src/routes/not_found.rs +++ b/apps/labrinth/src/routes/not_found.rs @@ -1,5 +1,5 @@ use crate::models::error::ApiError; -use actix_web::{HttpResponse, Responder}; +use ntex::web::{HttpResponse, Responder}; pub async fn not_found() -> impl Responder { let data = ApiError { @@ -7,5 +7,5 @@ pub async fn not_found() -> impl Responder { description: "the requested route does not exist".to_string(), }; - HttpResponse::NotFound().json(data) + HttpResponse::NotFound().json(&data) } diff --git a/apps/labrinth/src/routes/updates.rs b/apps/labrinth/src/routes/updates.rs index 64ee7b218..fff6768f9 100644 --- a/apps/labrinth/src/routes/updates.rs +++ b/apps/labrinth/src/routes/updates.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use actix_web::{get, web, HttpRequest, HttpResponse}; +use ntex::web::{self, get, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -15,7 +15,7 @@ use crate::queue::session::AuthQueue; use super::ApiError; -pub fn config(cfg: &mut web::ServiceConfig) { +pub fn config(cfg: &mut ntex::web::ServiceConfig) { cfg.service(forge_updates); } @@ -32,23 +32,23 @@ fn default_neoforge() -> String { #[get("{id}/forge_updates.json")] pub async fn forge_updates( req: HttpRequest, - web::Query(neo): web::Query, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(neo): web::types::Query, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { const ERROR: &str = "The specified project does not exist!"; let (id,) = info.into_inner(); - let project = database::models::Project::get(&id, &**pool, &redis) + let project = database::models::Project::get(&id, &*pool, &redis) .await? .ok_or_else(|| ApiError::InvalidInput(ERROR.to_string()))?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -62,7 +62,7 @@ pub async fn forge_updates( } let versions = - database::models::Version::get_many(&project.versions, &**pool, &redis) + database::models::Version::get_many(&project.versions, &*pool, &redis) .await?; let loaders = match &*neo.neoforge { @@ -129,5 +129,5 @@ pub async fn forge_updates( } } - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } diff --git a/apps/labrinth/src/routes/v2/mod.rs b/apps/labrinth/src/routes/v2/mod.rs index 13f823a6a..b15ce7907 100644 --- a/apps/labrinth/src/routes/v2/mod.rs +++ b/apps/labrinth/src/routes/v2/mod.rs @@ -1,6 +1,6 @@ mod moderation; mod notifications; -pub(crate) mod project_creation; +// pub(crate) mod project_creation; mod projects; mod reports; mod statistics; @@ -8,16 +8,16 @@ pub mod tags; mod teams; mod threads; mod users; -mod version_creation; +// mod version_creation; pub mod version_file; mod versions; pub use super::ApiError; use crate::util::cors::default_cors; -pub fn config(cfg: &mut actix_web::web::ServiceConfig) { +pub fn config(cfg: &mut ntex::web::ServiceConfig) { cfg.service( - actix_web::web::scope("v2") + ntex::web::scope("v2") .wrap(default_cors()) .configure(super::internal::admin::config) // Todo: separate these- they need to also follow v2-v3 conversion @@ -26,7 +26,7 @@ pub fn config(cfg: &mut actix_web::web::ServiceConfig) { .configure(super::internal::pats::config) .configure(moderation::config) .configure(notifications::config) - .configure(project_creation::config) + // .configure(project_creation::config) .configure(projects::config) .configure(reports::config) .configure(statistics::config) diff --git a/apps/labrinth/src/routes/v2/moderation.rs b/apps/labrinth/src/routes/v2/moderation.rs index e961da24a..808a75a2f 100644 --- a/apps/labrinth/src/routes/v2/moderation.rs +++ b/apps/labrinth/src/routes/v2/moderation.rs @@ -4,7 +4,7 @@ use crate::models::v2::projects::LegacyProject; use crate::queue::session::AuthQueue; use crate::routes::internal; use crate::{database::redis::RedisPool, routes::v2_reroute}; -use actix_web::{get, web, HttpRequest, HttpResponse}; +use ntex::web::{self, get, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; @@ -25,16 +25,18 @@ fn default_count() -> i16 { #[get("projects")] pub async fn get_projects( req: HttpRequest, - pool: web::Data, - redis: web::Data, - count: web::Query, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + count: web::types::Query, + session_queue: web::types::State, ) -> Result { let response = internal::moderation::get_projects( req, pool.clone(), redis.clone(), - web::Query(internal::moderation::ResultCount { count: count.count }), + web::types::Query(internal::moderation::ResultCount { + count: count.count, + }), session_queue, ) .await @@ -44,8 +46,8 @@ pub async fn get_projects( match v2_reroute::extract_ok_json::>(response).await { Ok(project) => { let legacy_projects = - LegacyProject::from_many(project, &**pool, &redis).await?; - Ok(HttpResponse::Ok().json(legacy_projects)) + LegacyProject::from_many(project, &*pool, &redis).await?; + Ok(HttpResponse::Ok().json(&legacy_projects)) } Err(response) => Ok(response), } diff --git a/apps/labrinth/src/routes/v2/notifications.rs b/apps/labrinth/src/routes/v2/notifications.rs index 85810d614..512970500 100644 --- a/apps/labrinth/src/routes/v2/notifications.rs +++ b/apps/labrinth/src/routes/v2/notifications.rs @@ -6,7 +6,7 @@ use crate::queue::session::AuthQueue; use crate::routes::v2_reroute; use crate::routes::v3; use crate::routes::ApiError; -use actix_web::{delete, get, patch, web, HttpRequest, HttpResponse}; +use ntex::web::{self, delete, get, patch, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -31,14 +31,14 @@ pub struct NotificationIds { #[get("notifications")] pub async fn notifications_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let resp = v3::notifications::notifications_get( req, - web::Query(v3::notifications::NotificationIds { ids: ids.ids }), + web::types::Query(v3::notifications::NotificationIds { ids: ids.ids }), pool, redis, session_queue, @@ -51,7 +51,7 @@ pub async fn notifications_get( .into_iter() .map(LegacyNotification::from) .collect(); - Ok(HttpResponse::Ok().json(notifications)) + Ok(HttpResponse::Ok().json(¬ifications)) } Err(response) => Ok(response), } @@ -60,10 +60,10 @@ pub async fn notifications_get( #[get("{id}")] pub async fn notification_get( req: HttpRequest, - info: web::Path<(NotificationId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(NotificationId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::notifications::notification_get( req, @@ -77,7 +77,7 @@ pub async fn notification_get( match v2_reroute::extract_ok_json::(response).await { Ok(notification) => { let notification = LegacyNotification::from(notification); - Ok(HttpResponse::Ok().json(notification)) + Ok(HttpResponse::Ok().json(¬ification)) } Err(response) => Ok(response), } @@ -86,10 +86,10 @@ pub async fn notification_get( #[patch("{id}")] pub async fn notification_read( req: HttpRequest, - info: web::Path<(NotificationId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(NotificationId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::notifications::notification_read(req, info, pool, redis, session_queue) @@ -100,10 +100,10 @@ pub async fn notification_read( #[delete("{id}")] pub async fn notification_delete( req: HttpRequest, - info: web::Path<(NotificationId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(NotificationId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::notifications::notification_delete( @@ -120,15 +120,15 @@ pub async fn notification_delete( #[patch("notifications")] pub async fn notifications_read( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::notifications::notifications_read( req, - web::Query(v3::notifications::NotificationIds { ids: ids.ids }), + web::types::Query(v3::notifications::NotificationIds { ids: ids.ids }), pool, redis, session_queue, @@ -140,15 +140,15 @@ pub async fn notifications_read( #[delete("notifications")] pub async fn notifications_delete( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::notifications::notifications_delete( req, - web::Query(v3::notifications::NotificationIds { ids: ids.ids }), + web::types::Query(v3::notifications::NotificationIds { ids: ids.ids }), pool, redis, session_queue, diff --git a/apps/labrinth/src/routes/v2/project_creation.rs b/apps/labrinth/src/routes/v2/project_creation.rs index decc71a3d..3ed166ecf 100644 --- a/apps/labrinth/src/routes/v2/project_creation.rs +++ b/apps/labrinth/src/routes/v2/project_creation.rs @@ -11,9 +11,8 @@ use crate::queue::session::AuthQueue; use crate::routes::v3::project_creation::default_project_type; use crate::routes::v3::project_creation::{CreateError, NewGalleryItem}; use crate::routes::{v2_reroute, v3}; -use actix_multipart::Multipart; -use actix_web::web::Data; -use actix_web::{post, HttpRequest, HttpResponse}; +use ntex::web::{self, post, HttpRequest, HttpResponse}; +use ntex_multipart::Multipart; use serde::{Deserialize, Serialize}; use serde_json::json; use sqlx::postgres::PgPool; @@ -24,7 +23,7 @@ use validator::Validate; use super::version_creation::InitialVersionData; -pub fn config(cfg: &mut actix_web::web::ServiceConfig) { +pub fn config(cfg: &mut ntex::web::ServiceConfig) { cfg.service(project_create); } @@ -139,10 +138,10 @@ struct ProjectCreateData { pub async fn project_create( req: HttpRequest, payload: Multipart, - client: Data, - redis: Data, - file_host: Data>, - session_queue: Data, + client: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { // Convert V2 multipart payload to V3 multipart payload let payload = v2_reroute::alter_actix_multipart( @@ -260,13 +259,13 @@ pub async fn project_create( Ok(project) => { let version_item = match project.versions.first() { Some(vid) => { - version_item::Version::get((*vid).into(), &**client, &redis) + version_item::Version::get((*vid).into(), &*client, &redis) .await? } None => None, }; let project = LegacyProject::from(project, version_item); - Ok(HttpResponse::Ok().json(project)) + Ok(HttpResponse::Ok().json(&project)) } Err(response) => Ok(response), } diff --git a/apps/labrinth/src/routes/v2/projects.rs b/apps/labrinth/src/routes/v2/projects.rs index 7bc5eed60..ba8337633 100644 --- a/apps/labrinth/src/routes/v2/projects.rs +++ b/apps/labrinth/src/routes/v2/projects.rs @@ -14,7 +14,7 @@ use crate::queue::session::AuthQueue; use crate::routes::v3::projects::ProjectIds; use crate::routes::{v2_reroute, v3, ApiError}; use crate::search::{search_for_project, SearchConfig, SearchError}; -use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse}; +use ntex::web::{self, delete, get, patch, post, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; use std::collections::HashMap; @@ -52,8 +52,8 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("search")] pub async fn project_search( - web::Query(info): web::Query, - config: web::Data, + web::types::Query(info): web::types::Query, + config: web::types::State, ) -> Result { // Search now uses loader_fields instead of explicit 'client_side' and 'server_side' fields // While the backend for this has changed, it doesnt affect much @@ -108,7 +108,7 @@ pub async fn project_search( let results = LegacySearchResults::from(results); - Ok(HttpResponse::Ok().json(results)) + Ok(HttpResponse::Ok().json(&results)) } /// Parses a facet into a key, operator, and value @@ -153,14 +153,14 @@ pub struct RandomProjects { #[get("projects_random")] pub async fn random_projects_get( - web::Query(count): web::Query, - pool: web::Data, - redis: web::Data, + web::types::Query(count): web::types::Query, + pool: web::types::State, + redis: web::types::State, ) -> Result { let count = v3::projects::RandomProjects { count: count.count }; let response = v3::projects::random_projects_get( - web::Query(count), + web::types::Query(count), pool.clone(), redis.clone(), ) @@ -171,8 +171,8 @@ pub async fn random_projects_get( match v2_reroute::extract_ok_json::>(response).await { Ok(project) => { let legacy_projects = - LegacyProject::from_many(project, &**pool, &redis).await?; - Ok(HttpResponse::Ok().json(legacy_projects)) + LegacyProject::from_many(project, &*pool, &redis).await?; + Ok(HttpResponse::Ok().json(&legacy_projects)) } Err(response) => Ok(response), } @@ -181,15 +181,15 @@ pub async fn random_projects_get( #[get("projects")] pub async fn projects_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Call V3 project creation let response = v3::projects::projects_get( req, - web::Query(ids), + web::types::Query(ids), pool.clone(), redis.clone(), session_queue, @@ -202,8 +202,8 @@ pub async fn projects_get( match v2_reroute::extract_ok_json::>(response).await { Ok(project) => { let legacy_projects = - LegacyProject::from_many(project, &**pool, &redis).await?; - Ok(HttpResponse::Ok().json(legacy_projects)) + LegacyProject::from_many(project, &*pool, &redis).await?; + Ok(HttpResponse::Ok().json(&legacy_projects)) } Err(response) => Ok(response), } @@ -212,10 +212,10 @@ pub async fn projects_get( #[get("{id}")] pub async fn project_get( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Convert V2 data to V3 data // Call V3 project creation @@ -234,13 +234,13 @@ pub async fn project_get( Ok(project) => { let version_item = match project.versions.first() { Some(vid) => { - version_item::Version::get((*vid).into(), &**pool, &redis) + version_item::Version::get((*vid).into(), &*pool, &redis) .await? } None => None, }; let project = LegacyProject::from(project, version_item); - Ok(HttpResponse::Ok().json(project)) + Ok(HttpResponse::Ok().json(&project)) } Err(response) => Ok(response), } @@ -249,9 +249,9 @@ pub async fn project_get( //checks the validity of a project id or slug #[get("{id}/check")] pub async fn project_get_check( - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, ) -> Result { // Returns an id only, do not need to convert v3::projects::project_get_check(info, pool, redis) @@ -268,10 +268,10 @@ struct DependencyInfo { #[get("dependencies")] pub async fn dependency_list( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // TODO: tests, probably let response = v3::projects::dependency_list( @@ -292,7 +292,7 @@ pub async fn dependency_list( Ok(dependency_info) => { let converted_projects = LegacyProject::from_many( dependency_info.projects, - &**pool, + &*pool, &redis, ) .await?; @@ -302,7 +302,7 @@ pub async fn dependency_list( .map(LegacyVersion::from) .collect(); - Ok(HttpResponse::Ok().json(DependencyInfo { + Ok(HttpResponse::Ok().json(&DependencyInfo { projects: converted_projects, versions: converted_versions, })) @@ -414,13 +414,13 @@ pub struct EditProject { #[allow(clippy::too_many_arguments)] pub async fn project_edit( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - search_config: web::Data, - new_project: web::Json, - redis: web::Data, - session_queue: web::Data, - moderation_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + search_config: web::types::State, + new_project: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, + moderation_queue: web::types::State, ) -> Result { let v2_new_project = new_project.into_inner(); let client_side = v2_new_project.client_side; @@ -474,7 +474,7 @@ pub async fn project_edit( if let Some(donation_urls) = v2_new_project.donation_urls { // Fetch current donation links from project so we know what to delete let fetched_example_project = - project_item::Project::get(&info.0, &**pool, &redis).await?; + project_item::Project::get(&info.0, &*pool, &redis).await?; let donation_links = fetched_example_project .map(|x| { x.urls @@ -525,7 +525,7 @@ pub async fn project_edit( info, pool.clone(), search_config, - web::Json(new_project), + web::types::Json(new_project), redis.clone(), session_queue.clone(), moderation_queue, @@ -540,13 +540,13 @@ pub async fn project_edit( { let project_item = project_item::Project::get( &new_slug.unwrap_or(project_id), - &**pool, + &*pool, &redis, ) .await?; let version_ids = project_item.map(|x| x.versions).unwrap_or_default(); let versions = - version_item::Version::get_many(&version_ids, &**pool, &redis) + version_item::Version::get_many(&version_ids, &*pool, &redis) .await?; for version in versions { let version = Version::from(version); @@ -643,11 +643,11 @@ pub struct BulkEditProject { #[patch("projects")] pub async fn projects_edit( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - bulk_edit_project: web::Json, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + bulk_edit_project: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let bulk_edit_project = bulk_edit_project.into_inner(); @@ -656,7 +656,7 @@ pub async fn projects_edit( // If we are *setting* donation links, we will set every possible donation link to None, as // setting will delete all of them then 're-add' the ones we want to keep if let Some(donation_url) = bulk_edit_project.donation_urls { - let link_platforms = LinkPlatform::list(&**pool, &redis).await?; + let link_platforms = LinkPlatform::list(&*pool, &redis).await?; for link in link_platforms { if link.donation { link_urls.insert(link.name, None); @@ -717,9 +717,9 @@ pub async fn projects_edit( // This returns NoContent or failure so we don't need to do anything with it v3::projects::projects_edit( req, - web::Query(ids), + web::types::Query(ids), pool.clone(), - web::Json(v3::projects::BulkEditProject { + web::types::Json(v3::projects::BulkEditProject { categories: bulk_edit_project.categories, add_categories: bulk_edit_project.add_categories, remove_categories: bulk_edit_project.remove_categories, @@ -745,18 +745,18 @@ pub struct Extension { #[patch("{id}/icon")] #[allow(clippy::too_many_arguments)] pub async fn project_icon_edit( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - payload: web::Payload, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::project_icon_edit( - web::Query(v3::projects::Extension { ext: ext.ext }), + web::types::Query(v3::projects::Extension { ext: ext.ext }), req, info, pool, @@ -772,11 +772,11 @@ pub async fn project_icon_edit( #[delete("{id}/icon")] pub async fn delete_project_icon( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::delete_project_icon( @@ -804,21 +804,21 @@ pub struct GalleryCreateQuery { #[post("{id}/gallery")] #[allow(clippy::too_many_arguments)] pub async fn add_gallery_item( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - web::Query(item): web::Query, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - payload: web::Payload, - session_queue: web::Data, + web::types::Query(item): web::types::Query, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::add_gallery_item( - web::Query(v3::projects::Extension { ext: ext.ext }), + web::types::Query(v3::projects::Extension { ext: ext.ext }), req, - web::Query(v3::projects::GalleryCreateQuery { + web::types::Query(v3::projects::GalleryCreateQuery { featured: item.featured, name: item.title, description: item.description, @@ -860,15 +860,15 @@ pub struct GalleryEditQuery { #[patch("{id}/gallery")] pub async fn edit_gallery_item( req: HttpRequest, - web::Query(item): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(item): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::edit_gallery_item( req, - web::Query(v3::projects::GalleryEditQuery { + web::types::Query(v3::projects::GalleryEditQuery { url: item.url, featured: item.featured, name: item.title, @@ -891,16 +891,16 @@ pub struct GalleryDeleteQuery { #[delete("{id}/gallery")] pub async fn delete_gallery_item( req: HttpRequest, - web::Query(item): web::Query, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - session_queue: web::Data, + web::types::Query(item): web::types::Query, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::delete_gallery_item( req, - web::Query(v3::projects::GalleryDeleteQuery { url: item.url }), + web::types::Query(v3::projects::GalleryDeleteQuery { url: item.url }), pool, redis, file_host, @@ -913,11 +913,11 @@ pub async fn delete_gallery_item( #[delete("{id}")] pub async fn project_delete( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - search_config: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + search_config: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::project_delete( @@ -935,10 +935,10 @@ pub async fn project_delete( #[post("{id}/follow")] pub async fn project_follow( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::project_follow(req, info, pool, redis, session_queue) @@ -949,10 +949,10 @@ pub async fn project_follow( #[delete("{id}/follow")] pub async fn project_unfollow( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::projects::project_unfollow(req, info, pool, redis, session_queue) diff --git a/apps/labrinth/src/routes/v2/reports.rs b/apps/labrinth/src/routes/v2/reports.rs index 35173102d..dd73a270f 100644 --- a/apps/labrinth/src/routes/v2/reports.rs +++ b/apps/labrinth/src/routes/v2/reports.rs @@ -3,7 +3,7 @@ use crate::models::reports::Report; use crate::models::v2::reports::LegacyReport; use crate::queue::session::AuthQueue; use crate::routes::{v2_reroute, v3, ApiError}; -use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse}; +use ntex::web::{self, delete, get, patch, post, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; use validator::Validate; @@ -20,10 +20,10 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[post("report")] pub async fn report_create( req: HttpRequest, - pool: web::Data, - body: web::Payload, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + body: web::types::Payload, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::reports::report_create(req, pool, body, redis, session_queue) @@ -34,7 +34,7 @@ pub async fn report_create( match v2_reroute::extract_ok_json::(response).await { Ok(report) => { let report = LegacyReport::from(report); - Ok(HttpResponse::Ok().json(report)) + Ok(HttpResponse::Ok().json(&report)) } Err(response) => Ok(response), } @@ -58,16 +58,16 @@ fn default_all() -> bool { #[get("report")] pub async fn reports( req: HttpRequest, - pool: web::Data, - redis: web::Data, - count: web::Query, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + count: web::types::Query, + session_queue: web::types::State, ) -> Result { let response = v3::reports::reports( req, pool, redis, - web::Query(v3::reports::ReportsRequestOptions { + web::types::Query(v3::reports::ReportsRequestOptions { count: count.count, all: count.all, }), @@ -81,7 +81,7 @@ pub async fn reports( Ok(reports) => { let reports: Vec<_> = reports.into_iter().map(LegacyReport::from).collect(); - Ok(HttpResponse::Ok().json(reports)) + Ok(HttpResponse::Ok().json(&reports)) } Err(response) => Ok(response), } @@ -95,14 +95,14 @@ pub struct ReportIds { #[get("reports")] pub async fn reports_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::reports::reports_get( req, - web::Query(v3::reports::ReportIds { ids: ids.ids }), + web::types::Query(v3::reports::ReportIds { ids: ids.ids }), pool, redis, session_queue, @@ -115,7 +115,7 @@ pub async fn reports_get( Ok(report_list) => { let report_list: Vec<_> = report_list.into_iter().map(LegacyReport::from).collect(); - Ok(HttpResponse::Ok().json(report_list)) + Ok(HttpResponse::Ok().json(&report_list)) } Err(response) => Ok(response), } @@ -124,10 +124,10 @@ pub async fn reports_get( #[get("report/{id}")] pub async fn report_get( req: HttpRequest, - pool: web::Data, - redis: web::Data, - info: web::Path<(crate::models::reports::ReportId,)>, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + info: web::types::Path<(crate::models::reports::ReportId,)>, + session_queue: web::types::State, ) -> Result { let response = v3::reports::report_get(req, pool, redis, info, session_queue) @@ -138,7 +138,7 @@ pub async fn report_get( match v2_reroute::extract_ok_json::(response).await { Ok(report) => { let report = LegacyReport::from(report); - Ok(HttpResponse::Ok().json(report)) + Ok(HttpResponse::Ok().json(&report)) } Err(response) => Ok(response), } @@ -154,11 +154,11 @@ pub struct EditReport { #[patch("report/{id}")] pub async fn report_edit( req: HttpRequest, - pool: web::Data, - redis: web::Data, - info: web::Path<(crate::models::reports::ReportId,)>, - session_queue: web::Data, - edit_report: web::Json, + pool: web::types::State, + redis: web::types::State, + info: web::types::Path<(crate::models::reports::ReportId,)>, + session_queue: web::types::State, + edit_report: web::types::Json, ) -> Result { let edit_report = edit_report.into_inner(); // Returns NoContent, so no need to convert @@ -168,7 +168,7 @@ pub async fn report_edit( redis, info, session_queue, - web::Json(v3::reports::EditReport { + web::types::Json(v3::reports::EditReport { body: edit_report.body, closed: edit_report.closed, }), @@ -180,10 +180,10 @@ pub async fn report_edit( #[delete("report/{id}")] pub async fn report_delete( req: HttpRequest, - pool: web::Data, - info: web::Path<(crate::models::reports::ReportId,)>, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + info: web::types::Path<(crate::models::reports::ReportId,)>, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert v3::reports::report_delete(req, pool, info, redis, session_queue) diff --git a/apps/labrinth/src/routes/v2/statistics.rs b/apps/labrinth/src/routes/v2/statistics.rs index bd98da12e..d57f45cb2 100644 --- a/apps/labrinth/src/routes/v2/statistics.rs +++ b/apps/labrinth/src/routes/v2/statistics.rs @@ -3,7 +3,7 @@ use crate::routes::{ v3::{self, statistics::V3Stats}, ApiError, }; -use actix_web::{get, web, HttpResponse}; +use ntex::web::{self, get, HttpResponse}; use sqlx::PgPool; pub fn config(cfg: &mut web::ServiceConfig) { @@ -20,7 +20,7 @@ pub struct V2Stats { #[get("statistics")] pub async fn get_stats( - pool: web::Data, + pool: web::types::State, ) -> Result { let response = v3::statistics::get_stats(pool) .await @@ -34,7 +34,7 @@ pub async fn get_stats( authors: stats.authors, files: stats.files, }; - Ok(HttpResponse::Ok().json(stats)) + Ok(HttpResponse::Ok().json(&stats)) } Err(response) => Ok(response), } diff --git a/apps/labrinth/src/routes/v2/tags.rs b/apps/labrinth/src/routes/v2/tags.rs index 3233e9aed..815413160 100644 --- a/apps/labrinth/src/routes/v2/tags.rs +++ b/apps/labrinth/src/routes/v2/tags.rs @@ -7,9 +7,9 @@ use crate::models::v2::projects::LegacySideType; use crate::routes::v2_reroute::capitalize_first; use crate::routes::v3::tags::{LinkPlatformQueryData, LoaderFieldsEnumQuery}; use crate::routes::{v2_reroute, v3}; -use actix_web::{get, web, HttpResponse}; use chrono::{DateTime, Utc}; use itertools::Itertools; +use ntex::web::{self, get, HttpResponse}; use sqlx::PgPool; pub fn config(cfg: &mut web::ServiceConfig) { @@ -37,8 +37,8 @@ pub struct CategoryData { #[get("category")] pub async fn category_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { let response = v3::tags::category_list(pool, redis).await?; @@ -56,7 +56,7 @@ pub async fn category_list( header: c.header, }) .collect::>(); - Ok(HttpResponse::Ok().json(categories)) + Ok(HttpResponse::Ok().json(&categories)) } Err(response) => Ok(response), } @@ -71,8 +71,8 @@ pub struct LoaderData { #[get("loader")] pub async fn loader_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { let response = v3::tags::loader_list(pool, redis).await?; @@ -110,7 +110,7 @@ pub async fn loader_list( } }) .collect::>(); - Ok(HttpResponse::Ok().json(loaders)) + Ok(HttpResponse::Ok().json(&loaders)) } Err(response) => Ok(response), } @@ -133,9 +133,9 @@ pub struct GameVersionQuery { #[get("game_version")] pub async fn game_version_list( - pool: web::Data, - query: web::Query, - redis: web::Data, + pool: web::types::State, + query: web::types::Query, + redis: web::types::State, ) -> Result { let mut filters = HashMap::new(); if let Some(type_) = &query.type_ { @@ -146,7 +146,7 @@ pub async fn game_version_list( } let response = v3::tags::loader_fields_list( pool, - web::Query(LoaderFieldsEnumQuery { + web::types::Query(LoaderFieldsEnumQuery { loader_field: "game_versions".to_string(), filters: Some(filters), }), @@ -178,7 +178,7 @@ pub async fn game_version_list( .unwrap_or_default(), }) .collect::>(); - HttpResponse::Ok().json(fields) + HttpResponse::Ok().json(&fields) } Err(response) => response, }, @@ -206,7 +206,7 @@ pub async fn license_list() -> HttpResponse { name: l.name, }) .collect::>(); - HttpResponse::Ok().json(licenses) + HttpResponse::Ok().json(&licenses) } Err(response) => response, } @@ -220,7 +220,7 @@ pub struct LicenseText { #[get("license/{id}")] pub async fn license_text( - params: web::Path<(String,)>, + params: web::types::Path<(String,)>, ) -> Result { let license = v3::tags::license_text(params) .await @@ -231,7 +231,7 @@ pub async fn license_text( match v2_reroute::extract_ok_json::(license) .await { - Ok(license) => HttpResponse::Ok().json(LicenseText { + Ok(license) => HttpResponse::Ok().json(&LicenseText { title: license.title, body: license.body, }), @@ -251,8 +251,8 @@ pub struct DonationPlatformQueryData { #[get("donation_platform")] pub async fn donation_platform_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { let response = v3::tags::link_platform_list(pool, redis).await?; @@ -287,7 +287,7 @@ pub async fn donation_platform_list( } }) .collect::>(); - HttpResponse::Ok().json(platforms) + HttpResponse::Ok().json(&platforms) } Err(response) => response, }, @@ -297,8 +297,8 @@ pub async fn donation_platform_list( #[get("report_type")] pub async fn report_type_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { // This returns a list of strings directly, so we don't need to convert to v2 format. v3::tags::report_type_list(pool, redis) @@ -308,8 +308,8 @@ pub async fn report_type_list( #[get("project_type")] pub async fn project_type_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { // This returns a list of strings directly, so we don't need to convert to v2 format. v3::tags::project_type_list(pool, redis) @@ -328,5 +328,5 @@ pub async fn side_type_list() -> Result { LegacySideType::Unknown, ]; let side_types = side_types.iter().map(|s| s.to_string()).collect_vec(); - Ok(HttpResponse::Ok().json(side_types)) + Ok(HttpResponse::Ok().json(&side_types)) } diff --git a/apps/labrinth/src/routes/v2/teams.rs b/apps/labrinth/src/routes/v2/teams.rs index 444ff13ec..b4282614c 100644 --- a/apps/labrinth/src/routes/v2/teams.rs +++ b/apps/labrinth/src/routes/v2/teams.rs @@ -6,7 +6,7 @@ use crate::models::users::UserId; use crate::models::v2::teams::LegacyTeamMember; use crate::queue::session::AuthQueue; use crate::routes::{v2_reroute, v3, ApiError}; -use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse}; +use ntex::web::{self, delete, get, patch, post, HttpRequest, HttpResponse}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -33,10 +33,10 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("{id}/members")] pub async fn team_members_get_project( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::teams::team_members_get_project( req, @@ -54,7 +54,7 @@ pub async fn team_members_get_project( .into_iter() .map(LegacyTeamMember::from) .collect::>(); - Ok(HttpResponse::Ok().json(members)) + Ok(HttpResponse::Ok().json(&members)) } Err(response) => Ok(response), } @@ -64,10 +64,10 @@ pub async fn team_members_get_project( #[get("{id}/members")] pub async fn team_members_get( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::teams::team_members_get(req, info, pool, redis, session_queue) @@ -80,7 +80,7 @@ pub async fn team_members_get( .into_iter() .map(LegacyTeamMember::from) .collect::>(); - Ok(HttpResponse::Ok().json(members)) + Ok(HttpResponse::Ok().json(&members)) } Err(response) => Ok(response), } @@ -94,14 +94,14 @@ pub struct TeamIds { #[get("teams")] pub async fn teams_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::teams::teams_get( req, - web::Query(v3::teams::TeamIds { ids: ids.ids }), + web::types::Query(v3::teams::TeamIds { ids: ids.ids }), pool, redis, session_queue, @@ -120,7 +120,7 @@ pub async fn teams_get( .collect::>() }) .collect::>(); - Ok(HttpResponse::Ok().json(members)) + Ok(HttpResponse::Ok().json(&members)) } Err(response) => Ok(response), } @@ -129,10 +129,10 @@ pub async fn teams_get( #[post("{id}/join")] pub async fn join_team( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert the response v3::teams::join_team(req, info, pool, redis, session_queue) @@ -167,18 +167,18 @@ pub struct NewTeamMember { #[post("{id}/members")] pub async fn add_team_member( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - new_member: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + new_member: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert the response v3::teams::add_team_member( req, info, pool, - web::Json(v3::teams::NewTeamMember { + web::types::Json(v3::teams::NewTeamMember { user_id: new_member.user_id, role: new_member.role.clone(), permissions: new_member.permissions, @@ -205,18 +205,18 @@ pub struct EditTeamMember { #[patch("{id}/members/{user_id}")] pub async fn edit_team_member( req: HttpRequest, - info: web::Path<(TeamId, UserId)>, - pool: web::Data, - edit_member: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId, UserId)>, + pool: web::types::State, + edit_member: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert the response v3::teams::edit_team_member( req, info, pool, - web::Json(v3::teams::EditTeamMember { + web::types::Json(v3::teams::EditTeamMember { permissions: edit_member.permissions, organization_permissions: edit_member.organization_permissions, role: edit_member.role.clone(), @@ -238,18 +238,18 @@ pub struct TransferOwnership { #[patch("{id}/owner")] pub async fn transfer_ownership( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - new_owner: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + new_owner: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert the response v3::teams::transfer_ownership( req, info, pool, - web::Json(v3::teams::TransferOwnership { + web::types::Json(v3::teams::TransferOwnership { user_id: new_owner.user_id, }), redis, @@ -262,10 +262,10 @@ pub async fn transfer_ownership( #[delete("{id}/members/{user_id}")] pub async fn remove_team_member( req: HttpRequest, - info: web::Path<(TeamId, UserId)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId, UserId)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert the response v3::teams::remove_team_member(req, info, pool, redis, session_queue) diff --git a/apps/labrinth/src/routes/v2/threads.rs b/apps/labrinth/src/routes/v2/threads.rs index ab5e781a5..55fab55a2 100644 --- a/apps/labrinth/src/routes/v2/threads.rs +++ b/apps/labrinth/src/routes/v2/threads.rs @@ -7,7 +7,7 @@ use crate::models::threads::{MessageBody, Thread, ThreadId}; use crate::models::v2::threads::LegacyThread; use crate::queue::session::AuthQueue; use crate::routes::{v2_reroute, v3, ApiError}; -use actix_web::{delete, get, post, web, HttpRequest, HttpResponse}; +use ntex::web::{self, delete, get, post, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; @@ -24,10 +24,10 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("{id}")] pub async fn thread_get( req: HttpRequest, - info: web::Path<(ThreadId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(ThreadId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { v3::threads::thread_get(req, info, pool, redis, session_queue) .await @@ -42,14 +42,14 @@ pub struct ThreadIds { #[get("threads")] pub async fn threads_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::threads::threads_get( req, - web::Query(v3::threads::ThreadIds { ids: ids.ids }), + web::types::Query(v3::threads::ThreadIds { ids: ids.ids }), pool, redis, session_queue, @@ -64,7 +64,7 @@ pub async fn threads_get( .into_iter() .map(LegacyThread::from) .collect::>(); - Ok(HttpResponse::Ok().json(threads)) + Ok(HttpResponse::Ok().json(&threads)) } Err(response) => Ok(response), } @@ -78,11 +78,11 @@ pub struct NewThreadMessage { #[post("{id}")] pub async fn thread_send_message( req: HttpRequest, - info: web::Path<(ThreadId,)>, - pool: web::Data, - new_message: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(ThreadId,)>, + pool: web::types::State, + new_message: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let new_message = new_message.into_inner(); // Returns NoContent, so we don't need to convert the response @@ -90,7 +90,7 @@ pub async fn thread_send_message( req, info, pool, - web::Json(v3::threads::NewThreadMessage { + web::types::Json(v3::threads::NewThreadMessage { body: new_message.body, }), redis, @@ -103,11 +103,11 @@ pub async fn thread_send_message( #[delete("{id}")] pub async fn message_delete( req: HttpRequest, - info: web::Path<(ThreadMessageId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - file_host: web::Data>, + info: web::types::Path<(ThreadMessageId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + file_host: web::types::State>, ) -> Result { // Returns NoContent, so we don't need to convert the response v3::threads::message_delete( diff --git a/apps/labrinth/src/routes/v2/users.rs b/apps/labrinth/src/routes/v2/users.rs index 573af4300..0a9c0ab54 100644 --- a/apps/labrinth/src/routes/v2/users.rs +++ b/apps/labrinth/src/routes/v2/users.rs @@ -8,8 +8,8 @@ use crate::models::v2::projects::LegacyProject; use crate::models::v2::user::LegacyUser; use crate::queue::session::AuthQueue; use crate::routes::{v2_reroute, v3, ApiError}; -use actix_web::{delete, get, patch, web, HttpRequest, HttpResponse}; use lazy_static::lazy_static; +use ntex::web::{self, delete, get, patch, HttpRequest, HttpResponse}; use regex::Regex; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -35,9 +35,9 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("user")] pub async fn user_auth_get( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::users::user_auth_get(req, pool, redis, session_queue) .await @@ -47,7 +47,7 @@ pub async fn user_auth_get( match v2_reroute::extract_ok_json::(response).await { Ok(user) => { let user = LegacyUser::from(user); - Ok(HttpResponse::Ok().json(user)) + Ok(HttpResponse::Ok().json(&user)) } Err(response) => Ok(response), } @@ -60,12 +60,12 @@ pub struct UserIds { #[get("users")] pub async fn users_get( - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, ) -> Result { let response = v3::users::users_get( - web::Query(v3::users::UserIds { ids: ids.ids }), + web::types::Query(v3::users::UserIds { ids: ids.ids }), pool, redis, ) @@ -77,7 +77,7 @@ pub async fn users_get( Ok(users) => { let legacy_users: Vec = users.into_iter().map(LegacyUser::from).collect(); - Ok(HttpResponse::Ok().json(legacy_users)) + Ok(HttpResponse::Ok().json(&legacy_users)) } Err(response) => Ok(response), } @@ -85,9 +85,9 @@ pub async fn users_get( #[get("{id}")] pub async fn user_get( - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, ) -> Result { let response = v3::users::user_get(info, pool, redis) .await @@ -97,7 +97,7 @@ pub async fn user_get( match v2_reroute::extract_ok_json::(response).await { Ok(user) => { let user = LegacyUser::from(user); - Ok(HttpResponse::Ok().json(user)) + Ok(HttpResponse::Ok().json(&user)) } Err(response) => Ok(response), } @@ -106,10 +106,10 @@ pub async fn user_get( #[get("{user_id}/projects")] pub async fn projects_list( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::users::projects_list( req, @@ -125,8 +125,8 @@ pub async fn projects_list( match v2_reroute::extract_ok_json::>(response).await { Ok(project) => { let legacy_projects = - LegacyProject::from_many(project, &**pool, &redis).await?; - Ok(HttpResponse::Ok().json(legacy_projects)) + LegacyProject::from_many(project, &*pool, &redis).await?; + Ok(HttpResponse::Ok().json(&legacy_projects)) } Err(response) => Ok(response), } @@ -162,18 +162,18 @@ pub struct EditUser { #[patch("{id}")] pub async fn user_edit( req: HttpRequest, - info: web::Path<(String,)>, - new_user: web::Json, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + new_user: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let new_user = new_user.into_inner(); // Returns NoContent, so we don't need to convert to V2 v3::users::user_edit( req, info, - web::Json(v3::users::EditUser { + web::types::Json(v3::users::EditUser { username: new_user.username, bio: new_user.bio, role: new_user.role, @@ -197,18 +197,18 @@ pub struct Extension { #[patch("{id}/icon")] #[allow(clippy::too_many_arguments)] pub async fn user_icon_edit( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - payload: web::Payload, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert to V2 v3::users::user_icon_edit( - web::Query(v3::users::Extension { ext: ext.ext }), + web::types::Query(v3::users::Extension { ext: ext.ext }), req, info, pool, @@ -224,10 +224,10 @@ pub async fn user_icon_edit( #[delete("{id}")] pub async fn user_delete( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert to V2 v3::users::user_delete(req, info, pool, redis, session_queue) @@ -238,10 +238,10 @@ pub async fn user_delete( #[get("{id}/follows")] pub async fn user_follows( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::users::user_follows( req, @@ -257,8 +257,8 @@ pub async fn user_follows( match v2_reroute::extract_ok_json::>(response).await { Ok(project) => { let legacy_projects = - LegacyProject::from_many(project, &**pool, &redis).await?; - Ok(HttpResponse::Ok().json(legacy_projects)) + LegacyProject::from_many(project, &*pool, &redis).await?; + Ok(HttpResponse::Ok().json(&legacy_projects)) } Err(response) => Ok(response), } @@ -267,10 +267,10 @@ pub async fn user_follows( #[get("{id}/notifications")] pub async fn user_notifications( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let response = v3::users::user_notifications(req, info, pool, redis, session_queue) @@ -283,7 +283,7 @@ pub async fn user_notifications( .into_iter() .map(LegacyNotification::from) .collect(); - Ok(HttpResponse::Ok().json(legacy_notifications)) + Ok(HttpResponse::Ok().json(&legacy_notifications)) } Err(response) => Ok(response), } diff --git a/apps/labrinth/src/routes/v2/version_creation.rs b/apps/labrinth/src/routes/v2/version_creation.rs index ba8248db7..e55a907ae 100644 --- a/apps/labrinth/src/routes/v2/version_creation.rs +++ b/apps/labrinth/src/routes/v2/version_creation.rs @@ -13,10 +13,8 @@ use crate::queue::session::AuthQueue; use crate::routes::v3::project_creation::CreateError; use crate::routes::v3::version_creation; use crate::routes::{v2_reroute, v3}; -use actix_multipart::Multipart; -use actix_web::http::header::ContentDisposition; -use actix_web::web::Data; -use actix_web::{post, web, HttpRequest, HttpResponse}; +use ntex::web::{self, post, HttpRequest, HttpResponse}; +use ntex_multipart::Multipart; use serde::{Deserialize, Serialize}; use serde_json::json; use sqlx::postgres::PgPool; @@ -85,11 +83,11 @@ struct InitialFileData { pub async fn version_create( req: HttpRequest, payload: Multipart, - client: Data, - redis: Data, - file_host: Data>, - session_queue: Data, - moderation_queue: Data, + client: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, + moderation_queue: web::types::State, ) -> Result { let payload = v2_reroute::alter_actix_multipart( payload, @@ -272,7 +270,7 @@ pub async fn version_create( match v2_reroute::extract_ok_json::(response).await { Ok(version) => { let v2_version = LegacyVersion::from(version); - Ok(HttpResponse::Ok().json(v2_version)) + Ok(HttpResponse::Ok().json(&v2_version)) } Err(response) => Ok(response), } @@ -281,7 +279,7 @@ pub async fn version_create( // Gets version fields of an example version of a project, if one exists. async fn get_example_version_fields( project_id: Option, - pool: Data, + pool: web::types::State, redis: &RedisPool, ) -> Result>, CreateError> { let project_id = match project_id { @@ -290,7 +288,7 @@ async fn get_example_version_fields( }; let vid = - match project_item::Project::get_id(project_id.into(), &**pool, redis) + match project_item::Project::get_id(project_id.into(), &*pool, redis) .await? .and_then(|p| p.versions.first().cloned()) { @@ -299,7 +297,7 @@ async fn get_example_version_fields( }; let example_version = - match version_item::Version::get(vid, &**pool, redis).await? { + match version_item::Version::get(vid, &*pool, redis).await? { Some(version) => version, None => return Ok(None), }; @@ -310,12 +308,12 @@ async fn get_example_version_fields( #[post("{version_id}/file")] pub async fn upload_file_to_version( req: HttpRequest, - url_data: web::Path<(VersionId,)>, + url_data: web::types::Path<(VersionId,)>, payload: Multipart, - client: Data, - redis: Data, - file_host: Data>, - session_queue: web::Data, + client: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert to V2 let response = v3::version_creation::upload_file_to_version( diff --git a/apps/labrinth/src/routes/v2/version_file.rs b/apps/labrinth/src/routes/v2/version_file.rs index bb998b661..fbbe7b797 100644 --- a/apps/labrinth/src/routes/v2/version_file.rs +++ b/apps/labrinth/src/routes/v2/version_file.rs @@ -5,7 +5,7 @@ use crate::models::v2::projects::{LegacyProject, LegacyVersion}; use crate::queue::session::AuthQueue; use crate::routes::v3::version_file::HashQuery; use crate::routes::{v2_reroute, v3}; -use actix_web::{delete, get, post, web, HttpRequest, HttpResponse}; +use ntex::web::{self, delete, get, post, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; use std::collections::HashMap; @@ -32,11 +32,11 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("{version_id}")] pub async fn get_version_from_hash( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + session_queue: web::types::State, ) -> Result { let response = v3::version_file::get_version_from_hash( req, @@ -53,7 +53,7 @@ pub async fn get_version_from_hash( match v2_reroute::extract_ok_json::(response).await { Ok(version) => { let v2_version = LegacyVersion::from(version); - Ok(HttpResponse::Ok().json(v2_version)) + Ok(HttpResponse::Ok().json(&v2_version)) } Err(response) => Ok(response), } @@ -63,11 +63,11 @@ pub async fn get_version_from_hash( #[get("{version_id}/download")] pub async fn download_version( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + session_queue: web::types::State, ) -> Result { // Returns TemporaryRedirect, so no need to convert to V2 v3::version_file::download_version( @@ -86,11 +86,11 @@ pub async fn download_version( #[delete("{version_id}")] pub async fn delete_file( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + session_queue: web::types::State, ) -> Result { // Returns NoContent, so no need to convert to V2 v3::version_file::delete_file( @@ -115,12 +115,12 @@ pub struct UpdateData { #[post("{version_id}/update")] pub async fn get_update_from_hash( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - update_data: web::Json, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + update_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let update_data = update_data.into_inner(); let mut loader_fields = HashMap::new(); @@ -143,7 +143,7 @@ pub async fn get_update_from_hash( pool, redis, hash_query, - web::Json(update_data), + web::types::Json(update_data), session_queue, ) .await @@ -153,7 +153,7 @@ pub async fn get_update_from_hash( match v2_reroute::extract_ok_json::(response).await { Ok(version) => { let v2_version = LegacyVersion::from(version); - Ok(HttpResponse::Ok().json(v2_version)) + Ok(HttpResponse::Ok().json(&v2_version)) } Err(response) => Ok(response), } @@ -170,10 +170,10 @@ pub struct FileHashes { #[post("")] pub async fn get_versions_from_hashes( req: HttpRequest, - pool: web::Data, - redis: web::Data, - file_data: web::Json, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + file_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let file_data = file_data.into_inner(); let file_data = v3::version_file::FileHashes { @@ -184,7 +184,7 @@ pub async fn get_versions_from_hashes( req, pool, redis, - web::Json(file_data), + web::types::Json(file_data), session_queue, ) .await @@ -202,7 +202,7 @@ pub async fn get_versions_from_hashes( (hash, v2_version) }) .collect::>(); - Ok(HttpResponse::Ok().json(v2_versions)) + Ok(HttpResponse::Ok().json(&v2_versions)) } Err(response) => Ok(response), } @@ -211,10 +211,10 @@ pub async fn get_versions_from_hashes( #[post("project")] pub async fn get_projects_from_hashes( req: HttpRequest, - pool: web::Data, - redis: web::Data, - file_data: web::Json, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + file_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let file_data = file_data.into_inner(); let file_data = v3::version_file::FileHashes { @@ -225,7 +225,7 @@ pub async fn get_projects_from_hashes( req, pool.clone(), redis.clone(), - web::Json(file_data), + web::types::Json(file_data), session_queue, ) .await @@ -245,7 +245,7 @@ pub async fn get_projects_from_hashes( .collect::>(); let legacy_projects = LegacyProject::from_many( projects_hashes.into_values().collect(), - &**pool, + &*pool, &redis, ) .await?; @@ -260,7 +260,7 @@ pub async fn get_projects_from_hashes( }) .collect::>(); - Ok(HttpResponse::Ok().json(legacy_projects_hashes)) + Ok(HttpResponse::Ok().json(&legacy_projects_hashes)) } Err(response) => Ok(response), } @@ -277,9 +277,9 @@ pub struct ManyUpdateData { #[post("update")] pub async fn update_files( - pool: web::Data, - redis: web::Data, - update_data: web::Json, + pool: web::types::State, + redis: web::types::State, + update_data: web::types::Json, ) -> Result { let update_data = update_data.into_inner(); let update_data = v3::version_file::ManyUpdateData { @@ -290,10 +290,13 @@ pub async fn update_files( hashes: update_data.hashes, }; - let response = - v3::version_file::update_files(pool, redis, web::Json(update_data)) - .await - .or_else(v2_reroute::flatten_404_error)?; + let response = v3::version_file::update_files( + pool, + redis, + web::types::Json(update_data), + ) + .await + .or_else(v2_reroute::flatten_404_error)?; // Convert response to V2 format match v2_reroute::extract_ok_json::>(response) @@ -307,7 +310,7 @@ pub async fn update_files( (hash, v2_version) }) .collect::>(); - Ok(HttpResponse::Ok().json(v3_versions)) + Ok(HttpResponse::Ok().json(&v3_versions)) } Err(response) => Ok(response), } @@ -330,10 +333,10 @@ pub struct ManyFileUpdateData { #[post("update_individual")] pub async fn update_individual_files( req: HttpRequest, - pool: web::Data, - redis: web::Data, - update_data: web::Json, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + update_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let update_data = update_data.into_inner(); let update_data = v3::version_file::ManyFileUpdateData { @@ -365,7 +368,7 @@ pub async fn update_individual_files( req, pool, redis, - web::Json(update_data), + web::types::Json(update_data), session_queue, ) .await @@ -383,7 +386,7 @@ pub async fn update_individual_files( (hash, v2_version) }) .collect::>(); - Ok(HttpResponse::Ok().json(v3_versions)) + Ok(HttpResponse::Ok().json(&v3_versions)) } Err(response) => Ok(response), } diff --git a/apps/labrinth/src/routes/v2/versions.rs b/apps/labrinth/src/routes/v2/versions.rs index 4d642542c..6d57d1b2a 100644 --- a/apps/labrinth/src/routes/v2/versions.rs +++ b/apps/labrinth/src/routes/v2/versions.rs @@ -11,21 +11,21 @@ use crate::models::v2::projects::LegacyVersion; use crate::queue::session::AuthQueue; use crate::routes::{v2_reroute, v3}; use crate::search::SearchConfig; -use actix_web::{delete, get, patch, web, HttpRequest, HttpResponse}; +use ntex::web::{self, delete, get, patch, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; use validator::Validate; pub fn config(cfg: &mut web::ServiceConfig) { cfg.service(versions_get); - cfg.service(super::version_creation::version_create); + // TODO: fix me + // cfg.service(super::version_creation::version_create); cfg.service( web::scope("version") .service(version_get) .service(version_delete) - .service(version_edit) - .service(super::version_creation::upload_file_to_version), + .service(version_edit), // .service(super::version_creation::upload_file_to_version), ); } @@ -42,11 +42,11 @@ pub struct VersionListFilters { #[get("version")] pub async fn version_list( req: HttpRequest, - info: web::Path<(String,)>, - web::Query(filters): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + web::types::Query(filters): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let loaders = if let Some(loaders) = filters.loaders { if let Ok(mut loaders) = serde_json::from_str::>(&loaders) { @@ -100,7 +100,7 @@ pub async fn version_list( let response = v3::versions::version_list( req, info, - web::Query(filters), + web::types::Query(filters), pool, redis, session_queue, @@ -115,7 +115,7 @@ pub async fn version_list( .into_iter() .map(LegacyVersion::from) .collect::>(); - Ok(HttpResponse::Ok().json(v2_versions)) + Ok(HttpResponse::Ok().json(&v2_versions)) } Err(response) => Ok(response), } @@ -125,10 +125,10 @@ pub async fn version_list( #[get("version/{slug}")] pub async fn version_project_get( req: HttpRequest, - info: web::Path<(String, String)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String, String)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let id = info.into_inner(); let response = v3::versions::version_project_get_helper( @@ -144,7 +144,7 @@ pub async fn version_project_get( match v2_reroute::extract_ok_json::(response).await { Ok(version) => { let v2_version = LegacyVersion::from(version); - Ok(HttpResponse::Ok().json(v2_version)) + Ok(HttpResponse::Ok().json(&v2_version)) } Err(response) => Ok(response), } @@ -158,15 +158,15 @@ pub struct VersionIds { #[get("versions")] pub async fn versions_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let ids = v3::versions::VersionIds { ids: ids.ids }; let response = v3::versions::versions_get( req, - web::Query(ids), + web::types::Query(ids), pool, redis, session_queue, @@ -181,7 +181,7 @@ pub async fn versions_get( .into_iter() .map(LegacyVersion::from) .collect::>(); - Ok(HttpResponse::Ok().json(v2_versions)) + Ok(HttpResponse::Ok().json(&v2_versions)) } Err(response) => Ok(response), } @@ -190,10 +190,10 @@ pub async fn versions_get( #[get("{version_id}")] pub async fn version_get( req: HttpRequest, - info: web::Path<(models::ids::VersionId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(models::ids::VersionId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let id = info.into_inner().0; let response = @@ -204,7 +204,7 @@ pub async fn version_get( match v2_reroute::extract_ok_json::(response).await { Ok(version) => { let v2_version = LegacyVersion::from(version); - Ok(HttpResponse::Ok().json(v2_version)) + Ok(HttpResponse::Ok().json(&v2_version)) } Err(response) => Ok(response), } @@ -248,11 +248,11 @@ pub struct EditVersionFileType { #[patch("{id}")] pub async fn version_edit( req: HttpRequest, - info: web::Path<(VersionId,)>, - pool: web::Data, - redis: web::Data, - new_version: web::Json, - session_queue: web::Data, + info: web::types::Path<(VersionId,)>, + pool: web::types::State, + redis: web::types::State, + new_version: web::types::Json, + session_queue: web::types::State, ) -> Result { let new_version = new_version.into_inner(); @@ -322,7 +322,7 @@ pub async fn version_edit( info, pool, redis, - web::Json(serde_json::to_value(new_version)?), + web::types::Json(serde_json::to_value(new_version)?), session_queue, ) .await @@ -333,11 +333,11 @@ pub async fn version_edit( #[delete("{version_id}")] pub async fn version_delete( req: HttpRequest, - info: web::Path<(VersionId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - search_config: web::Data, + info: web::types::Path<(VersionId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + search_config: web::types::State, ) -> Result { // Returns NoContent, so we don't need to convert the response v3::versions::version_delete( diff --git a/apps/labrinth/src/routes/v2_reroute.rs b/apps/labrinth/src/routes/v2_reroute.rs index 665f11a7f..b4b25a0d9 100644 --- a/apps/labrinth/src/routes/v2_reroute.rs +++ b/apps/labrinth/src/routes/v2_reroute.rs @@ -1,17 +1,15 @@ use std::collections::HashMap; -use super::v3::project_creation::CreateError; +// use super::v3::project_creation::CreateError; use super::ApiError; use crate::models::v2::projects::LegacySideType; use crate::util::actix::{ generate_multipart, MultipartSegment, MultipartSegmentData, }; -use actix_multipart::Multipart; -use actix_web::http::header::{ - ContentDisposition, HeaderMap, TryIntoHeaderPair, -}; -use actix_web::HttpResponse; use futures::{stream, Future, StreamExt}; +use ntex::http::header::HeaderMap; +use ntex::web::HttpResponse; +use ntex_multipart::Multipart; use serde_json::{json, Value}; pub async fn extract_ok_json( @@ -21,21 +19,24 @@ where T: serde::de::DeserializeOwned, { // If the response is StatusCode::OK, parse the json and return it - if response.status() == actix_web::http::StatusCode::OK { + if response.status() == ntex::http::StatusCode::OK { let failure_http_response = || { - HttpResponse::InternalServerError().json(json!({ + HttpResponse::InternalServerError().json(&json!({ "error": "reroute_error", "description": "Could not parse response from V2 redirection of route." })) }; + + // TODO: fix me + Err(failure_http_response()) // Takes json out of HttpResponse, mutates it, then regenerates the HttpResponse - let body = response.into_body(); - let bytes = actix_web::body::to_bytes(body) - .await - .map_err(|_| failure_http_response())?; - let json_value: T = serde_json::from_slice(&bytes) - .map_err(|_| failure_http_response())?; - Ok(json_value) + // let body = response.into_body(); + // let bytes = actix_web::body::to_bytes(body) + // .await + // .map_err(|_| failure_http_response())?; + // let json_value: T = serde_json::from_slice(&bytes) + // .map_err(|_| failure_http_response())?; + // Ok(json_value) } else { Err(response) } @@ -55,115 +56,115 @@ pub fn flatten_404_error(res: ApiError) -> Result { // 1. A json segment // 2. Any number of other binary segments // 'closure' is called with the json value, and the content disposition of the other segments -pub async fn alter_actix_multipart( - mut multipart: Multipart, - mut headers: HeaderMap, - mut closure: impl FnMut(T, Vec) -> Fut, -) -> Result -where - T: serde::de::DeserializeOwned, - U: serde::Serialize, - Fut: Future>, -{ - let mut segments: Vec = Vec::new(); - - let mut json = None; - let mut json_segment = None; - let mut content_dispositions = Vec::new(); - - if let Some(field) = multipart.next().await { - let mut field = field?; - let content_disposition = field.content_disposition().clone(); - let field_name = content_disposition.get_name().unwrap_or(""); - let field_filename = content_disposition.get_filename(); - let field_content_type = field.content_type(); - let field_content_type = field_content_type.map(|ct| ct.to_string()); - - let mut buffer = Vec::new(); - while let Some(chunk) = field.next().await { - let data = chunk?; - buffer.extend_from_slice(&data); - } - - { - let json_value: T = serde_json::from_slice(&buffer)?; - json = Some(json_value); - } - - json_segment = Some(MultipartSegment { - name: field_name.to_string(), - filename: field_filename.map(|s| s.to_string()), - content_type: field_content_type, - data: MultipartSegmentData::Binary(vec![]), // Initialize to empty, will be finished after - }); - } - - while let Some(field) = multipart.next().await { - let mut field = field?; - let content_disposition = field.content_disposition().clone(); - let field_name = content_disposition.get_name().unwrap_or(""); - let field_filename = content_disposition.get_filename(); - let field_content_type = field.content_type(); - let field_content_type = field_content_type.map(|ct| ct.to_string()); - - let mut buffer = Vec::new(); - while let Some(chunk) = field.next().await { - let data = chunk?; - buffer.extend_from_slice(&data); - } - - content_dispositions.push(content_disposition.clone()); - segments.push(MultipartSegment { - name: field_name.to_string(), - filename: field_filename.map(|s| s.to_string()), - content_type: field_content_type, - data: MultipartSegmentData::Binary(buffer), - }) - } - - // Finishes the json segment, with aggregated content dispositions - { - let json_value = json.ok_or(CreateError::InvalidInput( - "No json segment found in multipart.".to_string(), - ))?; - let mut json_segment = - json_segment.ok_or(CreateError::InvalidInput( - "No json segment found in multipart.".to_string(), - ))?; - - // Call closure, with the json value and names of the other segments - let json_value: U = closure(json_value, content_dispositions).await?; - let buffer = serde_json::to_vec(&json_value)?; - json_segment.data = MultipartSegmentData::Binary(buffer); - - // Insert the json segment at the beginning - segments.insert(0, json_segment); - } - - let (boundary, payload) = generate_multipart(segments); - - match ( - "Content-Type", - format!("multipart/form-data; boundary={}", boundary).as_str(), - ) - .try_into_pair() - { - Ok((key, value)) => { - headers.insert(key, value); - } - Err(err) => { - CreateError::InvalidInput(format!( - "Error inserting test header: {:?}.", - err - )); - } - }; - - let new_multipart = - Multipart::new(&headers, stream::once(async { Ok(payload) })); - - Ok(new_multipart) -} +// pub async fn alter_actix_multipart( +// mut multipart: Multipart, +// mut headers: HeaderMap, +// mut closure: impl FnMut(T, Vec) -> Fut, +// ) -> Result +// where +// T: serde::de::DeserializeOwned, +// U: serde::Serialize, +// Fut: Future>, +// { +// let mut segments: Vec = Vec::new(); +// +// let mut json = None; +// let mut json_segment = None; +// let mut content_dispositions = Vec::new(); +// +// if let Some(field) = multipart.next().await { +// let mut field = field?; +// let content_disposition = field.content_disposition().clone(); +// let field_name = content_disposition.get_name().unwrap_or(""); +// let field_filename = content_disposition.get_filename(); +// let field_content_type = field.content_type(); +// let field_content_type = field_content_type.map(|ct| ct.to_string()); +// +// let mut buffer = Vec::new(); +// while let Some(chunk) = field.next().await { +// let data = chunk?; +// buffer.extend_from_slice(&data); +// } +// +// { +// let json_value: T = serde_json::from_slice(&buffer)?; +// json = Some(json_value); +// } +// +// json_segment = Some(MultipartSegment { +// name: field_name.to_string(), +// filename: field_filename.map(|s| s.to_string()), +// content_type: field_content_type, +// data: MultipartSegmentData::Binary(vec![]), // Initialize to empty, will be finished after +// }); +// } +// +// while let Some(field) = multipart.next().await { +// let mut field = field?; +// let content_disposition = field.content_disposition().clone(); +// let field_name = content_disposition.get_name().unwrap_or(""); +// let field_filename = content_disposition.get_filename(); +// let field_content_type = field.content_type(); +// let field_content_type = field_content_type.map(|ct| ct.to_string()); +// +// let mut buffer = Vec::new(); +// while let Some(chunk) = field.next().await { +// let data = chunk?; +// buffer.extend_from_slice(&data); +// } +// +// content_dispositions.push(content_disposition.clone()); +// segments.push(MultipartSegment { +// name: field_name.to_string(), +// filename: field_filename.map(|s| s.to_string()), +// content_type: field_content_type, +// data: MultipartSegmentData::Binary(buffer), +// }) +// } +// +// // Finishes the json segment, with aggregated content dispositions +// { +// let json_value = json.ok_or(CreateError::InvalidInput( +// "No json segment found in multipart.".to_string(), +// ))?; +// let mut json_segment = +// json_segment.ok_or(CreateError::InvalidInput( +// "No json segment found in multipart.".to_string(), +// ))?; +// +// // Call closure, with the json value and names of the other segments +// let json_value: U = closure(json_value, content_dispositions).await?; +// let buffer = serde_json::to_vec(&json_value)?; +// json_segment.data = MultipartSegmentData::Binary(buffer); +// +// // Insert the json segment at the beginning +// segments.insert(0, json_segment); +// } +// +// let (boundary, payload) = generate_multipart(segments); +// +// match ( +// "Content-Type", +// format!("multipart/form-data; boundary={}", boundary).as_str(), +// ) +// .try_into_pair() +// { +// Ok((key, value)) => { +// headers.insert(key, value); +// } +// Err(err) => { +// CreateError::InvalidInput(format!( +// "Error inserting test header: {:?}.", +// err +// )); +// } +// }; +// +// let new_multipart = +// Multipart::new(&headers, stream::once(async { Ok(payload) })); +// +// Ok(new_multipart) +// } // Converts a "client_side" and "server_side" pair into the new v3 corresponding fields pub fn convert_side_types_v3( diff --git a/apps/labrinth/src/routes/v3/analytics_get.rs b/apps/labrinth/src/routes/v3/analytics_get.rs index a31e753b4..73d91a011 100644 --- a/apps/labrinth/src/routes/v3/analytics_get.rs +++ b/apps/labrinth/src/routes/v3/analytics_get.rs @@ -11,8 +11,8 @@ use crate::{ }, queue::session::AuthQueue, }; -use actix_web::{web, HttpRequest, HttpResponse}; use chrono::{DateTime, Duration, Utc}; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::postgres::types::PgInterval; use sqlx::PgPool; @@ -69,15 +69,15 @@ pub struct FetchedPlaytime { } pub async fn playtimes_get( req: HttpRequest, - clickhouse: web::Data, - data: web::Query, - session_queue: web::Data, - pool: web::Data, - redis: web::Data, + clickhouse: web::types::State, + data: web::types::Query, + session_queue: web::types::State, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ANALYTICS]), @@ -107,7 +107,7 @@ pub async fn playtimes_get( start_date, end_date, resolution_minutes, - clickhouse.into_inner(), + &*clickhouse, ) .await?; @@ -122,7 +122,7 @@ pub async fn playtimes_get( } } - Ok(HttpResponse::Ok().json(hm)) + Ok(HttpResponse::Ok().json(&hm)) } /// Get view data for a set of projects or versions @@ -136,15 +136,15 @@ pub async fn playtimes_get( /// Either a list of project_ids or version_ids can be used, but not both. Unauthorized projects/versions will be filtered out. pub async fn views_get( req: HttpRequest, - clickhouse: web::Data, - data: web::Query, - session_queue: web::Data, - pool: web::Data, - redis: web::Data, + clickhouse: web::types::State, + data: web::types::Query, + session_queue: web::types::State, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ANALYTICS]), @@ -174,7 +174,7 @@ pub async fn views_get( start_date, end_date, resolution_minutes, - clickhouse.into_inner(), + &*clickhouse, ) .await?; @@ -189,7 +189,7 @@ pub async fn views_get( } } - Ok(HttpResponse::Ok().json(hm)) + Ok(HttpResponse::Ok().json(&hm)) } /// Get download data for a set of projects or versions @@ -203,15 +203,15 @@ pub async fn views_get( /// Either a list of project_ids or version_ids can be used, but not both. Unauthorized projects/versions will be filtered out. pub async fn downloads_get( req: HttpRequest, - clickhouse: web::Data, - data: web::Query, - session_queue: web::Data, - pool: web::Data, - redis: web::Data, + clickhouse: web::types::State, + data: web::types::Query, + session_queue: web::types::State, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ANALYTICS]), @@ -242,7 +242,7 @@ pub async fn downloads_get( start_date, end_date, resolution_minutes, - clickhouse.into_inner(), + &*clickhouse, ) .await?; @@ -257,7 +257,7 @@ pub async fn downloads_get( } } - Ok(HttpResponse::Ok().json(hm)) + Ok(HttpResponse::Ok().json(&hm)) } /// Get payout data for a set of projects @@ -271,14 +271,14 @@ pub async fn downloads_get( /// ONLY project IDs can be used. Unauthorized projects will be filtered out. pub async fn revenue_get( req: HttpRequest, - data: web::Query, - session_queue: web::Data, - pool: web::Data, - redis: web::Data, + data: web::types::Query, + session_queue: web::types::State, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAYOUTS_READ]), @@ -345,7 +345,7 @@ pub async fn revenue_get( end_date, duration, ) - .fetch_all(&**pool) + .fetch_all(&*pool) .await?.into_iter().map(|x| PayoutValue { mod_id: x.mod_id, amount_sum: x.amount_sum, @@ -364,7 +364,7 @@ pub async fn revenue_get( end_date, duration, ) - .fetch_all(&**pool) + .fetch_all(&*pool) .await?.into_iter().map(|x| PayoutValue { mod_id: x.mod_id, amount_sum: x.amount_sum, @@ -392,7 +392,7 @@ pub async fn revenue_get( } } - Ok(HttpResponse::Ok().json(hm)) + Ok(HttpResponse::Ok().json(&hm)) } /// Get country data for a set of projects or versions @@ -409,15 +409,15 @@ pub async fn revenue_get( /// For this endpoint, provided dates are a range to aggregate over, not specific days to fetch pub async fn countries_downloads_get( req: HttpRequest, - clickhouse: web::Data, - data: web::Query, - session_queue: web::Data, - pool: web::Data, - redis: web::Data, + clickhouse: web::types::State, + data: web::types::Query, + session_queue: web::types::State, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ANALYTICS]), @@ -445,7 +445,7 @@ pub async fn countries_downloads_get( project_ids.unwrap_or_default(), start_date, end_date, - clickhouse.into_inner(), + &*clickhouse, ) .await?; @@ -465,7 +465,7 @@ pub async fn countries_downloads_get( .map(|(key, value)| (key, condense_countries(value))) .collect(); - Ok(HttpResponse::Ok().json(hm)) + Ok(HttpResponse::Ok().json(&hm)) } /// Get country data for a set of projects or versions @@ -482,15 +482,15 @@ pub async fn countries_downloads_get( /// For this endpoint, provided dates are a range to aggregate over, not specific days to fetch pub async fn countries_views_get( req: HttpRequest, - clickhouse: web::Data, - data: web::Query, - session_queue: web::Data, - pool: web::Data, - redis: web::Data, + clickhouse: web::types::State, + data: web::types::Query, + session_queue: web::types::State, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ANALYTICS]), @@ -518,7 +518,7 @@ pub async fn countries_views_get( project_ids.unwrap_or_default(), start_date, end_date, - clickhouse.into_inner(), + &*clickhouse, ) .await?; @@ -538,7 +538,7 @@ pub async fn countries_views_get( .map(|(key, value)| (key, condense_countries(value))) .collect(); - Ok(HttpResponse::Ok().json(hm)) + Ok(HttpResponse::Ok().json(&hm)) } fn condense_countries(countries: HashMap) -> HashMap { @@ -561,14 +561,14 @@ fn condense_countries(countries: HashMap) -> HashMap { async fn filter_allowed_ids( mut project_ids: Option>, user: crate::models::users::User, - pool: &web::Data, + pool: &web::types::State, redis: &RedisPool, remove_defaults: Option, ) -> Result>, ApiError> { // If no project_ids or version_ids are provided, we default to all projects the user has *public* access to if project_ids.is_none() && !remove_defaults.unwrap_or(false) { project_ids = Some( - user_item::User::get_projects(user.id.into(), &***pool, redis) + user_item::User::get_projects(user.id.into(), &**pool, redis) .await? .into_iter() .map(|x| ProjectId::from(x).to_string()) @@ -581,7 +581,7 @@ async fn filter_allowed_ids( let project_ids = if let Some(project_strings) = project_ids { let projects_data = database::models::Project::get_many( &project_strings, - &***pool, + &**pool, redis, ) .await?; @@ -592,7 +592,7 @@ async fn filter_allowed_ids( .collect::>(); let team_members = database::models::TeamMember::get_from_team_full_many( - &team_ids, &***pool, redis, + &team_ids, &**pool, redis, ) .await?; @@ -602,7 +602,7 @@ async fn filter_allowed_ids( .collect::>(); let organizations = database::models::Organization::get_many_ids( &organization_ids, - &***pool, + &**pool, redis, ) .await?; @@ -614,7 +614,7 @@ async fn filter_allowed_ids( let organization_team_members = database::models::TeamMember::get_from_team_full_many( &organization_team_ids, - &***pool, + &**pool, redis, ) .await?; diff --git a/apps/labrinth/src/routes/v3/collections.rs b/apps/labrinth/src/routes/v3/collections.rs index 6a9f19e39..c12bd1af8 100644 --- a/apps/labrinth/src/routes/v3/collections.rs +++ b/apps/labrinth/src/routes/v3/collections.rs @@ -10,16 +10,14 @@ use crate::models::ids::base62_impl::parse_base62; use crate::models::ids::{CollectionId, ProjectId}; use crate::models::pats::Scopes; use crate::queue::session::AuthQueue; -use crate::routes::v3::project_creation::CreateError; use crate::routes::ApiError; use crate::util::img::delete_old_images; use crate::util::routes::read_from_payload; use crate::util::validate::validation_errors_to_string; use crate::{database, models}; -use actix_web::web::Data; -use actix_web::{web, HttpRequest, HttpResponse}; use chrono::Utc; use itertools::Itertools; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; use std::sync::Arc; @@ -58,17 +56,17 @@ pub struct CollectionCreateData { pub async fn collection_create( req: HttpRequest, - collection_create_data: web::Json, - client: Data, - redis: Data, - session_queue: Data, -) -> Result { + collection_create_data: web::types::Json, + client: web::types::State, + redis: web::types::State, + session_queue: web::types::State, +) -> Result { let collection_create_data = collection_create_data.into_inner(); // The currently logged in user let current_user = get_user_from_headers( &req, - &**client, + &*client, &redis, &session_queue, Some(&[Scopes::COLLECTION_CREATE]), @@ -77,7 +75,7 @@ pub async fn collection_create( .1; collection_create_data.validate().map_err(|err| { - CreateError::InvalidInput(validation_errors_to_string(err, None)) + ApiError::InvalidInput(validation_errors_to_string(err, None)) })?; let mut transaction = client.begin().await?; @@ -126,7 +124,7 @@ pub async fn collection_create( }; transaction.commit().await?; - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } #[derive(Serialize, Deserialize)] @@ -135,10 +133,10 @@ pub struct CollectionIds { } pub async fn collections_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let ids = serde_json::from_str::>(&ids.ids)?; let ids = ids @@ -149,11 +147,11 @@ pub async fn collections_get( .collect::, _>>()?; let collections_data = - database::models::Collection::get_many(&ids, &**pool, &redis).await?; + database::models::Collection::get_many(&ids, &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::COLLECTION_READ]), @@ -165,24 +163,24 @@ pub async fn collections_get( let collections = filter_visible_collections(collections_data, &user_option).await?; - Ok(HttpResponse::Ok().json(collections)) + Ok(HttpResponse::Ok().json(&collections)) } pub async fn collection_get( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let string = info.into_inner().0; let id = database::models::CollectionId(parse_base62(&string)? as i64); let collection_data = - database::models::Collection::get(id, &**pool, &redis).await?; + database::models::Collection::get(id, &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::COLLECTION_READ]), @@ -193,7 +191,7 @@ pub async fn collection_get( if let Some(data) = collection_data { if is_visible_collection(&data, &user_option).await? { - return Ok(HttpResponse::Ok().json(Collection::from(data))); + return Ok(HttpResponse::Ok().json(&Collection::from(data))); } } Err(ApiError::NotFound) @@ -220,15 +218,15 @@ pub struct EditCollection { pub async fn collection_edit( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - new_collection: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + new_collection: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::COLLECTION_WRITE]), @@ -242,7 +240,7 @@ pub async fn collection_edit( let string = info.into_inner().0; let id = database::models::CollectionId(parse_base62(&string)? as i64); - let result = database::models::Collection::get(id, &**pool, &redis).await?; + let result = database::models::Collection::get(id, &*pool, &redis).await?; if let Some(collection_item) = result { if !can_modify_collection(&collection_item, &user) { @@ -323,7 +321,7 @@ pub async fn collection_edit( let mut validated_project_ids = Vec::new(); for project_id in new_project_ids { let project = - database::models::Project::get(project_id, &**pool, &redis) + database::models::Project::get(project_id, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput(format!( @@ -374,18 +372,18 @@ pub struct Extension { #[allow(clippy::too_many_arguments)] pub async fn collection_icon_edit( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - mut payload: web::Payload, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + mut payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::COLLECTION_WRITE]), @@ -395,14 +393,13 @@ pub async fn collection_icon_edit( let string = info.into_inner().0; let id = database::models::CollectionId(parse_base62(&string)? as i64); - let collection_item = - database::models::Collection::get(id, &**pool, &redis) - .await? - .ok_or_else(|| { - ApiError::InvalidInput( - "The specified collection does not exist!".to_string(), - ) - })?; + let collection_item = database::models::Collection::get(id, &*pool, &redis) + .await? + .ok_or_else(|| { + ApiError::InvalidInput( + "The specified collection does not exist!".to_string(), + ) + })?; if !can_modify_collection(&collection_item, &user) { return Ok(HttpResponse::Unauthorized().body("")); @@ -411,7 +408,7 @@ pub async fn collection_icon_edit( delete_old_images( collection_item.icon_url, collection_item.raw_icon_url, - &***file_host, + &**file_host, ) .await?; @@ -429,7 +426,7 @@ pub async fn collection_icon_edit( &ext.ext, Some(96), Some(1.0), - &***file_host, + &**file_host, ) .await?; @@ -458,15 +455,15 @@ pub async fn collection_icon_edit( pub async fn delete_collection_icon( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::COLLECTION_WRITE]), @@ -476,14 +473,13 @@ pub async fn delete_collection_icon( let string = info.into_inner().0; let id = database::models::CollectionId(parse_base62(&string)? as i64); - let collection_item = - database::models::Collection::get(id, &**pool, &redis) - .await? - .ok_or_else(|| { - ApiError::InvalidInput( - "The specified collection does not exist!".to_string(), - ) - })?; + let collection_item = database::models::Collection::get(id, &*pool, &redis) + .await? + .ok_or_else(|| { + ApiError::InvalidInput( + "The specified collection does not exist!".to_string(), + ) + })?; if !can_modify_collection(&collection_item, &user) { return Ok(HttpResponse::Unauthorized().body("")); } @@ -491,7 +487,7 @@ pub async fn delete_collection_icon( delete_old_images( collection_item.icon_url, collection_item.raw_icon_url, - &***file_host, + &**file_host, ) .await?; let mut transaction = pool.begin().await?; @@ -516,14 +512,14 @@ pub async fn delete_collection_icon( pub async fn collection_delete( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::COLLECTION_DELETE]), @@ -533,7 +529,7 @@ pub async fn collection_delete( let string = info.into_inner().0; let id = database::models::CollectionId(parse_base62(&string)? as i64); - let collection = database::models::Collection::get(id, &**pool, &redis) + let collection = database::models::Collection::get(id, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( diff --git a/apps/labrinth/src/routes/v3/friends.rs b/apps/labrinth/src/routes/v3/friends.rs index 9541c3dd5..a09ed2a0a 100644 --- a/apps/labrinth/src/routes/v3/friends.rs +++ b/apps/labrinth/src/routes/v3/friends.rs @@ -7,8 +7,8 @@ use crate::queue::session::AuthQueue; use crate::queue::socket::ActiveSockets; use crate::routes::internal::statuses::{close_socket, ServerToClientMessage}; use crate::routes::ApiError; -use actix_web::{delete, get, post, web, HttpRequest, HttpResponse}; use chrono::Utc; +use ntex::web::{self, delete, get, post, HttpRequest, HttpResponse}; use sqlx::PgPool; pub fn config(cfg: &mut web::ServiceConfig) { @@ -20,15 +20,15 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[post("friend/{id}")] pub async fn add_friend( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - db: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + db: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_WRITE]), @@ -38,7 +38,7 @@ pub async fn add_friend( let string = info.into_inner().0; let friend = - crate::database::models::User::get(&string, &**pool, &redis).await?; + crate::database::models::User::get(&string, &*pool, &redis).await?; if let Some(friend) = friend { let mut transaction = pool.begin().await?; @@ -47,7 +47,7 @@ pub async fn add_friend( crate::database::models::friend_item::FriendItem::get_friend( user.id.into(), friend.id, - &**pool, + &*pool, ) .await? { @@ -76,22 +76,23 @@ pub async fn add_friend( friend_id: UserId, sockets: &ActiveSockets, ) -> Result<(), ApiError> { - if let Some(pair) = sockets.auth_sockets.get(&user_id.into()) { - let (friend_status, _) = pair.value(); - if let Some(mut socket) = - sockets.auth_sockets.get_mut(&friend_id.into()) - { - let (_, socket) = socket.value_mut(); - - let _ = socket - .text(serde_json::to_string( - &ServerToClientMessage::StatusUpdate { - status: friend_status.clone(), - }, - )?) - .await; - } - } + // TODO: FIX ME + // if let Some(pair) = sockets.auth_sockets.get(&user_id.into()) { + // let (friend_status, _) = pair.value(); + // if let Some(mut socket) = + // sockets.auth_sockets.get_mut(&friend_id.into()) + // { + // let (_, socket) = socket.value_mut(); + // + // let _ = socket + // .text(serde_json::to_string( + // &ServerToClientMessage::StatusUpdate { + // status: friend_status.clone(), + // }, + // )?) + // .await; + // } + // } Ok(()) } @@ -120,20 +121,21 @@ pub async fn add_friend( .insert(&mut transaction) .await?; - if let Some(mut socket) = db.auth_sockets.get_mut(&friend.id.into()) - { - let (_, socket) = socket.value_mut(); - - if socket - .text(serde_json::to_string( - &ServerToClientMessage::FriendRequest { from: user.id }, - )?) - .await - .is_err() - { - close_socket(user.id, &pool, &db).await?; - } - } + // TODO: FIX ME + // if let Some(mut socket) = db.auth_sockets.get_mut(&friend.id.into()) + // { + // let (_, socket) = socket.value_mut(); + // + // if socket + // .text(serde_json::to_string( + // &ServerToClientMessage::FriendRequest { from: user.id }, + // )?) + // .await + // .is_err() + // { + // close_socket(user.id, &pool, &db).await?; + // } + // } } transaction.commit().await?; @@ -147,15 +149,15 @@ pub async fn add_friend( #[delete("friend/{id}")] pub async fn remove_friend( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - db: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + db: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_WRITE]), @@ -165,7 +167,7 @@ pub async fn remove_friend( let string = info.into_inner().0; let friend = - crate::database::models::User::get(&string, &**pool, &redis).await?; + crate::database::models::User::get(&string, &*pool, &redis).await?; if let Some(friend) = friend { let mut transaction = pool.begin().await?; @@ -177,17 +179,18 @@ pub async fn remove_friend( ) .await?; - if let Some(mut socket) = db.auth_sockets.get_mut(&friend.id.into()) { - let (_, socket) = socket.value_mut(); - - let _ = socket - .text(serde_json::to_string( - &ServerToClientMessage::FriendRequestRejected { - from: user.id, - }, - )?) - .await; - } + // TODO: FIX ME + // if let Some(mut socket) = db.auth_sockets.get_mut(&friend.id.into()) { + // let (_, socket) = socket.value_mut(); + // + // let _ = socket + // .text(serde_json::to_string( + // &ServerToClientMessage::FriendRequestRejected { + // from: user.id, + // }, + // )?) + // .await; + // } transaction.commit().await?; @@ -200,13 +203,13 @@ pub async fn remove_friend( #[get("friends")] pub async fn friends( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_READ]), @@ -218,12 +221,12 @@ pub async fn friends( crate::database::models::friend_item::FriendItem::get_user_friends( user.id.into(), None, - &**pool, + &*pool, ) .await? .into_iter() .map(UserFriend::from) .collect::>(); - Ok(HttpResponse::Ok().json(friends)) + Ok(HttpResponse::Ok().json(&friends)) } diff --git a/apps/labrinth/src/routes/v3/images.rs b/apps/labrinth/src/routes/v3/images.rs index a1c2c841c..dd5443545 100644 --- a/apps/labrinth/src/routes/v3/images.rs +++ b/apps/labrinth/src/routes/v3/images.rs @@ -16,7 +16,7 @@ use crate::queue::session::AuthQueue; use crate::routes::ApiError; use crate::util::img::upload_image_optimized; use crate::util::routes::read_from_payload; -use actix_web::{web, HttpRequest, HttpResponse}; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -41,12 +41,12 @@ pub struct ImageUpload { pub async fn images_add( req: HttpRequest, - web::Query(data): web::Query, - file_host: web::Data>, - mut payload: web::Payload, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(data): web::types::Query, + file_host: web::types::State>, + mut payload: web::types::Payload, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let mut context = ImageContext::from_str(&data.context, None); @@ -54,7 +54,7 @@ pub async fn images_add( let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&scopes), @@ -68,7 +68,7 @@ pub async fn images_add( ImageContext::Project { project_id } => { if let Some(id) = data.project_id { let project = - project_item::Project::get(&id, &**pool, &redis).await?; + project_item::Project::get(&id, &*pool, &redis).await?; if let Some(project) = project { if is_team_member_project( &project.inner, @@ -93,7 +93,7 @@ pub async fn images_add( ImageContext::Version { version_id } => { if let Some(id) = data.version_id { let version = - version_item::Version::get(id.into(), &**pool, &redis) + version_item::Version::get(id.into(), &*pool, &redis) .await?; if let Some(version) = version { if is_team_member_version( @@ -120,15 +120,14 @@ pub async fn images_add( ImageContext::ThreadMessage { thread_message_id } => { if let Some(id) = data.thread_message_id { let thread_message = - thread_item::ThreadMessage::get(id.into(), &**pool) + thread_item::ThreadMessage::get(id.into(), &*pool) .await? .ok_or_else(|| { - ApiError::InvalidInput( - "The thread message could not found." - .to_string(), - ) - })?; - let thread = thread_item::Thread::get(thread_message.thread_id, &**pool) + ApiError::InvalidInput( + "The thread message could not found.".to_string(), + ) + })?; + let thread = thread_item::Thread::get(thread_message.thread_id, &*pool) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -148,14 +147,14 @@ pub async fn images_add( } ImageContext::Report { report_id } => { if let Some(id) = data.report_id { - let report = report_item::Report::get(id.into(), &**pool) + let report = report_item::Report::get(id.into(), &*pool) .await? .ok_or_else(|| { ApiError::InvalidInput( "The report could not be found.".to_string(), ) })?; - let thread = thread_item::Thread::get(report.thread_id, &**pool) + let thread = thread_item::Thread::get(report.thread_id, &*pool) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -193,7 +192,7 @@ pub async fn images_add( &data.ext, None, None, - &***file_host, + &**file_host, ) .await?; @@ -255,5 +254,5 @@ pub async fn images_add( transaction.commit().await?; - Ok(HttpResponse::Ok().json(image)) + Ok(HttpResponse::Ok().json(&image)) } diff --git a/apps/labrinth/src/routes/v3/mod.rs b/apps/labrinth/src/routes/v3/mod.rs index 3233d88ae..d3f140395 100644 --- a/apps/labrinth/src/routes/v3/mod.rs +++ b/apps/labrinth/src/routes/v3/mod.rs @@ -1,6 +1,6 @@ pub use super::ApiError; use crate::util::cors::default_cors; -use actix_web::{web, HttpResponse}; +use ntex::web::{self, HttpResponse}; use serde_json::json; pub mod analytics_get; @@ -10,7 +10,7 @@ pub mod images; pub mod notifications; pub mod organizations; pub mod payouts; -pub mod project_creation; +// pub mod project_creation; pub mod projects; pub mod reports; pub mod statistics; @@ -18,7 +18,7 @@ pub mod tags; pub mod teams; pub mod threads; pub mod users; -pub mod version_creation; +// pub mod version_creation; pub mod version_file; pub mod versions; @@ -33,7 +33,7 @@ pub fn config(cfg: &mut web::ServiceConfig) { .configure(images::config) .configure(notifications::config) .configure(organizations::config) - .configure(project_creation::config) + // .configure(project_creation::config) .configure(projects::config) .configure(reports::config) .configure(statistics::config) @@ -49,7 +49,7 @@ pub fn config(cfg: &mut web::ServiceConfig) { } pub async fn hello_world() -> Result { - Ok(HttpResponse::Ok().json(json!({ + Ok(HttpResponse::Ok().json(&json!({ "hello": "world", }))) } diff --git a/apps/labrinth/src/routes/v3/notifications.rs b/apps/labrinth/src/routes/v3/notifications.rs index abff2e587..f6fc9ca59 100644 --- a/apps/labrinth/src/routes/v3/notifications.rs +++ b/apps/labrinth/src/routes/v3/notifications.rs @@ -6,7 +6,7 @@ use crate::models::notifications::Notification; use crate::models::pats::Scopes; use crate::queue::session::AuthQueue; use crate::routes::ApiError; -use actix_web::{web, HttpRequest, HttpResponse}; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -30,14 +30,14 @@ pub struct NotificationIds { pub async fn notifications_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::NOTIFICATION_READ]), @@ -57,7 +57,7 @@ pub async fn notifications_get( let notifications_data: Vec = database::models::notification_item::Notification::get_many( ¬ification_ids, - &**pool, + &*pool, ) .await?; @@ -67,19 +67,19 @@ pub async fn notifications_get( .map(Notification::from) .collect(); - Ok(HttpResponse::Ok().json(notifications)) + Ok(HttpResponse::Ok().json(¬ifications)) } pub async fn notification_get( req: HttpRequest, - info: web::Path<(NotificationId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(NotificationId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::NOTIFICATION_READ]), @@ -92,13 +92,13 @@ pub async fn notification_get( let notification_data = database::models::notification_item::Notification::get( id.into(), - &**pool, + &*pool, ) .await?; if let Some(data) = notification_data { if user.id == data.user_id.into() || user.role.is_admin() { - Ok(HttpResponse::Ok().json(Notification::from(data))) + Ok(HttpResponse::Ok().json(&Notification::from(data))) } else { Err(ApiError::NotFound) } @@ -109,14 +109,14 @@ pub async fn notification_get( pub async fn notification_read( req: HttpRequest, - info: web::Path<(NotificationId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(NotificationId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::NOTIFICATION_WRITE]), @@ -129,7 +129,7 @@ pub async fn notification_read( let notification_data = database::models::notification_item::Notification::get( id.into(), - &**pool, + &*pool, ) .await?; @@ -159,14 +159,14 @@ pub async fn notification_read( pub async fn notification_delete( req: HttpRequest, - info: web::Path<(NotificationId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(NotificationId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::NOTIFICATION_WRITE]), @@ -179,7 +179,7 @@ pub async fn notification_delete( let notification_data = database::models::notification_item::Notification::get( id.into(), - &**pool, + &*pool, ) .await?; @@ -210,14 +210,14 @@ pub async fn notification_delete( pub async fn notifications_read( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::NOTIFICATION_WRITE]), @@ -236,7 +236,7 @@ pub async fn notifications_read( let notifications_data = database::models::notification_item::Notification::get_many( ¬ification_ids, - &**pool, + &*pool, ) .await?; @@ -263,14 +263,14 @@ pub async fn notifications_read( pub async fn notifications_delete( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::NOTIFICATION_WRITE]), @@ -289,7 +289,7 @@ pub async fn notifications_delete( let notifications_data = database::models::notification_item::Notification::get_many( ¬ification_ids, - &**pool, + &*pool, ) .await?; diff --git a/apps/labrinth/src/routes/v3/oauth_clients.rs b/apps/labrinth/src/routes/v3/oauth_clients.rs index a65dcc75d..796045aa6 100644 --- a/apps/labrinth/src/routes/v3/oauth_clients.rs +++ b/apps/labrinth/src/routes/v3/oauth_clients.rs @@ -1,12 +1,8 @@ use std::{collections::HashSet, fmt::Display, sync::Arc}; -use actix_web::{ - delete, get, patch, post, - web::{self, scope}, - HttpRequest, HttpResponse, -}; use chrono::Utc; use itertools::Itertools; +use ntex::web::{self, delete, get, patch, post, HttpRequest, HttpResponse}; use rand::{distributions::Alphanumeric, Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; use serde::{Deserialize, Serialize}; @@ -31,7 +27,6 @@ use crate::{ pats::Scopes, }, queue::session::AuthQueue, - routes::v3::project_creation::CreateError, util::validate::validation_errors_to_string, }; use crate::{ @@ -49,7 +44,7 @@ use crate::util::img::{delete_old_images, upload_image_optimized}; pub fn config(cfg: &mut web::ServiceConfig) { cfg.service( - scope("oauth") + web::scope("oauth") .configure(crate::auth::oauth::config) .service(revoke_oauth_authorization) .service(oauth_client_create) @@ -65,14 +60,14 @@ pub fn config(cfg: &mut web::ServiceConfig) { pub async fn get_user_clients( req: HttpRequest, - info: web::Path, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -80,7 +75,7 @@ pub async fn get_user_clients( .await? .1; - let target_user = User::get(&info.into_inner(), &**pool, &redis).await?; + let target_user = User::get(&info.into_inner(), &*pool, &redis).await?; if let Some(target_user) = target_user { if target_user.id != current_user.id.into() @@ -92,14 +87,14 @@ pub async fn get_user_clients( } let clients = - OAuthClient::get_all_user_clients(target_user.id, &**pool).await?; + OAuthClient::get_all_user_clients(target_user.id, &*pool).await?; let response = clients .into_iter() .map(models::oauth_clients::OAuthClient::from) .collect_vec(); - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } else { Err(ApiError::NotFound) } @@ -107,12 +102,12 @@ pub async fn get_user_clients( #[get("app/{id}")] pub async fn get_client( - id: web::Path, - pool: web::Data, + id: web::types::Path, + pool: web::types::State, ) -> Result { let clients = get_clients_inner(&[id.into_inner()], pool).await?; if let Some(client) = clients.into_iter().next() { - Ok(HttpResponse::Ok().json(client)) + Ok(HttpResponse::Ok().json(&client)) } else { Err(ApiError::NotFound) } @@ -120,8 +115,8 @@ pub async fn get_client( #[get("apps")] pub async fn get_clients( - info: web::Query, - pool: web::Data, + info: web::types::Query, + pool: web::types::State, ) -> Result { let ids: Vec<_> = info .ids @@ -131,7 +126,7 @@ pub async fn get_clients( let clients = get_clients_inner(&ids, pool).await?; - Ok(HttpResponse::Ok().json(clients)) + Ok(HttpResponse::Ok().json(&clients)) } #[derive(Deserialize, Validate)] @@ -162,14 +157,14 @@ pub struct NewOAuthApp { #[post("app")] pub async fn oauth_client_create<'a>( req: HttpRequest, - new_oauth_app: web::Json, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, -) -> Result { + new_oauth_app: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, +) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -178,7 +173,7 @@ pub async fn oauth_client_create<'a>( .1; new_oauth_app.validate().map_err(|e| { - CreateError::ValidationError(validation_errors_to_string(e, None)) + ApiError::InvalidInput(validation_errors_to_string(e, None)) })?; let mut transaction = pool.begin().await?; @@ -214,7 +209,7 @@ pub async fn oauth_client_create<'a>( let client = models::oauth_clients::OAuthClient::from(client); - Ok(HttpResponse::Ok().json(OAuthClientCreationResult { + Ok(HttpResponse::Ok().json(&OAuthClientCreationResult { client, client_secret, })) @@ -223,14 +218,14 @@ pub async fn oauth_client_create<'a>( #[delete("app/{id}")] pub async fn oauth_client_delete<'a>( req: HttpRequest, - client_id: web::Path, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + client_id: web::types::Path, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -239,10 +234,10 @@ pub async fn oauth_client_delete<'a>( .1; let client = - OAuthClient::get(client_id.into_inner().into(), &**pool).await?; + OAuthClient::get(client_id.into_inner().into(), &*pool).await?; if let Some(client) = client { client.validate_authorized(Some(¤t_user))?; - OAuthClient::remove(client.id, &**pool).await?; + OAuthClient::remove(client.id, &*pool).await?; Ok(HttpResponse::NoContent().body("")) } else { @@ -279,15 +274,15 @@ pub struct OAuthClientEdit { #[patch("app/{id}")] pub async fn oauth_client_edit( req: HttpRequest, - client_id: web::Path, - client_updates: web::Json, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + client_id: web::types::Path, + client_updates: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -300,7 +295,7 @@ pub async fn oauth_client_edit( })?; if let Some(existing_client) = - OAuthClient::get(client_id.into_inner().into(), &**pool).await? + OAuthClient::get(client_id.into_inner().into(), &*pool).await? { existing_client.validate_authorized(Some(¤t_user))?; @@ -354,18 +349,18 @@ pub struct Extension { #[patch("app/{id}/icon")] #[allow(clippy::too_many_arguments)] pub async fn oauth_client_icon_edit( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - client_id: web::Path, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - mut payload: web::Payload, - session_queue: web::Data, + client_id: web::types::Path, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + mut payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -373,7 +368,7 @@ pub async fn oauth_client_icon_edit( .await? .1; - let client = OAuthClient::get((*client_id).into(), &**pool) + let client = OAuthClient::get((*client_id).into(), &*pool) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -386,7 +381,7 @@ pub async fn oauth_client_icon_edit( delete_old_images( client.icon_url.clone(), client.raw_icon_url.clone(), - &***file_host, + &**file_host, ) .await?; @@ -402,7 +397,7 @@ pub async fn oauth_client_icon_edit( &ext.ext, Some(96), Some(1.0), - &***file_host, + &**file_host, ) .await?; @@ -424,15 +419,15 @@ pub async fn oauth_client_icon_edit( #[delete("app/{id}/icon")] pub async fn oauth_client_icon_delete( req: HttpRequest, - client_id: web::Path, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - session_queue: web::Data, + client_id: web::types::Path, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -440,7 +435,7 @@ pub async fn oauth_client_icon_delete( .await? .1; - let client = OAuthClient::get((*client_id).into(), &**pool) + let client = OAuthClient::get((*client_id).into(), &*pool) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -452,7 +447,7 @@ pub async fn oauth_client_icon_delete( delete_old_images( client.icon_url.clone(), client.raw_icon_url.clone(), - &***file_host, + &**file_host, ) .await?; @@ -473,13 +468,13 @@ pub async fn oauth_client_icon_delete( #[get("authorizations")] pub async fn get_user_oauth_authorizations( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -489,27 +484,27 @@ pub async fn get_user_oauth_authorizations( let authorizations = OAuthClientAuthorization::get_all_for_user( current_user.id.into(), - &**pool, + &*pool, ) .await?; let mapped: Vec = authorizations.into_iter().map(|a| a.into()).collect_vec(); - Ok(HttpResponse::Ok().json(mapped)) + Ok(HttpResponse::Ok().json(&mapped)) } #[delete("authorizations")] pub async fn revoke_oauth_authorization( req: HttpRequest, - info: web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::SESSION_ACCESS]), @@ -520,7 +515,7 @@ pub async fn revoke_oauth_authorization( OAuthClientAuthorization::remove( info.client_id.into(), current_user.id.into(), - &**pool, + &*pool, ) .await?; @@ -587,10 +582,10 @@ async fn edit_redirects( pub async fn get_clients_inner( ids: &[ApiOAuthClientId], - pool: web::Data, + pool: web::types::State, ) -> Result, ApiError> { let ids: Vec = ids.iter().map(|i| (*i).into()).collect(); - let clients = OAuthClient::get_many(&ids, &**pool).await?; + let clients = OAuthClient::get_many(&ids, &*pool).await?; Ok(clients.into_iter().map(|c| c.into()).collect_vec()) } diff --git a/apps/labrinth/src/routes/v3/organizations.rs b/apps/labrinth/src/routes/v3/organizations.rs index 0307341b3..c75a4c566 100644 --- a/apps/labrinth/src/routes/v3/organizations.rs +++ b/apps/labrinth/src/routes/v3/organizations.rs @@ -15,13 +15,13 @@ use crate::models::organizations::OrganizationId; use crate::models::pats::Scopes; use crate::models::teams::{OrganizationPermissions, ProjectPermissions}; use crate::queue::session::AuthQueue; -use crate::routes::v3::project_creation::CreateError; +// use crate::routes::v3::project_creation::CreateError; use crate::util::img::delete_old_images; use crate::util::routes::read_from_payload; use crate::util::validate::validation_errors_to_string; use crate::{database, models}; -use actix_web::{web, HttpRequest, HttpResponse}; use futures::TryStreamExt; +use ntex::web::{self, HttpRequest, HttpResponse}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -52,15 +52,15 @@ pub fn config(cfg: &mut web::ServiceConfig) { pub async fn organization_projects_get( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let info = info.into_inner().0; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_READ, Scopes::PROJECT_READ]), @@ -80,14 +80,14 @@ pub async fn organization_projects_get( possible_organization_id.map(|x| x as i64), info ) - .fetch(&**pool) + .fetch(&*pool) .map_ok(|m| database::models::ProjectId(m.id)) .try_collect::>() .await?; let projects_data = crate::database::models::Project::get_many_ids( &project_ids, - &**pool, + &*pool, &redis, ) .await?; @@ -95,7 +95,7 @@ pub async fn organization_projects_get( let projects = filter_visible_projects(projects_data, ¤t_user, &pool, true) .await?; - Ok(HttpResponse::Ok().json(projects)) + Ok(HttpResponse::Ok().json(&projects)) } #[derive(Deserialize, Validate)] @@ -114,14 +114,14 @@ pub struct NewOrganization { pub async fn organization_create( req: HttpRequest, - new_organization: web::Json, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, -) -> Result { + new_organization: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, +) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_CREATE]), @@ -130,7 +130,7 @@ pub async fn organization_create( .1; new_organization.validate().map_err(|err| { - CreateError::ValidationError(validation_errors_to_string(err, None)) + ApiError::InvalidInput(validation_errors_to_string(err, None)) })?; let mut transaction = pool.begin().await?; @@ -150,7 +150,7 @@ pub async fn organization_create( ) .await?; if !results.is_empty() { - return Err(CreateError::SlugCollision); + return Err(ApiError::InvalidInput("Slug collision".to_owned())); } let organization_id = generate_organization_id(&mut transaction).await?; @@ -185,7 +185,7 @@ pub async fn organization_create( transaction.commit().await?; // Only member is the owner, the logged in one - let member_data = TeamMember::get_from_team_full(team_id, &**pool, &redis) + let member_data = TeamMember::get_from_team_full(team_id, &*pool, &redis) .await? .into_iter() .next(); @@ -196,7 +196,7 @@ pub async fn organization_create( false, )] } else { - return Err(CreateError::InvalidInput( + return Err(ApiError::InvalidInput( "Failed to get created team.".to_owned(), // should never happen )); }; @@ -204,20 +204,20 @@ pub async fn organization_create( let organization = models::organizations::Organization::from(organization, members_data); - Ok(HttpResponse::Ok().json(organization)) + Ok(HttpResponse::Ok().json(&organization)) } pub async fn organization_get( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let id = info.into_inner().0; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_READ]), @@ -227,15 +227,15 @@ pub async fn organization_get( .ok(); let user_id = current_user.as_ref().map(|x| x.id.into()); - let organization_data = Organization::get(&id, &**pool, &redis).await?; + let organization_data = Organization::get(&id, &*pool, &redis).await?; if let Some(data) = organization_data { let members_data = - TeamMember::get_from_team_full(data.team_id, &**pool, &redis) + TeamMember::get_from_team_full(data.team_id, &*pool, &redis) .await?; let users = crate::database::models::User::get_many_ids( &members_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -271,7 +271,7 @@ pub async fn organization_get( let organization = models::organizations::Organization::from(data, team_members); - return Ok(HttpResponse::Ok().json(organization)); + return Ok(HttpResponse::Ok().json(&organization)); } Err(ApiError::NotFound) } @@ -283,31 +283,31 @@ pub struct OrganizationIds { pub async fn organizations_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let ids = serde_json::from_str::>(&ids.ids)?; let organizations_data = - Organization::get_many(&ids, &**pool, &redis).await?; + Organization::get_many(&ids, &*pool, &redis).await?; let team_ids = organizations_data .iter() .map(|x| x.team_id) .collect::>(); let teams_data = - TeamMember::get_from_team_full_many(&team_ids, &**pool, &redis).await?; + TeamMember::get_from_team_full_many(&team_ids, &*pool, &redis).await?; let users = crate::database::models::User::get_many_ids( &teams_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_READ]), @@ -362,7 +362,7 @@ pub async fn organizations_get( organizations.push(organization); } - Ok(HttpResponse::Ok().json(organizations)) + Ok(HttpResponse::Ok().json(&organizations)) } #[derive(Serialize, Deserialize, Validate)] @@ -380,15 +380,15 @@ pub struct OrganizationEdit { pub async fn organizations_edit( req: HttpRequest, - info: web::Path<(String,)>, - new_organization: web::Json, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + new_organization: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_WRITE]), @@ -402,14 +402,14 @@ pub async fn organizations_edit( let string = info.into_inner().0; let result = - database::models::Organization::get(&string, &**pool, &redis).await?; + database::models::Organization::get(&string, &*pool, &redis).await?; if let Some(organization_item) = result { let id = organization_item.id; let team_member = database::models::TeamMember::get_from_user_id( organization_item.team_id, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -544,14 +544,14 @@ pub async fn organizations_edit( pub async fn organization_delete( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_DELETE]), @@ -561,7 +561,7 @@ pub async fn organization_delete( let string = info.into_inner().0; let organization = - database::models::Organization::get(&string, &**pool, &redis) + database::models::Organization::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -575,7 +575,7 @@ pub async fn organization_delete( organization.id, user.id.into(), false, - &**pool, + &*pool, ) .await .map_err(ApiError::Database)? @@ -606,7 +606,7 @@ pub async fn organization_delete( ", organization.team_id as database::models::ids::TeamId ) - .fetch_one(&**pool) + .fetch_one(&*pool) .await? .user_id; let owner_id = database::models::ids::UserId(owner_id); @@ -683,16 +683,16 @@ pub struct OrganizationProjectAdd { } pub async fn organization_projects_add( req: HttpRequest, - info: web::Path<(String,)>, - project_info: web::Json, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + project_info: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let info = info.into_inner().0; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE, Scopes::ORGANIZATION_WRITE]), @@ -701,7 +701,7 @@ pub async fn organization_projects_add( .1; let organization = - database::models::Organization::get(&info, &**pool, &redis) + database::models::Organization::get(&info, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -711,7 +711,7 @@ pub async fn organization_projects_add( let project_item = database::models::Project::get( &project_info.project_id, - &**pool, + &*pool, &redis, ) .await? @@ -732,7 +732,7 @@ pub async fn organization_projects_add( project_item.inner.id, current_user.id.into(), false, - &**pool, + &*pool, ) .await? .ok_or_else(|| { @@ -745,7 +745,7 @@ pub async fn organization_projects_add( organization.id, current_user.id.into(), false, - &**pool, + &*pool, ) .await? .ok_or_else(|| { @@ -846,16 +846,16 @@ pub struct OrganizationProjectRemoval { pub async fn organization_projects_remove( req: HttpRequest, - info: web::Path<(String, String)>, - pool: web::Data, - data: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String, String)>, + pool: web::types::State, + data: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let (organization_id, project_id) = info.into_inner(); let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE, Scopes::ORGANIZATION_WRITE]), @@ -864,7 +864,7 @@ pub async fn organization_projects_remove( .1; let organization = - database::models::Organization::get(&organization_id, &**pool, &redis) + database::models::Organization::get(&organization_id, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -873,7 +873,7 @@ pub async fn organization_projects_remove( })?; let project_item = - database::models::Project::get(&project_id, &**pool, &redis) + database::models::Project::get(&project_id, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -897,7 +897,7 @@ pub async fn organization_projects_remove( organization.id, current_user.id.into(), false, - &**pool, + &*pool, ) .await? .ok_or_else(|| { @@ -917,7 +917,7 @@ pub async fn organization_projects_remove( organization.id, data.new_owner.into(), false, - &**pool, + &*pool, ) .await? .ok_or_else(|| { @@ -933,7 +933,7 @@ pub async fn organization_projects_remove( project_item.inner.id, data.new_owner.into(), true, - &**pool, + &*pool, ) .await?; @@ -1028,18 +1028,18 @@ pub struct Extension { #[allow(clippy::too_many_arguments)] pub async fn organization_icon_edit( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - mut payload: web::Payload, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + mut payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_WRITE]), @@ -1049,7 +1049,7 @@ pub async fn organization_icon_edit( let string = info.into_inner().0; let organization_item = - database::models::Organization::get(&string, &**pool, &redis) + database::models::Organization::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -1061,7 +1061,7 @@ pub async fn organization_icon_edit( let team_member = database::models::TeamMember::get_from_user_id( organization_item.team_id, user.id.into(), - &**pool, + &*pool, ) .await .map_err(ApiError::Database)?; @@ -1083,7 +1083,7 @@ pub async fn organization_icon_edit( delete_old_images( organization_item.icon_url, organization_item.raw_icon_url, - &***file_host, + &**file_host, ) .await?; @@ -1101,7 +1101,7 @@ pub async fn organization_icon_edit( &ext.ext, Some(96), Some(1.0), - &***file_host, + &**file_host, ) .await?; @@ -1134,15 +1134,15 @@ pub async fn organization_icon_edit( pub async fn delete_organization_icon( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_WRITE]), @@ -1152,7 +1152,7 @@ pub async fn delete_organization_icon( let string = info.into_inner().0; let organization_item = - database::models::Organization::get(&string, &**pool, &redis) + database::models::Organization::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -1164,7 +1164,7 @@ pub async fn delete_organization_icon( let team_member = database::models::TeamMember::get_from_user_id( organization_item.team_id, user.id.into(), - &**pool, + &*pool, ) .await .map_err(ApiError::Database)?; @@ -1186,7 +1186,7 @@ pub async fn delete_organization_icon( delete_old_images( organization_item.icon_url, organization_item.raw_icon_url, - &***file_host, + &**file_host, ) .await?; diff --git a/apps/labrinth/src/routes/v3/payouts.rs b/apps/labrinth/src/routes/v3/payouts.rs index ad5636de1..4257157f6 100644 --- a/apps/labrinth/src/routes/v3/payouts.rs +++ b/apps/labrinth/src/routes/v3/payouts.rs @@ -8,10 +8,10 @@ use crate::models::payouts::{PayoutMethodType, PayoutStatus}; use crate::queue::payouts::{make_aditude_request, PayoutsQueue}; use crate::queue::session::AuthQueue; use crate::routes::ApiError; -use actix_web::{delete, get, post, web, HttpRequest, HttpResponse}; use chrono::{Datelike, Duration, TimeZone, Utc, Weekday}; use hex::ToHex; use hmac::{Hmac, Mac, NewMac}; +use ntex::web::{self, delete, get, post, HttpRequest, HttpResponse}; use reqwest::Method; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; @@ -37,9 +37,9 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[post("_paypal")] pub async fn paypal_webhook( req: HttpRequest, - pool: web::Data, - redis: web::Data, - payouts: web::Data, + pool: web::types::State, + redis: web::types::State, + payouts: web::types::State, body: String, ) -> Result { let auth_algo = req @@ -191,8 +191,8 @@ pub async fn paypal_webhook( #[post("_tremendous")] pub async fn tremendous_webhook( req: HttpRequest, - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, body: String, ) -> Result { let signature = req @@ -298,13 +298,13 @@ pub async fn tremendous_webhook( #[get("")] pub async fn user_payouts( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAYOUTS_READ]), @@ -315,17 +315,17 @@ pub async fn user_payouts( let payout_ids = crate::database::models::payout_item::Payout::get_all_for_user( user.id.into(), - &**pool, + &*pool, ) .await?; let payouts = crate::database::models::payout_item::Payout::get_many( &payout_ids, - &**pool, + &*pool, ) .await?; Ok(HttpResponse::Ok().json( - payouts + &payouts .into_iter() .map(crate::models::payouts::Payout::from) .collect::>(), @@ -343,16 +343,16 @@ pub struct Withdrawal { #[post("")] pub async fn create_payout( req: HttpRequest, - pool: web::Data, - redis: web::Data, - body: web::Json, - session_queue: web::Data, - payouts_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + body: web::types::Json, + session_queue: web::types::State, + payouts_queue: web::types::State, ) -> Result { let (scopes, user) = get_user_record_from_bearer_token( &req, None, - &**pool, + &*pool, &redis, &session_queue, ) @@ -635,16 +635,16 @@ pub async fn create_payout( #[delete("{id}")] pub async fn cancel_payout( - info: web::Path<(PayoutId,)>, + info: web::types::Path<(PayoutId,)>, req: HttpRequest, - pool: web::Data, - redis: web::Data, - payouts: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + payouts: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAYOUTS_WRITE]), @@ -654,7 +654,7 @@ pub async fn cancel_payout( let id = info.into_inner().0; let payout = - crate::database::models::payout_item::Payout::get(id.into(), &**pool) + crate::database::models::payout_item::Payout::get(id.into(), &*pool) .await?; if let Some(payout) = payout { @@ -738,8 +738,8 @@ pub struct MethodFilter { #[get("methods")] pub async fn payment_methods( - payouts_queue: web::Data, - filter: web::Query, + payouts_queue: web::types::State, + filter: web::types::Query, ) -> Result { let methods = payouts_queue .get_payout_methods() @@ -756,7 +756,7 @@ pub async fn payment_methods( }) .collect::>(); - Ok(HttpResponse::Ok().json(methods)) + Ok(HttpResponse::Ok().json(&methods)) } #[derive(Serialize)] @@ -768,13 +768,13 @@ pub struct UserBalance { #[get("balance")] pub async fn get_balance( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PAYOUTS_READ]), @@ -784,7 +784,7 @@ pub async fn get_balance( let balance = get_user_balance(user.id.into(), &pool).await?; - Ok(HttpResponse::Ok().json(balance)) + Ok(HttpResponse::Ok().json(&balance)) } async fn get_user_balance( @@ -862,8 +862,8 @@ pub struct RevenueData { #[get("platform_revenue")] pub async fn platform_revenue( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { let mut redis = redis.connect().await?; @@ -874,7 +874,7 @@ pub async fn platform_revenue( .await?; if let Some(res) = res { - return Ok(HttpResponse::Ok().json(res)); + return Ok(HttpResponse::Ok().json(&res)); } let all_time_payouts = sqlx::query!( @@ -882,7 +882,7 @@ pub async fn platform_revenue( SELECT SUM(amount) from payouts_values ", ) - .fetch_optional(&**pool) + .fetch_optional(&*pool) .await? .and_then(|x| x.sum) .unwrap_or(Decimal::ZERO); @@ -968,7 +968,7 @@ pub async fn platform_revenue( ) .await?; - Ok(HttpResponse::Ok().json(res)) + Ok(HttpResponse::Ok().json(&res)) } fn get_legacy_data_point(timestamp: u64) -> RevenueData { diff --git a/apps/labrinth/src/routes/v3/project_creation.rs b/apps/labrinth/src/routes/v3/project_creation.rs index 31d751205..e663b4045 100644 --- a/apps/labrinth/src/routes/v3/project_creation.rs +++ b/apps/labrinth/src/routes/v3/project_creation.rs @@ -24,14 +24,13 @@ use crate::search::indexing::IndexingError; use crate::util::img::upload_image_optimized; use crate::util::routes::read_from_field; use crate::util::validate::validation_errors_to_string; -use actix_multipart::{Field, Multipart}; -use actix_web::http::StatusCode; -use actix_web::web::{self, Data}; -use actix_web::{HttpRequest, HttpResponse}; use chrono::Utc; use futures::stream::StreamExt; use image::ImageError; use itertools::Itertools; +use ntex::http::StatusCode; +use ntex::web::{self, HttpRequest, HttpResponse}; +use ntex_multipart::{Field, Multipart}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use sqlx::postgres::PgPool; @@ -40,7 +39,7 @@ use std::sync::Arc; use thiserror::Error; use validator::Validate; -pub fn config(cfg: &mut actix_web::web::ServiceConfig) { +pub fn config(cfg: &mut ntex::web::ServiceConfig) { cfg.route("project", web::post().to(project_create)); } @@ -55,7 +54,7 @@ pub enum CreateError { #[error("Indexing Error: {0}")] IndexingError(#[from] IndexingError), #[error("Error while parsing multipart payload: {0}")] - MultipartError(#[from] actix_multipart::MultipartError), + MultipartError(#[from] ntex_multipart::MultipartError), #[error("Error while parsing JSON: {0}")] SerDeError(#[from] serde_json::Error), #[error("Error while validating input: {0}")] @@ -90,7 +89,7 @@ pub enum CreateError { RerouteError(#[from] reqwest::Error), } -impl actix_web::ResponseError for CreateError { +impl ntex::web::WebResponseError for CreateError { fn status_code(&self) -> StatusCode { match self { CreateError::EnvError(..) => StatusCode::INTERNAL_SERVER_ERROR, @@ -123,8 +122,8 @@ impl actix_web::ResponseError for CreateError { } } - fn error_response(&self) -> HttpResponse { - HttpResponse::build(self.status_code()).json(ApiError { + fn error_response(&self, _req: &HttpRequest) -> HttpResponse { + HttpResponse::build(self.status_code()).json(&ApiError { error: match self { CreateError::EnvError(..) => "environment_error", CreateError::SqlxDatabaseError(..) => "database_error", @@ -265,10 +264,10 @@ pub async fn undo_uploads( pub async fn project_create( req: HttpRequest, mut payload: Multipart, - client: Data, - redis: Data, - file_host: Data>, - session_queue: Data, + client: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { let mut transaction = client.begin().await?; let mut uploaded_files = Vec::new(); @@ -277,7 +276,7 @@ pub async fn project_create( req, &mut payload, &mut transaction, - &***file_host, + &**file_host, &mut uploaded_files, &client, &redis, @@ -286,7 +285,7 @@ pub async fn project_create( .await; if result.is_err() { - let undo_result = undo_uploads(&***file_host, &uploaded_files).await; + let undo_result = undo_uploads(&**file_host, &uploaded_files).await; let rollback_result = transaction.rollback().await; undo_result?; @@ -377,10 +376,12 @@ async fn project_create_inner( ))) })?; - let content_disposition = field.content_disposition(); - let name = content_disposition.get_name().ok_or_else(|| { - CreateError::MissingValueError(String::from("Missing content name")) - })?; + // TODO: fix me + // let content_disposition = field.content_disposition(); + // let name = content_disposition.get_name().ok_or_else(|| { + // CreateError::MissingValueError(String::from("Missing content name")) + // })?; + let name = "TODO FIX ME"; if name != "data" { return Err(CreateError::InvalidInput(String::from( @@ -476,14 +477,17 @@ async fn project_create_inner( } let result = async { - let content_disposition = field.content_disposition().clone(); - - let name = content_disposition.get_name().ok_or_else(|| { - CreateError::MissingValueError("Missing content name".to_string()) - })?; - - let (file_name, file_extension) = - super::version_creation::get_name_ext(&content_disposition)?; + // let content_disposition = field.content_disposition().clone(); + // + // let name = content_disposition.get_name().ok_or_else(|| { + // CreateError::MissingValueError("Missing content name".to_string()) + // })?; + // TODO: fix me + let name = "TODO FIX ME".to_string(); + + let (file_name, file_extension) = ("TODO FIX ME", "TODO FIX ME"); + // let (file_name, file_extension) = + // super::version_creation::get_name_ext(&content_disposition)?; if name == "icon" { if icon_data.is_some() { @@ -915,7 +919,7 @@ async fn project_create_inner( fields: HashMap::new(), // Fields instantiate to empty }; - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } } diff --git a/apps/labrinth/src/routes/v3/projects.rs b/apps/labrinth/src/routes/v3/projects.rs index 0a47aea2c..f5139838f 100644 --- a/apps/labrinth/src/routes/v3/projects.rs +++ b/apps/labrinth/src/routes/v3/projects.rs @@ -29,10 +29,10 @@ use crate::util::img; use crate::util::img::{delete_old_images, upload_image_optimized}; use crate::util::routes::read_from_payload; use crate::util::validate::validation_errors_to_string; -use actix_web::{web, HttpRequest, HttpResponse}; use chrono::Utc; use futures::TryStreamExt; use itertools::Itertools; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use serde_json::json; use sqlx::PgPool; @@ -84,9 +84,9 @@ pub struct RandomProjects { } pub async fn random_projects_get( - web::Query(count): web::Query, - pool: web::Data, - redis: web::Data, + web::types::Query(count): web::types::Query, + pool: web::types::State, + redis: web::types::State, ) -> Result { count.validate().map_err(|err| { ApiError::Validation(validation_errors_to_string(err, None)) @@ -102,19 +102,19 @@ pub async fn random_projects_get( .map(|x| x.to_string()) .collect::>(), ) - .fetch(&**pool) + .fetch(&*pool) .map_ok(|m| db_ids::ProjectId(m.id)) .try_collect::>() .await?; let projects_data = - db_models::Project::get_many_ids(&project_ids, &**pool, &redis) + db_models::Project::get_many_ids(&project_ids, &*pool, &redis) .await? .into_iter() .map(Project::from) .collect::>(); - Ok(HttpResponse::Ok().json(projects_data)) + Ok(HttpResponse::Ok().json(&projects_data)) } #[derive(Serialize, Deserialize)] @@ -124,18 +124,18 @@ pub struct ProjectIds { pub async fn projects_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let ids = serde_json::from_str::>(&ids.ids)?; let projects_data = - db_models::Project::get_many(&ids, &**pool, &redis).await?; + db_models::Project::get_many(&ids, &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -148,23 +148,22 @@ pub async fn projects_get( filter_visible_projects(projects_data, &user_option, &pool, false) .await?; - Ok(HttpResponse::Ok().json(projects)) + Ok(HttpResponse::Ok().json(&projects)) } pub async fn project_get( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let string = info.into_inner().0; - let project_data = - db_models::Project::get(&string, &**pool, &redis).await?; + let project_data = db_models::Project::get(&string, &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -175,7 +174,7 @@ pub async fn project_get( if let Some(data) = project_data { if is_visible_project(&data.inner, &user_option, &pool, false).await? { - return Ok(HttpResponse::Ok().json(Project::from(data))); + return Ok(HttpResponse::Ok().json(&Project::from(data))); } } Err(ApiError::NotFound) @@ -244,17 +243,17 @@ pub struct EditProject { #[allow(clippy::too_many_arguments)] pub async fn project_edit( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - search_config: web::Data, - new_project: web::Json, - redis: web::Data, - session_queue: web::Data, - moderation_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + search_config: web::types::State, + new_project: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, + moderation_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -267,7 +266,7 @@ pub async fn project_edit( })?; let string = info.into_inner().0; - let result = db_models::Project::get(&string, &**pool, &redis).await?; + let result = db_models::Project::get(&string, &*pool, &redis).await?; if let Some(project_item) = result { let id = project_item.inner.id; @@ -275,7 +274,7 @@ pub async fn project_edit( db_models::TeamMember::get_for_project_permissions( &project_item.inner, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -949,8 +948,8 @@ pub async fn edit_project_categories( // } pub async fn project_search( - web::Query(info): web::Query, - config: web::Data, + web::types::Query(info): web::types::Query, + config: web::types::State, ) -> Result { let results = search_for_project(&info, &config).await?; @@ -966,21 +965,21 @@ pub async fn project_search( // total_hits: results.total_hits, // }; - Ok(HttpResponse::Ok().json(results)) + Ok(HttpResponse::Ok().json(&results)) } //checks the validity of a project id or slug pub async fn project_get_check( - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, ) -> Result { let slug = info.into_inner().0; - let project_data = db_models::Project::get(&slug, &**pool, &redis).await?; + let project_data = db_models::Project::get(&slug, &*pool, &redis).await?; if let Some(project) = project_data { - Ok(HttpResponse::Ok().json(json! ({ + Ok(HttpResponse::Ok().json(&json! ({ "id": models::ids::ProjectId::from(project.inner.id) }))) } else { @@ -996,18 +995,18 @@ pub struct DependencyInfo { pub async fn dependency_list( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let string = info.into_inner().0; - let result = db_models::Project::get(&string, &**pool, &redis).await?; + let result = db_models::Project::get(&string, &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -1025,7 +1024,7 @@ pub async fn dependency_list( let dependencies = database::Project::get_dependencies( project.inner.id, - &**pool, + &*pool, &redis, ) .await?; @@ -1051,8 +1050,8 @@ pub async fn dependency_list( .unique() .collect::>(); let (projects_result, versions_result) = futures::future::try_join( - database::Project::get_many_ids(&project_ids, &**pool, &redis), - database::Version::get_many(&dep_version_ids, &**pool, &redis), + database::Project::get_many_ids(&project_ids, &*pool, &redis), + database::Version::get_many(&dep_version_ids, &*pool, &redis), ) .await?; @@ -1077,7 +1076,7 @@ pub async fn dependency_list( versions.sort_by(|a, b| b.date_published.cmp(&a.date_published)); versions.dedup_by(|a, b| a.id == b.id); - Ok(HttpResponse::Ok().json(DependencyInfo { projects, versions })) + Ok(HttpResponse::Ok().json(&DependencyInfo { projects, versions })) } else { Err(ApiError::NotFound) } @@ -1112,15 +1111,15 @@ pub struct BulkEditProject { pub async fn projects_edit( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - bulk_edit_project: web::Json, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + bulk_edit_project: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -1139,7 +1138,7 @@ pub async fn projects_edit( .collect(); let projects_data = - db_models::Project::get_many_ids(&project_ids, &**pool, &redis).await?; + db_models::Project::get_many_ids(&project_ids, &*pool, &redis).await?; if let Some(id) = project_ids .iter() @@ -1156,7 +1155,7 @@ pub async fn projects_edit( .map(|x| x.inner.team_id) .collect::>(); let team_members = db_models::TeamMember::get_from_team_full_many( - &team_ids, &**pool, &redis, + &team_ids, &*pool, &redis, ) .await?; @@ -1166,7 +1165,7 @@ pub async fn projects_edit( .collect::>(); let organizations = db_models::Organization::get_many_ids( &organization_ids, - &**pool, + &*pool, &redis, ) .await?; @@ -1178,15 +1177,15 @@ pub async fn projects_edit( let organization_team_members = db_models::TeamMember::get_from_team_full_many( &organization_team_ids, - &**pool, + &*pool, &redis, ) .await?; let categories = - db_models::categories::Category::list(&**pool, &redis).await?; + db_models::categories::Category::list(&*pool, &redis).await?; let link_platforms = - db_models::categories::LinkPlatform::list(&**pool, &redis).await?; + db_models::categories::LinkPlatform::list(&*pool, &redis).await?; let mut transaction = pool.begin().await?; @@ -1407,18 +1406,18 @@ pub struct Extension { #[allow(clippy::too_many_arguments)] pub async fn project_icon_edit( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - mut payload: web::Payload, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + mut payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -1427,7 +1426,7 @@ pub async fn project_icon_edit( .1; let string = info.into_inner().0; - let project_item = db_models::Project::get(&string, &**pool, &redis) + let project_item = db_models::Project::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -1440,7 +1439,7 @@ pub async fn project_icon_edit( db_models::TeamMember::get_for_project_permissions( &project_item.inner, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -1469,7 +1468,7 @@ pub async fn project_icon_edit( delete_old_images( project_item.inner.icon_url, project_item.inner.raw_icon_url, - &***file_host, + &**file_host, ) .await?; @@ -1487,7 +1486,7 @@ pub async fn project_icon_edit( &ext.ext, Some(96), Some(1.0), - &***file_host, + &**file_host, ) .await?; @@ -1521,15 +1520,15 @@ pub async fn project_icon_edit( pub async fn delete_project_icon( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -1538,7 +1537,7 @@ pub async fn delete_project_icon( .1; let string = info.into_inner().0; - let project_item = db_models::Project::get(&string, &**pool, &redis) + let project_item = db_models::Project::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -1551,7 +1550,7 @@ pub async fn delete_project_icon( db_models::TeamMember::get_for_project_permissions( &project_item.inner, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -1579,7 +1578,7 @@ pub async fn delete_project_icon( delete_old_images( project_item.inner.icon_url, project_item.inner.raw_icon_url, - &***file_host, + &**file_host, ) .await?; @@ -1620,15 +1619,15 @@ pub struct GalleryCreateQuery { #[allow(clippy::too_many_arguments)] pub async fn add_gallery_item( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - web::Query(item): web::Query, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - mut payload: web::Payload, - session_queue: web::Data, + web::types::Query(item): web::types::Query, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + mut payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { item.validate().map_err(|err| { ApiError::Validation(validation_errors_to_string(err, None)) @@ -1636,7 +1635,7 @@ pub async fn add_gallery_item( let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -1645,7 +1644,7 @@ pub async fn add_gallery_item( .1; let string = info.into_inner().0; - let project_item = db_models::Project::get(&string, &**pool, &redis) + let project_item = db_models::Project::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -1665,7 +1664,7 @@ pub async fn add_gallery_item( db_models::TeamMember::get_for_project_permissions( &project_item.inner, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -1705,7 +1704,7 @@ pub async fn add_gallery_item( &ext.ext, Some(350), Some(1.0), - &***file_host, + &**file_host, ) .await?; @@ -1787,14 +1786,14 @@ pub struct GalleryEditQuery { pub async fn edit_gallery_item( req: HttpRequest, - web::Query(item): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(item): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -1813,7 +1812,7 @@ pub async fn edit_gallery_item( ", item.url ) - .fetch_optional(&**pool) + .fetch_optional(&*pool) .await? .ok_or_else(|| { ApiError::InvalidInput(format!( @@ -1824,7 +1823,7 @@ pub async fn edit_gallery_item( let project_item = db_models::Project::get_id( database::models::ProjectId(result.mod_id), - &**pool, + &*pool, &redis, ) .await? @@ -1839,7 +1838,7 @@ pub async fn edit_gallery_item( db_models::TeamMember::get_for_project_permissions( &project_item.inner, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -1953,15 +1952,15 @@ pub struct GalleryDeleteQuery { pub async fn delete_gallery_item( req: HttpRequest, - web::Query(item): web::Query, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - session_queue: web::Data, + web::types::Query(item): web::types::Query, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -1976,7 +1975,7 @@ pub async fn delete_gallery_item( ", item.url ) - .fetch_optional(&**pool) + .fetch_optional(&*pool) .await? .ok_or_else(|| { ApiError::InvalidInput(format!( @@ -1987,7 +1986,7 @@ pub async fn delete_gallery_item( let project_item = db_models::Project::get_id( database::models::ProjectId(item.mod_id), - &**pool, + &*pool, &redis, ) .await? @@ -2002,7 +2001,7 @@ pub async fn delete_gallery_item( db_models::TeamMember::get_for_project_permissions( &project_item.inner, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -2031,7 +2030,7 @@ pub async fn delete_gallery_item( delete_old_images( Some(item.image_url), Some(item.raw_image_url), - &***file_host, + &**file_host, ) .await?; @@ -2062,15 +2061,15 @@ pub async fn delete_gallery_item( pub async fn project_delete( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - search_config: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + search_config: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_DELETE]), @@ -2079,7 +2078,7 @@ pub async fn project_delete( .1; let string = info.into_inner().0; - let project = db_models::Project::get(&string, &**pool, &redis) + let project = db_models::Project::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -2092,7 +2091,7 @@ pub async fn project_delete( db_models::TeamMember::get_for_project_permissions( &project.inner, user.id.into(), - &**pool, + &*pool, ) .await?; @@ -2162,14 +2161,14 @@ pub async fn project_delete( pub async fn project_follow( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_WRITE]), @@ -2178,7 +2177,7 @@ pub async fn project_follow( .1; let string = info.into_inner().0; - let result = db_models::Project::get(&string, &**pool, &redis) + let result = db_models::Project::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -2200,7 +2199,7 @@ pub async fn project_follow( user_id as db_ids::UserId, project_id as db_ids::ProjectId ) - .fetch_one(&**pool) + .fetch_one(&*pool) .await? .exists .unwrap_or(false); @@ -2242,14 +2241,14 @@ pub async fn project_follow( pub async fn project_unfollow( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_WRITE]), @@ -2258,7 +2257,7 @@ pub async fn project_unfollow( .1; let string = info.into_inner().0; - let result = db_models::Project::get(&string, &**pool, &redis) + let result = db_models::Project::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -2276,7 +2275,7 @@ pub async fn project_unfollow( user_id as db_ids::UserId, project_id as db_ids::ProjectId ) - .fetch_one(&**pool) + .fetch_one(&*pool) .await? .exists .unwrap_or(false); @@ -2318,14 +2317,14 @@ pub async fn project_unfollow( pub async fn project_get_organization( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ, Scopes::ORGANIZATION_READ]), @@ -2336,7 +2335,7 @@ pub async fn project_get_organization( let user_id = current_user.as_ref().map(|x| x.id.into()); let string = info.into_inner().0; - let result = db_models::Project::get(&string, &**pool, &redis) + let result = db_models::Project::get(&string, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -2350,7 +2349,7 @@ pub async fn project_get_organization( )) } else if let Some(organization_id) = result.inner.organization_id { let organization = - db_models::Organization::get_id(organization_id, &**pool, &redis) + db_models::Organization::get_id(organization_id, &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -2360,14 +2359,14 @@ pub async fn project_get_organization( let members_data = TeamMember::get_from_team_full( organization.team_id, - &**pool, + &*pool, &redis, ) .await?; let users = crate::database::models::User::get_many_ids( &members_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -2405,7 +2404,7 @@ pub async fn project_get_organization( organization, team_members, ); - return Ok(HttpResponse::Ok().json(organization)); + return Ok(HttpResponse::Ok().json(&organization)); } else { Err(ApiError::NotFound) } diff --git a/apps/labrinth/src/routes/v3/reports.rs b/apps/labrinth/src/routes/v3/reports.rs index 1af674627..2bfc5081e 100644 --- a/apps/labrinth/src/routes/v3/reports.rs +++ b/apps/labrinth/src/routes/v3/reports.rs @@ -16,9 +16,10 @@ use crate::models::threads::{MessageBody, ThreadType}; use crate::queue::session::AuthQueue; use crate::routes::ApiError; use crate::util::img; -use actix_web::{web, HttpRequest, HttpResponse}; +use bytes::BytesMut; use chrono::Utc; use futures::StreamExt; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; use validator::Validate; @@ -46,16 +47,16 @@ pub struct CreateReport { pub async fn report_create( req: HttpRequest, - pool: web::Data, - mut body: web::Payload, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + mut body: web::types::Payload, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let mut transaction = pool.begin().await?; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::REPORT_CREATE]), @@ -63,7 +64,7 @@ pub async fn report_create( .await? .1; - let mut bytes = web::BytesMut::new(); + let mut bytes = BytesMut::new(); while let Some(item) = body.next().await { bytes.extend_from_slice(&item.map_err(|_| { ApiError::InvalidInput( @@ -216,7 +217,7 @@ pub async fn report_create( transaction.commit().await?; - Ok(HttpResponse::Ok().json(Report { + Ok(HttpResponse::Ok().json(&Report { id: id.into(), report_type: new_report.report_type.clone(), item_id: new_report.item_id.clone(), @@ -246,14 +247,14 @@ fn default_all() -> bool { pub async fn reports( req: HttpRequest, - pool: web::Data, - redis: web::Data, - count: web::Query, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + count: web::types::Query, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::REPORT_READ]), @@ -273,7 +274,7 @@ pub async fn reports( ", count.count as i64 ) - .fetch(&**pool) + .fetch(&*pool) .map_ok(|m| crate::database::models::ids::ReportId(m.id)) .try_collect::>() .await? @@ -288,7 +289,7 @@ pub async fn reports( user.id.0 as i64, count.count as i64 ) - .fetch(&**pool) + .fetch(&*pool) .map_ok(|m| crate::database::models::ids::ReportId(m.id)) .try_collect::>() .await? @@ -296,7 +297,7 @@ pub async fn reports( let query_reports = crate::database::models::report_item::Report::get_many( &report_ids, - &**pool, + &*pool, ) .await?; @@ -306,7 +307,7 @@ pub async fn reports( reports.push(x.into()); } - Ok(HttpResponse::Ok().json(reports)) + Ok(HttpResponse::Ok().json(&reports)) } #[derive(Deserialize)] @@ -316,10 +317,10 @@ pub struct ReportIds { pub async fn reports_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let report_ids: Vec = serde_json::from_str::>(&ids.ids)? @@ -329,13 +330,13 @@ pub async fn reports_get( let reports_data = crate::database::models::report_item::Report::get_many( &report_ids, - &**pool, + &*pool, ) .await?; let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::REPORT_READ]), @@ -349,19 +350,19 @@ pub async fn reports_get( .map(|x| x.into()) .collect::>(); - Ok(HttpResponse::Ok().json(all_reports)) + Ok(HttpResponse::Ok().json(&all_reports)) } pub async fn report_get( req: HttpRequest, - pool: web::Data, - redis: web::Data, - info: web::Path<(crate::models::reports::ReportId,)>, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + info: web::types::Path<(crate::models::reports::ReportId,)>, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::REPORT_READ]), @@ -371,7 +372,7 @@ pub async fn report_get( let id = info.into_inner().0.into(); let report = - crate::database::models::report_item::Report::get(id, &**pool).await?; + crate::database::models::report_item::Report::get(id, &*pool).await?; if let Some(report) = report { if !user.role.is_mod() && report.reporter != user.id.into() { @@ -379,7 +380,7 @@ pub async fn report_get( } let report: Report = report.into(); - Ok(HttpResponse::Ok().json(report)) + Ok(HttpResponse::Ok().json(&report)) } else { Err(ApiError::NotFound) } @@ -394,15 +395,15 @@ pub struct EditReport { pub async fn report_edit( req: HttpRequest, - pool: web::Data, - redis: web::Data, - info: web::Path<(crate::models::reports::ReportId,)>, - session_queue: web::Data, - edit_report: web::Json, + pool: web::types::State, + redis: web::types::State, + info: web::types::Path<(crate::models::reports::ReportId,)>, + session_queue: web::types::State, + edit_report: web::types::Json, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::REPORT_WRITE]), @@ -412,7 +413,7 @@ pub async fn report_edit( let id = info.into_inner().0.into(); let report = - crate::database::models::report_item::Report::get(id, &**pool).await?; + crate::database::models::report_item::Report::get(id, &*pool).await?; if let Some(report) = report { if !user.role.is_mod() && report.reporter != user.id.into() { @@ -494,14 +495,14 @@ pub async fn report_edit( pub async fn report_delete( req: HttpRequest, - pool: web::Data, - info: web::Path<(crate::models::reports::ReportId,)>, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + info: web::types::Path<(crate::models::reports::ReportId,)>, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { check_is_moderator_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::REPORT_DELETE]), diff --git a/apps/labrinth/src/routes/v3/statistics.rs b/apps/labrinth/src/routes/v3/statistics.rs index 511448043..7055435e3 100644 --- a/apps/labrinth/src/routes/v3/statistics.rs +++ b/apps/labrinth/src/routes/v3/statistics.rs @@ -1,5 +1,5 @@ use crate::routes::ApiError; -use actix_web::{web, HttpResponse}; +use ntex::web::{self, HttpResponse}; use sqlx::PgPool; pub fn config(cfg: &mut web::ServiceConfig) { @@ -15,7 +15,7 @@ pub struct V3Stats { } pub async fn get_stats( - pool: web::Data, + pool: web::types::State, ) -> Result { let projects = sqlx::query!( " @@ -28,7 +28,7 @@ pub async fn get_stats( .map(|x| x.to_string()) .collect::>(), ) - .fetch_one(&**pool) + .fetch_one(&*pool) .await?; let versions = sqlx::query!( @@ -47,7 +47,7 @@ pub async fn get_stats( .map(|x| x.to_string()) .collect::>(), ) - .fetch_one(&**pool) + .fetch_one(&*pool) .await?; let authors = sqlx::query!( @@ -62,7 +62,7 @@ pub async fn get_stats( .map(|x| x.to_string()) .collect::>(), ) - .fetch_one(&**pool) + .fetch_one(&*pool) .await?; let files = sqlx::query!( @@ -80,7 +80,7 @@ pub async fn get_stats( .map(|x| x.to_string()) .collect::>(), ) - .fetch_one(&**pool) + .fetch_one(&*pool) .await?; let v3_stats = V3Stats { @@ -90,5 +90,5 @@ pub async fn get_stats( files: files.count, }; - Ok(HttpResponse::Ok().json(v3_stats)) + Ok(HttpResponse::Ok().json(&v3_stats)) } diff --git a/apps/labrinth/src/routes/v3/tags.rs b/apps/labrinth/src/routes/v3/tags.rs index d7d5b2516..b05e5f411 100644 --- a/apps/labrinth/src/routes/v3/tags.rs +++ b/apps/labrinth/src/routes/v3/tags.rs @@ -8,7 +8,7 @@ use crate::database::models::loader_fields::{ Game, Loader, LoaderField, LoaderFieldEnumValue, LoaderFieldType, }; use crate::database::redis::RedisPool; -use actix_web::{web, HttpResponse}; +use ntex::web::{self, HttpResponse}; use itertools::Itertools; use serde_json::Value; @@ -38,10 +38,10 @@ pub struct GameData { } pub async fn games_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { - let results = Game::list(&**pool, &redis) + let results = Game::list(&*pool, &redis) .await? .into_iter() .map(|x| GameData { @@ -52,7 +52,7 @@ pub async fn games_list( }) .collect::>(); - Ok(HttpResponse::Ok().json(results)) + Ok(HttpResponse::Ok().json(&results)) } #[derive(serde::Serialize, serde::Deserialize)] @@ -64,10 +64,10 @@ pub struct CategoryData { } pub async fn category_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { - let results = Category::list(&**pool, &redis) + let results = Category::list(&*pool, &redis) .await? .into_iter() .map(|x| CategoryData { @@ -78,7 +78,7 @@ pub async fn category_list( }) .collect::>(); - Ok(HttpResponse::Ok().json(results)) + Ok(HttpResponse::Ok().json(&results)) } #[derive(serde::Serialize, serde::Deserialize)] @@ -92,14 +92,14 @@ pub struct LoaderData { } pub async fn loader_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { - let loaders = Loader::list(&**pool, &redis).await?; + let loaders = Loader::list(&*pool, &redis).await?; let loader_fields = LoaderField::get_fields_per_loader( &loaders.iter().map(|x| x.id).collect_vec(), - &**pool, + &*pool, &redis, ) .await?; @@ -121,7 +121,7 @@ pub async fn loader_list( results.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())); - Ok(HttpResponse::Ok().json(results)) + Ok(HttpResponse::Ok().json(&results)) } #[derive(serde::Deserialize, serde::Serialize)] @@ -132,12 +132,12 @@ pub struct LoaderFieldsEnumQuery { // Provides the variants for any enumerable loader field. pub async fn loader_fields_list( - pool: web::Data, - query: web::Query, - redis: web::Data, + pool: web::types::State, + query: web::types::Query, + redis: web::types::State, ) -> Result { let query = query.into_inner(); - let loader_field = LoaderField::get_fields_all(&**pool, &redis) + let loader_field = LoaderField::get_fields_all(&*pool, &redis) .await? .into_iter() .find(|x| x.field == query.loader_field) @@ -164,16 +164,15 @@ pub async fn loader_fields_list( LoaderFieldEnumValue::list_filter( loader_field_enum_id, filters, - &**pool, + &*pool, &redis, ) .await? } else { - LoaderFieldEnumValue::list(loader_field_enum_id, &**pool, &redis) - .await? + LoaderFieldEnumValue::list(loader_field_enum_id, &*pool, &redis).await? }; - Ok(HttpResponse::Ok().json(results)) + Ok(HttpResponse::Ok().json(&results)) } #[derive(serde::Serialize, serde::Deserialize)] @@ -193,7 +192,7 @@ pub async fn license_list() -> HttpResponse { }); } - HttpResponse::Ok().json(results) + HttpResponse::Ok().json(&results) } #[derive(serde::Serialize, serde::Deserialize)] @@ -203,19 +202,19 @@ pub struct LicenseText { } pub async fn license_text( - params: web::Path<(String,)>, + params: web::types::Path<(String,)>, ) -> Result { let license_id = params.into_inner().0; if license_id == *crate::models::projects::DEFAULT_LICENSE_ID { - return Ok(HttpResponse::Ok().json(LicenseText { + return Ok(HttpResponse::Ok().json(&LicenseText { title: "All Rights Reserved".to_string(), body: "All rights reserved unless explicitly stated.".to_string(), })); } if let Some(license) = spdx::license_id(&license_id) { - return Ok(HttpResponse::Ok().json(LicenseText { + return Ok(HttpResponse::Ok().json(&LicenseText { title: license.full_name.to_string(), body: license.text().to_string(), })); @@ -233,11 +232,11 @@ pub struct LinkPlatformQueryData { } pub async fn link_platform_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { let results: Vec = - LinkPlatform::list(&**pool, &redis) + LinkPlatform::list(&*pool, &redis) .await? .into_iter() .map(|x| LinkPlatformQueryData { @@ -245,21 +244,21 @@ pub async fn link_platform_list( donation: x.donation, }) .collect(); - Ok(HttpResponse::Ok().json(results)) + Ok(HttpResponse::Ok().json(&results)) } pub async fn report_type_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { - let results = ReportType::list(&**pool, &redis).await?; - Ok(HttpResponse::Ok().json(results)) + let results = ReportType::list(&*pool, &redis).await?; + Ok(HttpResponse::Ok().json(&results)) } pub async fn project_type_list( - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, ) -> Result { - let results = ProjectType::list(&**pool, &redis).await?; - Ok(HttpResponse::Ok().json(results)) + let results = ProjectType::list(&*pool, &redis).await?; + Ok(HttpResponse::Ok().json(&results)) } diff --git a/apps/labrinth/src/routes/v3/teams.rs b/apps/labrinth/src/routes/v3/teams.rs index 4917d0547..4ba34fb22 100644 --- a/apps/labrinth/src/routes/v3/teams.rs +++ b/apps/labrinth/src/routes/v3/teams.rs @@ -13,7 +13,7 @@ use crate::models::teams::{ use crate::models::users::UserId; use crate::queue::session::AuthQueue; use crate::routes::ApiError; -use actix_web::{web, HttpRequest, HttpResponse}; +use ntex::web::{self, HttpRequest, HttpResponse}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -42,19 +42,19 @@ pub fn config(cfg: &mut web::ServiceConfig) { // They can be differentiated by the "organization_permissions" field being null or not pub async fn team_members_get_project( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let string = info.into_inner().0; let project_data = - crate::database::models::Project::get(&string, &**pool, &redis).await?; + crate::database::models::Project::get(&string, &*pool, &redis).await?; if let Some(project) = project_data { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -70,13 +70,13 @@ pub async fn team_members_get_project( } let members_data = TeamMember::get_from_team_full( project.inner.team_id, - &**pool, + &*pool, &redis, ) .await?; let users = User::get_many_ids( &members_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -87,7 +87,7 @@ pub async fn team_members_get_project( TeamMember::get_for_project_permissions( &project.inner, user_id, - &**pool, + &*pool, ) .await?; @@ -118,7 +118,7 @@ pub async fn team_members_get_project( }) .collect(); - Ok(HttpResponse::Ok().json(team_members)) + Ok(HttpResponse::Ok().json(&team_members)) } else { Err(ApiError::NotFound) } @@ -126,20 +126,20 @@ pub async fn team_members_get_project( pub async fn team_members_get_organization( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let string = info.into_inner().0; let organization_data = - crate::database::models::Organization::get(&string, &**pool, &redis) + crate::database::models::Organization::get(&string, &*pool, &redis) .await?; if let Some(organization) = organization_data { let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::ORGANIZATION_READ]), @@ -150,13 +150,13 @@ pub async fn team_members_get_organization( let members_data = TeamMember::get_from_team_full( organization.team_id, - &**pool, + &*pool, &redis, ) .await?; let users = crate::database::models::User::get_many_ids( &members_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -193,7 +193,7 @@ pub async fn team_members_get_organization( }) .collect(); - Ok(HttpResponse::Ok().json(team_members)) + Ok(HttpResponse::Ok().json(&team_members)) } else { Err(ApiError::NotFound) } @@ -202,24 +202,24 @@ pub async fn team_members_get_organization( // Returns all members of a team, but not necessarily those of a project-team's organization (unlike team_members_get_project) pub async fn team_members_get( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let id = info.into_inner().0; let members_data = - TeamMember::get_from_team_full(id.into(), &**pool, &redis).await?; + TeamMember::get_from_team_full(id.into(), &*pool, &redis).await?; let users = crate::database::models::User::get_many_ids( &members_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -257,7 +257,7 @@ pub async fn team_members_get( }) .collect(); - Ok(HttpResponse::Ok().json(team_members)) + Ok(HttpResponse::Ok().json(&team_members)) } #[derive(Serialize, Deserialize)] @@ -267,10 +267,10 @@ pub struct TeamIds { pub async fn teams_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { use itertools::Itertools; @@ -280,17 +280,17 @@ pub async fn teams_get( .collect::>(); let teams_data = - TeamMember::get_from_team_full_many(&team_ids, &**pool, &redis).await?; + TeamMember::get_from_team_full_many(&team_ids, &*pool, &redis).await?; let users = crate::database::models::User::get_many_ids( &teams_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -331,20 +331,20 @@ pub async fn teams_get( teams.push(team_members.collect()); } - Ok(HttpResponse::Ok().json(teams)) + Ok(HttpResponse::Ok().json(&teams)) } pub async fn join_team( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let team_id = info.into_inner().0.into(); let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -355,7 +355,7 @@ pub async fn join_team( let member = TeamMember::get_from_user_id_pending( team_id, current_user.id.into(), - &**pool, + &*pool, ) .await?; @@ -421,11 +421,11 @@ pub struct NewTeamMember { pub async fn add_team_member( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - new_member: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + new_member: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let team_id = info.into_inner().0.into(); @@ -433,14 +433,14 @@ pub async fn add_team_member( let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), ) .await? .1; - let team_association = Team::get_association(team_id, &**pool) + let team_association = Team::get_association(team_id, &*pool) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -448,14 +448,14 @@ pub async fn add_team_member( ) })?; let member = - TeamMember::get_from_user_id(team_id, current_user.id.into(), &**pool) + TeamMember::get_from_user_id(team_id, current_user.id.into(), &*pool) .await?; match team_association { // If team is associated with a project, check if they have permissions to invite users to that project TeamAssociationId::Project(pid) => { let organization = Organization::get_associated_organization_project_id( - pid, &**pool, + pid, &*pool, ) .await?; let organization_team_member = @@ -463,7 +463,7 @@ pub async fn add_team_member( TeamMember::get_from_user_id( organization.team_id, current_user.id.into(), - &**pool, + &*pool, ) .await? } else { @@ -541,7 +541,7 @@ pub async fn add_team_member( let request = TeamMember::get_from_user_id_pending( team_id, new_member.user_id.into(), - &**pool, + &*pool, ) .await?; @@ -559,7 +559,7 @@ pub async fn add_team_member( } let new_user = crate::database::models::User::get_id( new_member.user_id.into(), - &**pool, + &*pool, &redis, ) .await? @@ -571,14 +571,14 @@ pub async fn add_team_member( if let TeamAssociationId::Project(pid) = team_association { // We cannot add the owner to a project team in their own org let organization = - Organization::get_associated_organization_project_id(pid, &**pool) + Organization::get_associated_organization_project_id(pid, &*pool) .await?; let new_user_organization_team_member = if let Some(organization) = &organization { TeamMember::get_from_user_id( organization.team_id, new_user.id, - &**pool, + &*pool, ) .await? } else { @@ -671,11 +671,11 @@ pub struct EditTeamMember { pub async fn edit_team_member( req: HttpRequest, - info: web::Path<(TeamId, UserId)>, - pool: web::Data, - edit_member: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId, UserId)>, + pool: web::types::State, + edit_member: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let ids = info.into_inner(); let id = ids.0.into(); @@ -683,7 +683,7 @@ pub async fn edit_team_member( let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -692,16 +692,16 @@ pub async fn edit_team_member( .1; let team_association = - Team::get_association(id, &**pool).await?.ok_or_else(|| { + Team::get_association(id, &*pool).await?.ok_or_else(|| { ApiError::InvalidInput( "The team specified does not exist".to_string(), ) })?; let member = - TeamMember::get_from_user_id(id, current_user.id.into(), &**pool) + TeamMember::get_from_user_id(id, current_user.id.into(), &*pool) .await?; let edit_member_db = - TeamMember::get_from_user_id_pending(id, user_id, &**pool) + TeamMember::get_from_user_id_pending(id, user_id, &*pool) .await? .ok_or_else(|| { ApiError::CustomAuthentication( @@ -725,7 +725,7 @@ pub async fn edit_team_member( TeamAssociationId::Project(project_id) => { let organization = Organization::get_associated_organization_project_id( - project_id, &**pool, + project_id, &*pool, ) .await?; let organization_team_member = @@ -733,7 +733,7 @@ pub async fn edit_team_member( TeamMember::get_from_user_id( organization.team_id, current_user.id.into(), - &**pool, + &*pool, ) .await? } else { @@ -859,17 +859,17 @@ pub struct TransferOwnership { pub async fn transfer_ownership( req: HttpRequest, - info: web::Path<(TeamId,)>, - pool: web::Data, - new_owner: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId,)>, + pool: web::types::State, + new_owner: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let id = info.into_inner().0; let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -880,9 +880,9 @@ pub async fn transfer_ownership( // Forbid transferring ownership of a project team that is owned by an organization // These are owned by the organization owner, and must be removed from the organization first // There shouldnt be an ownr on these projects in these cases, but just in case. - let team_association_id = Team::get_association(id.into(), &**pool).await?; + let team_association_id = Team::get_association(id.into(), &*pool).await?; if let Some(TeamAssociationId::Project(pid)) = team_association_id { - let result = Project::get_id(pid, &**pool, &redis).await?; + let result = Project::get_id(pid, &*pool, &redis).await?; if let Some(project_item) = result { if project_item.inner.organization_id.is_some() { return Err(ApiError::InvalidInput( @@ -897,7 +897,7 @@ pub async fn transfer_ownership( let member = TeamMember::get_from_user_id( id.into(), current_user.id.into(), - &**pool, + &*pool, ) .await? .ok_or_else(|| { @@ -918,7 +918,7 @@ pub async fn transfer_ownership( let new_member = TeamMember::get_from_user_id( id.into(), new_owner.user_id.into(), - &**pool, + &*pool, ) .await? .ok_or_else(|| { @@ -1021,10 +1021,10 @@ pub async fn transfer_ownership( pub async fn remove_team_member( req: HttpRequest, - info: web::Path<(TeamId, UserId)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(TeamId, UserId)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let ids = info.into_inner(); let id = ids.0.into(); @@ -1032,7 +1032,7 @@ pub async fn remove_team_member( let current_user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_WRITE]), @@ -1041,17 +1041,17 @@ pub async fn remove_team_member( .1; let team_association = - Team::get_association(id, &**pool).await?.ok_or_else(|| { + Team::get_association(id, &*pool).await?.ok_or_else(|| { ApiError::InvalidInput( "The team specified does not exist".to_string(), ) })?; let member = - TeamMember::get_from_user_id(id, current_user.id.into(), &**pool) + TeamMember::get_from_user_id(id, current_user.id.into(), &*pool) .await?; let delete_member = - TeamMember::get_from_user_id_pending(id, user_id, &**pool).await?; + TeamMember::get_from_user_id_pending(id, user_id, &*pool).await?; if let Some(delete_member) = delete_member { if delete_member.is_owner { @@ -1068,7 +1068,7 @@ pub async fn remove_team_member( TeamAssociationId::Project(pid) => { let organization = Organization::get_associated_organization_project_id( - pid, &**pool, + pid, &*pool, ) .await?; let organization_team_member = @@ -1076,7 +1076,7 @@ pub async fn remove_team_member( TeamMember::get_from_user_id( organization.team_id, current_user.id.into(), - &**pool, + &*pool, ) .await? } else { diff --git a/apps/labrinth/src/routes/v3/threads.rs b/apps/labrinth/src/routes/v3/threads.rs index ef500e94e..4656bd0b5 100644 --- a/apps/labrinth/src/routes/v3/threads.rs +++ b/apps/labrinth/src/routes/v3/threads.rs @@ -16,8 +16,8 @@ use crate::models::threads::{MessageBody, Thread, ThreadId, ThreadType}; use crate::models::users::User; use crate::queue::session::AuthQueue; use crate::routes::ApiError; -use actix_web::{web, HttpRequest, HttpResponse}; use futures::TryStreamExt; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::Deserialize; use sqlx::PgPool; @@ -96,7 +96,7 @@ pub async fn is_authorized_thread( pub async fn filter_authorized_threads( threads: Vec, user: &User, - pool: &web::Data, + pool: &web::types::State, redis: &RedisPool, ) -> Result, ApiError> { let user_id: database::models::UserId = user.id.into(); @@ -132,7 +132,7 @@ pub async fn filter_authorized_threads( &*project_thread_ids, user_id as database::models::ids::UserId, ) - .fetch(&***pool) + .fetch(&**pool) .map_ok(|row| { check_threads.retain(|x| { let bool = x.project_id.map(|x| x.0) == Some(row.id); @@ -165,7 +165,7 @@ pub async fn filter_authorized_threads( &*project_thread_ids, user_id as database::models::ids::UserId, ) - .fetch(&***pool) + .fetch(&**pool) .map_ok(|row| { check_threads.retain(|x| { let bool = x.project_id.map(|x| x.0) == Some(row.id); @@ -196,7 +196,7 @@ pub async fn filter_authorized_threads( &*report_thread_ids, user_id as database::models::ids::UserId, ) - .fetch(&***pool) + .fetch(&**pool) .map_ok(|row| { check_threads.retain(|x| { let bool = x.report_id.map(|x| x.0) == Some(row.id); @@ -230,7 +230,7 @@ pub async fn filter_authorized_threads( ); let users: Vec = - database::models::User::get_many_ids(&user_ids, &***pool, redis) + database::models::User::get_many_ids(&user_ids, &**pool, redis) .await? .into_iter() .map(From::from) @@ -271,18 +271,18 @@ pub async fn filter_authorized_threads( pub async fn thread_get( req: HttpRequest, - info: web::Path<(ThreadId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(ThreadId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let string = info.into_inner().0.into(); - let thread_data = database::models::Thread::get(string, &**pool).await?; + let thread_data = database::models::Thread::get(string, &*pool).await?; let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::THREAD_READ]), @@ -309,14 +309,14 @@ pub async fn thread_get( ); let users: Vec = - database::models::User::get_many_ids(authors, &**pool, &redis) + database::models::User::get_many_ids(authors, &*pool, &redis) .await? .into_iter() .map(From::from) .collect(); return Ok( - HttpResponse::Ok().json(Thread::from(data, users, &user)) + HttpResponse::Ok().json(&Thread::from(data, users, &user)) ); } } @@ -330,14 +330,14 @@ pub struct ThreadIds { pub async fn threads_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::THREAD_READ]), @@ -352,12 +352,12 @@ pub async fn threads_get( .collect(); let threads_data = - database::models::Thread::get_many(&thread_ids, &**pool).await?; + database::models::Thread::get_many(&thread_ids, &*pool).await?; let threads = filter_authorized_threads(threads_data, &user, &pool, &redis).await?; - Ok(HttpResponse::Ok().json(threads)) + Ok(HttpResponse::Ok().json(&threads)) } #[derive(Deserialize)] @@ -367,15 +367,15 @@ pub struct NewThreadMessage { pub async fn thread_send_message( req: HttpRequest, - info: web::Path<(ThreadId,)>, - pool: web::Data, - new_message: web::Json, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(ThreadId,)>, + pool: web::types::State, + new_message: web::types::Json, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::THREAD_WRITE]), @@ -407,7 +407,7 @@ pub async fn thread_send_message( if let Some(replying_to) = replying_to { let thread_message = database::models::ThreadMessage::get( (*replying_to).into(), - &**pool, + &*pool, ) .await?; @@ -430,7 +430,7 @@ pub async fn thread_send_message( )); } - let result = database::models::Thread::get(string, &**pool).await?; + let result = database::models::Thread::get(string, &*pool).await?; if let Some(thread) = result { if !is_authorized_thread(&thread, &user, &pool).await? { @@ -450,7 +450,7 @@ pub async fn thread_send_message( if let Some(project_id) = thread.project_id { let project = - database::models::Project::get_id(project_id, &**pool, &redis) + database::models::Project::get_id(project_id, &*pool, &redis) .await?; if let Some(project) = project { @@ -460,7 +460,7 @@ pub async fn thread_send_message( let members = database::models::TeamMember::get_from_team_full( project.inner.team_id, - &**pool, + &*pool, &redis, ) .await?; @@ -483,7 +483,7 @@ pub async fn thread_send_message( } } else if let Some(report_id) = thread.report_id { let report = - database::models::report_item::Report::get(report_id, &**pool) + database::models::report_item::Report::get(report_id, &*pool) .await?; if let Some(report) = report { @@ -565,15 +565,15 @@ pub async fn thread_send_message( pub async fn message_delete( req: HttpRequest, - info: web::Path<(ThreadMessageId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - file_host: web::Data>, + info: web::types::Path<(ThreadMessageId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + file_host: web::types::State>, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::THREAD_WRITE]), @@ -583,7 +583,7 @@ pub async fn message_delete( let result = database::models::ThreadMessage::get( info.into_inner().0.into(), - &**pool, + &*pool, ) .await?; diff --git a/apps/labrinth/src/routes/v3/users.rs b/apps/labrinth/src/routes/v3/users.rs index f0aafe265..49044a671 100644 --- a/apps/labrinth/src/routes/v3/users.rs +++ b/apps/labrinth/src/routes/v3/users.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, sync::Arc}; -use actix_web::{web, HttpRequest, HttpResponse}; use lazy_static::lazy_static; +use ntex::web::{self, HttpRequest, HttpResponse}; use regex::Regex; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -46,14 +46,14 @@ pub fn config(cfg: &mut web::ServiceConfig) { pub async fn projects_list( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -62,20 +62,20 @@ pub async fn projects_list( .map(|x| x.1) .ok(); - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(id) = id_option.map(|x| x.id) { - let project_data = User::get_projects(id, &**pool, &redis).await?; + let project_data = User::get_projects(id, &*pool, &redis).await?; let projects: Vec<_> = crate::database::Project::get_many_ids( &project_data, - &**pool, + &*pool, &redis, ) .await?; let projects = filter_visible_projects(projects, &user, &pool, true).await?; - Ok(HttpResponse::Ok().json(projects)) + Ok(HttpResponse::Ok().json(&projects)) } else { Err(ApiError::NotFound) } @@ -83,13 +83,13 @@ pub async fn projects_list( pub async fn user_auth_get( req: HttpRequest, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let (scopes, mut user) = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_READ]), @@ -104,7 +104,7 @@ pub async fn user_auth_get( user.payout_data = None; } - Ok(HttpResponse::Ok().json(user)) + Ok(HttpResponse::Ok().json(&user)) } #[derive(Serialize, Deserialize)] @@ -113,30 +113,30 @@ pub struct UserIds { } pub async fn users_get( - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, ) -> Result { let user_ids = serde_json::from_str::>(&ids.ids)?; - let users_data = User::get_many(&user_ids, &**pool, &redis).await?; + let users_data = User::get_many(&user_ids, &*pool, &redis).await?; let users: Vec = users_data.into_iter().map(From::from).collect(); - Ok(HttpResponse::Ok().json(users)) + Ok(HttpResponse::Ok().json(&users)) } pub async fn user_get( - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, ) -> Result { - let user_data = User::get(&info.into_inner().0, &**pool, &redis).await?; + let user_data = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(data) = user_data { let response: crate::models::users::User = data.into(); - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } else { Err(ApiError::NotFound) } @@ -144,14 +144,14 @@ pub async fn user_get( pub async fn collections_list( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::COLLECTION_READ]), @@ -160,7 +160,7 @@ pub async fn collections_list( .map(|x| x.1) .ok(); - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(id) = id_option.map(|x| x.id) { let user_id: UserId = id.into(); @@ -169,11 +169,11 @@ pub async fn collections_list( .map(|y| y.role.is_mod() || y.id == user_id) .unwrap_or(false); - let project_data = User::get_collections(id, &**pool).await?; + let project_data = User::get_collections(id, &*pool).await?; let response: Vec<_> = crate::database::models::Collection::get_many( &project_data, - &**pool, + &*pool, &redis, ) .await? @@ -184,7 +184,7 @@ pub async fn collections_list( .map(Collection::from) .collect(); - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } else { Err(ApiError::NotFound) } @@ -192,14 +192,14 @@ pub async fn collections_list( pub async fn orgs_list( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ]), @@ -208,14 +208,14 @@ pub async fn orgs_list( .map(|x| x.1) .ok(); - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(id) = id_option.map(|x| x.id) { - let org_data = User::get_organizations(id, &**pool).await?; + let org_data = User::get_organizations(id, &*pool).await?; let organizations_data = crate::database::models::organization_item::Organization::get_many_ids( - &org_data, &**pool, &redis, + &org_data, &*pool, &redis, ) .await?; @@ -226,12 +226,12 @@ pub async fn orgs_list( let teams_data = crate::database::models::TeamMember::get_from_team_full_many( - &team_ids, &**pool, &redis, + &team_ids, &*pool, &redis, ) .await?; let users = User::get_many_ids( &teams_data.iter().map(|x| x.user_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -275,7 +275,7 @@ pub async fn orgs_list( organizations.push(organization); } - Ok(HttpResponse::Ok().json(organizations)) + Ok(HttpResponse::Ok().json(&organizations)) } else { Err(ApiError::NotFound) } @@ -305,15 +305,15 @@ pub struct EditUser { pub async fn user_edit( req: HttpRequest, - info: web::Path<(String,)>, - new_user: web::Json, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + new_user: web::types::Json, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let (scopes, user) = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_WRITE]), @@ -324,7 +324,7 @@ pub async fn user_edit( ApiError::Validation(validation_errors_to_string(err, None)) })?; - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(actual_user) = id_option { let id = actual_user.id; @@ -335,7 +335,7 @@ pub async fn user_edit( if let Some(username) = &new_user.username { let existing_user_id_option = - User::get(username, &**pool, &redis).await?; + User::get(username, &*pool, &redis).await?; if existing_user_id_option .map(|x| UserId::from(x.id)) @@ -474,25 +474,25 @@ pub struct Extension { #[allow(clippy::too_many_arguments)] pub async fn user_icon_edit( - web::Query(ext): web::Query, + web::types::Query(ext): web::types::Query, req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - file_host: web::Data>, - mut payload: web::Payload, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + mut payload: web::types::Payload, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_WRITE]), ) .await? .1; - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(actual_user) = id_option { if user.id != actual_user.id.into() && !user.role.is_mod() { @@ -505,7 +505,7 @@ pub async fn user_icon_edit( delete_old_images( actual_user.avatar_url, actual_user.raw_avatar_url, - &***file_host, + &**file_host, ) .await?; @@ -523,7 +523,7 @@ pub async fn user_icon_edit( &ext.ext, Some(96), Some(1.0), - &***file_host, + &**file_host, ) .await?; @@ -537,7 +537,7 @@ pub async fn user_icon_edit( upload_result.raw_url, actual_user.id as crate::database::models::ids::UserId, ) - .execute(&**pool) + .execute(&*pool) .await?; User::clear_caches(&[(actual_user.id, None)], &redis).await?; @@ -549,21 +549,21 @@ pub async fn user_icon_edit( pub async fn user_delete( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_DELETE]), ) .await? .1; - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(id) = id_option.map(|x| x.id) { if !user.role.is_admin() && user.id != id.into() { @@ -590,21 +590,21 @@ pub async fn user_delete( pub async fn user_follows( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::USER_READ]), ) .await? .1; - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(id) = id_option.map(|x| x.id) { if !user.role.is_admin() && user.id != id.into() { @@ -613,10 +613,10 @@ pub async fn user_follows( )); } - let project_ids = User::get_follows(id, &**pool).await?; + let project_ids = User::get_follows(id, &*pool).await?; let projects: Vec<_> = crate::database::Project::get_many_ids( &project_ids, - &**pool, + &*pool, &redis, ) .await? @@ -624,7 +624,7 @@ pub async fn user_follows( .map(Project::from) .collect(); - Ok(HttpResponse::Ok().json(projects)) + Ok(HttpResponse::Ok().json(&projects)) } else { Err(ApiError::NotFound) } @@ -632,21 +632,21 @@ pub async fn user_follows( pub async fn user_notifications( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::NOTIFICATION_READ]), ) .await? .1; - let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?; + let id_option = User::get(&info.into_inner().0, &*pool, &redis).await?; if let Some(id) = id_option.map(|x| x.id) { if !user.role.is_admin() && user.id != id.into() { @@ -657,7 +657,7 @@ pub async fn user_notifications( let mut notifications: Vec = crate::database::models::notification_item::Notification::get_many_user( - id, &**pool, &redis, + id, &*pool, &redis, ) .await? .into_iter() @@ -665,7 +665,7 @@ pub async fn user_notifications( .collect(); notifications.sort_by(|a, b| b.created.cmp(&a.created)); - Ok(HttpResponse::Ok().json(notifications)) + Ok(HttpResponse::Ok().json(¬ifications)) } else { Err(ApiError::NotFound) } diff --git a/apps/labrinth/src/routes/v3/version_creation.rs b/apps/labrinth/src/routes/v3/version_creation.rs index 8d531c22b..b2f5fc9a4 100644 --- a/apps/labrinth/src/routes/v3/version_creation.rs +++ b/apps/labrinth/src/routes/v3/version_creation.rs @@ -25,12 +25,11 @@ use crate::queue::session::AuthQueue; use crate::util::routes::read_from_field; use crate::util::validate::validation_errors_to_string; use crate::validate::{validate_file, ValidationResult}; -use actix_multipart::{Field, Multipart}; -use actix_web::web::Data; -use actix_web::{web, HttpRequest, HttpResponse}; use chrono::Utc; use futures::stream::StreamExt; use itertools::Itertools; +use ntex::web::{self, HttpRequest, HttpResponse}; +use ntex_multipart::{Field, Multipart}; use serde::{Deserialize, Serialize}; use sqlx::postgres::PgPool; use std::collections::{HashMap, HashSet}; @@ -101,11 +100,11 @@ struct InitialFileData { pub async fn version_create( req: HttpRequest, mut payload: Multipart, - client: Data, - redis: Data, - file_host: Data>, - session_queue: Data, - moderation_queue: web::Data, + client: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, + moderation_queue: web::types::State, ) -> Result { let mut transaction = client.begin().await?; let mut uploaded_files = Vec::new(); @@ -115,7 +114,7 @@ pub async fn version_create( &mut payload, &mut transaction, &redis, - &***file_host, + &**file_host, &mut uploaded_files, &client, &session_queue, @@ -125,7 +124,7 @@ pub async fn version_create( if result.is_err() { let undo_result = super::project_creation::undo_uploads( - &***file_host, + &**file_host, &uploaded_files, ) .await; @@ -526,17 +525,17 @@ async fn version_create_inner( } } - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } pub async fn upload_file_to_version( req: HttpRequest, - url_data: web::Path<(VersionId,)>, + url_data: web::types::Path<(VersionId,)>, mut payload: Multipart, - client: Data, - redis: Data, - file_host: Data>, - session_queue: web::Data, + client: web::types::State, + redis: web::types::State, + file_host: web::types::State>, + session_queue: web::types::State, ) -> Result { let mut transaction = client.begin().await?; let mut uploaded_files = Vec::new(); @@ -549,7 +548,7 @@ pub async fn upload_file_to_version( client, &mut transaction, redis, - &***file_host, + &**file_host, &mut uploaded_files, version_id, &session_queue, @@ -558,7 +557,7 @@ pub async fn upload_file_to_version( if result.is_err() { let undo_result = super::project_creation::undo_uploads( - &***file_host, + &**file_host, &uploaded_files, ) .await; @@ -579,9 +578,9 @@ pub async fn upload_file_to_version( async fn upload_file_to_version_inner( req: HttpRequest, payload: &mut Multipart, - client: Data, + client: web::types::State, transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>, - redis: Data, + redis: web::types::State, file_host: &dyn FileHost, uploaded_files: &mut Vec, version_id: models::VersionId, @@ -594,7 +593,7 @@ async fn upload_file_to_version_inner( let user = get_user_from_headers( &req, - &**client, + &*client, &redis, session_queue, Some(&[Scopes::VERSION_WRITE]), @@ -602,7 +601,7 @@ async fn upload_file_to_version_inner( .await? .1; - let result = models::Version::get(version_id, &**client, &redis).await?; + let result = models::Version::get(version_id, &*client, &redis).await?; let version = match result { Some(v) => v, @@ -652,7 +651,7 @@ async fn upload_file_to_version_inner( let organization = Organization::get_associated_organization_project_id( version.inner.project_id, - &**client, + &*client, ) .await?; diff --git a/apps/labrinth/src/routes/v3/version_file.rs b/apps/labrinth/src/routes/v3/version_file.rs index e34d8ef53..9fe4666ad 100644 --- a/apps/labrinth/src/routes/v3/version_file.rs +++ b/apps/labrinth/src/routes/v3/version_file.rs @@ -8,10 +8,10 @@ use crate::models::projects::VersionType; use crate::models::teams::ProjectPermissions; use crate::queue::session::AuthQueue; use crate::{database, models}; -use actix_web::{web, HttpRequest, HttpResponse}; use dashmap::DashMap; use futures::TryStreamExt; use itertools::Itertools; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; use std::collections::HashMap; @@ -35,15 +35,15 @@ pub fn config(cfg: &mut web::ServiceConfig) { pub async fn get_version_from_hash( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + session_queue: web::types::State, ) -> Result { let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_READ]), @@ -60,13 +60,13 @@ pub async fn get_version_from_hash( algorithm, hash, hash_query.version_id.map(|x| x.into()), - &**pool, + &*pool, &redis, ) .await?; if let Some(file) = file { let version = - database::models::Version::get(file.version_id, &**pool, &redis) + database::models::Version::get(file.version_id, &*pool, &redis) .await?; if let Some(version) = version { if !is_visible_version(&version.inner, &user_option, &pool, &redis) @@ -76,7 +76,7 @@ pub async fn get_version_from_hash( } Ok(HttpResponse::Ok() - .json(models::projects::Version::from(version))) + .json(&models::projects::Version::from(version))) } else { Err(ApiError::NotFound) } @@ -121,16 +121,16 @@ pub struct UpdateData { pub async fn get_update_from_hash( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - update_data: web::Json, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + update_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_READ]), @@ -146,18 +146,18 @@ pub async fn get_update_from_hash( .unwrap_or_else(|| default_algorithm_from_hashes(&[hash.clone()])), hash, hash_query.version_id.map(|x| x.into()), - &**pool, + &*pool, &redis, ) .await? { if let Some(project) = - database::models::Project::get_id(file.project_id, &**pool, &redis) + database::models::Project::get_id(file.project_id, &*pool, &redis) .await? { let versions = database::models::Version::get_many( &project.versions, - &**pool, + &*pool, &redis, ) .await? @@ -204,7 +204,7 @@ pub async fn get_update_from_hash( } return Ok(HttpResponse::Ok() - .json(models::projects::Version::from(first))); + .json(&models::projects::Version::from(first))); } } } @@ -220,14 +220,14 @@ pub struct FileHashes { pub async fn get_versions_from_hashes( req: HttpRequest, - pool: web::Data, - redis: web::Data, - file_data: web::Json, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + file_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_READ]), @@ -244,14 +244,14 @@ pub async fn get_versions_from_hashes( let files = database::models::Version::get_files_from_hash( algorithm.clone(), &file_data.hashes, - &**pool, + &*pool, &redis, ) .await?; let version_ids = files.iter().map(|x| x.version_id).collect::>(); let versions_data = filter_visible_versions( - database::models::Version::get_many(&version_ids, &**pool, &redis) + database::models::Version::get_many(&version_ids, &*pool, &redis) .await?, &user_option, &pool, @@ -269,19 +269,19 @@ pub async fn get_versions_from_hashes( } } - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } pub async fn get_projects_from_hashes( req: HttpRequest, - pool: web::Data, - redis: web::Data, - file_data: web::Json, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + file_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ, Scopes::VERSION_READ]), @@ -297,7 +297,7 @@ pub async fn get_projects_from_hashes( let files = database::models::Version::get_files_from_hash( algorithm.clone(), &file_data.hashes, - &**pool, + &*pool, &redis, ) .await?; @@ -305,7 +305,7 @@ pub async fn get_projects_from_hashes( let project_ids = files.iter().map(|x| x.project_id).collect::>(); let projects_data = filter_visible_projects( - database::models::Project::get_many_ids(&project_ids, &**pool, &redis) + database::models::Project::get_many_ids(&project_ids, &*pool, &redis) .await?, &user_option, &pool, @@ -323,7 +323,7 @@ pub async fn get_projects_from_hashes( } } - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } #[derive(Deserialize)] @@ -335,9 +335,9 @@ pub struct ManyUpdateData { pub version_types: Option>, } pub async fn update_files( - pool: web::Data, - redis: web::Data, - update_data: web::Json, + pool: web::types::State, + redis: web::types::State, + update_data: web::types::Json, ) -> Result { let algorithm = update_data .algorithm @@ -346,7 +346,7 @@ pub async fn update_files( let files = database::models::Version::get_files_from_hash( algorithm.clone(), &update_data.hashes, - &**pool, + &*pool, &redis, ) .await?; @@ -369,7 +369,7 @@ pub async fn update_files( &update_data.loaders.clone().unwrap_or_default(), &update_data.version_types.clone().unwrap_or_default().iter().map(|x| x.to_string()).collect::>(), ) - .fetch(&**pool) + .fetch(&*pool) .try_fold(DashMap::new(), |acc : DashMap<_,Vec>, m| { acc.entry(database::models::ProjectId(m.mod_id)) .or_default() @@ -383,7 +383,7 @@ pub async fn update_files( .into_iter() .filter_map(|x| x.1.last().copied()) .collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -403,7 +403,7 @@ pub async fn update_files( } } - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } #[derive(Serialize, Deserialize)] @@ -422,14 +422,14 @@ pub struct ManyFileUpdateData { pub async fn update_individual_files( req: HttpRequest, - pool: web::Data, - redis: web::Data, - update_data: web::Json, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + update_data: web::types::Json, + session_queue: web::types::State, ) -> Result { let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_READ]), @@ -454,14 +454,14 @@ pub async fn update_individual_files( .iter() .map(|x| x.hash.clone()) .collect::>(), - &**pool, + &*pool, &redis, ) .await?; let projects = database::models::Project::get_many_ids( &files.iter().map(|x| x.project_id).collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -470,7 +470,7 @@ pub async fn update_individual_files( .iter() .flat_map(|x| x.versions.clone()) .collect::>(), - &**pool, + &*pool, &redis, ) .await?; @@ -547,21 +547,21 @@ pub async fn update_individual_files( } } - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } // under /api/v1/version_file/{hash} pub async fn delete_file( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_WRITE]), @@ -578,7 +578,7 @@ pub async fn delete_file( algorithm.clone(), hash, hash_query.version_id.map(|x| x.into()), - &**pool, + &*pool, &redis, ) .await?; @@ -589,7 +589,7 @@ pub async fn delete_file( database::models::TeamMember::get_from_user_id_version( row.version_id, user.id.into(), - &**pool, + &*pool, ) .await .map_err(ApiError::Database)?; @@ -597,7 +597,7 @@ pub async fn delete_file( let organization = database::models::Organization::get_associated_organization_project_id( row.project_id, - &**pool, + &*pool, ) .await .map_err(ApiError::Database)?; @@ -608,7 +608,7 @@ pub async fn delete_file( organization.id, user.id.into(), false, - &**pool, + &*pool, ) .await .map_err(ApiError::Database)? @@ -632,7 +632,7 @@ pub async fn delete_file( } let version = - database::models::Version::get(row.version_id, &**pool, &redis) + database::models::Version::get(row.version_id, &*pool, &redis) .await?; if let Some(version) = version { if version.files.len() < 2 { @@ -683,15 +683,15 @@ pub struct DownloadRedirect { // under /api/v1/version_file/{hash}/download pub async fn download_version( req: HttpRequest, - info: web::Path<(String,)>, - pool: web::Data, - redis: web::Data, - hash_query: web::Query, - session_queue: web::Data, + info: web::types::Path<(String,)>, + pool: web::types::State, + redis: web::types::State, + hash_query: web::types::Query, + session_queue: web::types::State, ) -> Result { let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_READ]), @@ -709,14 +709,14 @@ pub async fn download_version( algorithm.clone(), hash, hash_query.version_id.map(|x| x.into()), - &**pool, + &*pool, &redis, ) .await?; if let Some(file) = file { let version = - database::models::Version::get(file.version_id, &**pool, &redis) + database::models::Version::get(file.version_id, &*pool, &redis) .await?; if let Some(version) = version { @@ -727,8 +727,8 @@ pub async fn download_version( } Ok(HttpResponse::TemporaryRedirect() - .append_header(("Location", &*file.url)) - .json(DownloadRedirect { url: file.url })) + .header("Location", &*file.url) + .json(&DownloadRedirect { url: file.url })) } else { Err(ApiError::NotFound) } diff --git a/apps/labrinth/src/routes/v3/versions.rs b/apps/labrinth/src/routes/v3/versions.rs index ac27a075c..2aa8c0642 100644 --- a/apps/labrinth/src/routes/v3/versions.rs +++ b/apps/labrinth/src/routes/v3/versions.rs @@ -27,38 +27,37 @@ use crate::search::indexing::remove_documents; use crate::search::SearchConfig; use crate::util::img; use crate::util::validate::validation_errors_to_string; -use actix_web::{web, HttpRequest, HttpResponse}; use itertools::Itertools; +use ntex::web::{self, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; use validator::Validate; pub fn config(cfg: &mut web::ServiceConfig) { - cfg.route( - "version", - web::post().to(super::version_creation::version_create), - ); + // cfg.route( + // "version", + // web::post().to(super::version_creation::version_create), + // ); cfg.route("versions", web::get().to(versions_get)); cfg.service( web::scope("version") .route("{id}", web::get().to(version_get)) .route("{id}", web::patch().to(version_edit)) - .route("{id}", web::delete().to(version_delete)) - .route( - "{version_id}/file", - web::post().to(super::version_creation::upload_file_to_version), - ), + .route("{id}", web::delete().to(version_delete)), // .route( + // "{version_id}/file", + // web::post().to(super::version_creation::upload_file_to_version), + // ), ); } // Given a project ID/slug and a version slug pub async fn version_project_get( req: HttpRequest, - info: web::Path<(String, String)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String, String)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let info = info.into_inner(); version_project_get_helper(req, info, pool, redis, session_queue).await @@ -66,15 +65,15 @@ pub async fn version_project_get( pub async fn version_project_get_helper( req: HttpRequest, id: (String, String), - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { - let result = database::models::Project::get(&id.0, &**pool, &redis).await?; + let result = database::models::Project::get(&id.0, &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ, Scopes::VERSION_READ]), @@ -92,7 +91,7 @@ pub async fn version_project_get_helper( let versions = database::models::Version::get_many( &project.versions, - &**pool, + &*pool, &redis, ) .await?; @@ -108,7 +107,7 @@ pub async fn version_project_get_helper( .await? { return Ok(HttpResponse::Ok() - .json(models::projects::Version::from(version))); + .json(&models::projects::Version::from(version))); } } } @@ -123,10 +122,10 @@ pub struct VersionIds { pub async fn versions_get( req: HttpRequest, - web::Query(ids): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + web::types::Query(ids): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let version_ids = serde_json::from_str::>(&ids.ids)? @@ -134,12 +133,12 @@ pub async fn versions_get( .map(|x| x.into()) .collect::>(); let versions_data = - database::models::Version::get_many(&version_ids, &**pool, &redis) + database::models::Version::get_many(&version_ids, &*pool, &redis) .await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_READ]), @@ -152,15 +151,15 @@ pub async fn versions_get( filter_visible_versions(versions_data, &user_option, &pool, &redis) .await?; - Ok(HttpResponse::Ok().json(versions)) + Ok(HttpResponse::Ok().json(&versions)) } pub async fn version_get( req: HttpRequest, - info: web::Path<(models::ids::VersionId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(models::ids::VersionId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let id = info.into_inner().0; version_get_helper(req, id, pool, redis, session_queue).await @@ -169,16 +168,16 @@ pub async fn version_get( pub async fn version_get_helper( req: HttpRequest, id: models::ids::VersionId, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let version_data = - database::models::Version::get(id.into(), &**pool, &redis).await?; + database::models::Version::get(id.into(), &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_READ]), @@ -190,7 +189,7 @@ pub async fn version_get_helper( if let Some(data) = version_data { if is_visible_version(&data.inner, &user_option, &pool, &redis).await? { return Ok( - HttpResponse::Ok().json(models::projects::Version::from(data)) + HttpResponse::Ok().json(&models::projects::Version::from(data)) ); } } @@ -247,11 +246,11 @@ pub struct EditVersionFileType { pub async fn version_edit( req: HttpRequest, - info: web::Path<(VersionId,)>, - pool: web::Data, - redis: web::Data, - new_version: web::Json, - session_queue: web::Data, + info: web::types::Path<(VersionId,)>, + pool: web::types::State, + redis: web::types::State, + new_version: web::types::Json, + session_queue: web::types::State, ) -> Result { let new_version: EditVersion = serde_json::from_value(new_version.into_inner())?; @@ -268,14 +267,14 @@ pub async fn version_edit( pub async fn version_edit_helper( req: HttpRequest, info: (VersionId,), - pool: web::Data, - redis: web::Data, + pool: web::types::State, + redis: web::types::State, new_version: EditVersion, - session_queue: web::Data, + session_queue: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_WRITE]), @@ -290,7 +289,7 @@ pub async fn version_edit_helper( let version_id = info.0; let id = version_id.into(); - let result = database::models::Version::get(id, &**pool, &redis).await?; + let result = database::models::Version::get(id, &*pool, &redis).await?; if let Some(version_item) = result { let team_member = @@ -298,14 +297,14 @@ pub async fn version_edit_helper( version_item.inner.project_id, user.id.into(), false, - &**pool, + &*pool, ) .await?; let organization = Organization::get_associated_organization_project_id( version_item.inner.project_id, - &**pool, + &*pool, ) .await?; @@ -314,7 +313,7 @@ pub async fn version_edit_helper( database::models::TeamMember::get_from_user_id( organization.team_id, user.id.into(), - &**pool, + &*pool, ) .await? } else { @@ -621,7 +620,7 @@ pub async fn version_edit_helper( file_type.hash.as_bytes(), file_type.algorithm ) - .fetch_optional(&**pool) + .fetch_optional(&*pool) .await? .ok_or_else(|| { ApiError::InvalidInput(format!( @@ -714,20 +713,20 @@ pub struct VersionListFilters { pub async fn version_list( req: HttpRequest, - info: web::Path<(String,)>, - web::Query(filters): web::Query, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, + info: web::types::Path<(String,)>, + web::types::Query(filters): web::types::Query, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, ) -> Result { let string = info.into_inner().0; let result = - database::models::Project::get(&string, &**pool, &redis).await?; + database::models::Project::get(&string, &*pool, &redis).await?; let user_option = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::PROJECT_READ, Scopes::VERSION_READ]), @@ -752,7 +751,7 @@ pub async fn version_list( }); let mut versions = database::models::Version::get_many( &project.versions, - &**pool, + &*pool, &redis, ) .await? @@ -806,11 +805,11 @@ pub async fn version_list( // TODO: This is a bandaid fix for detecting auto-featured versions. // In the future, not all versions will have 'game_versions' fields, so this will need to be changed. let (loaders, game_versions) = futures::future::try_join( - database::models::loader_fields::Loader::list(&**pool, &redis), + database::models::loader_fields::Loader::list(&*pool, &redis), database::models::legacy_loader_fields::MinecraftGameVersion::list( None, Some(true), - &**pool, + &*pool, &redis, ), ) @@ -858,7 +857,7 @@ pub async fn version_list( filter_visible_versions(response, &user_option, &pool, &redis) .await?; - Ok(HttpResponse::Ok().json(response)) + Ok(HttpResponse::Ok().json(&response)) } else { Err(ApiError::NotFound) } @@ -866,15 +865,15 @@ pub async fn version_list( pub async fn version_delete( req: HttpRequest, - info: web::Path<(VersionId,)>, - pool: web::Data, - redis: web::Data, - session_queue: web::Data, - search_config: web::Data, + info: web::types::Path<(VersionId,)>, + pool: web::types::State, + redis: web::types::State, + session_queue: web::types::State, + search_config: web::types::State, ) -> Result { let user = get_user_from_headers( &req, - &**pool, + &*pool, &redis, &session_queue, Some(&[Scopes::VERSION_DELETE]), @@ -883,7 +882,7 @@ pub async fn version_delete( .1; let id = info.into_inner().0; - let version = database::models::Version::get(id.into(), &**pool, &redis) + let version = database::models::Version::get(id.into(), &*pool, &redis) .await? .ok_or_else(|| { ApiError::InvalidInput( @@ -897,7 +896,7 @@ pub async fn version_delete( version.inner.project_id, user.id.into(), false, - &**pool, + &*pool, ) .await .map_err(ApiError::Database)?; @@ -905,7 +904,7 @@ pub async fn version_delete( let organization = Organization::get_associated_organization_project_id( version.inner.project_id, - &**pool, + &*pool, ) .await?; @@ -914,7 +913,7 @@ pub async fn version_delete( database::models::TeamMember::get_from_user_id( organization.team_id, user.id.into(), - &**pool, + &*pool, ) .await? } else { diff --git a/apps/labrinth/src/scheduler.rs b/apps/labrinth/src/scheduler.rs index 7bc5e5195..fd7619e0b 100644 --- a/apps/labrinth/src/scheduler.rs +++ b/apps/labrinth/src/scheduler.rs @@ -1,53 +1,25 @@ -use actix_rt::Arbiter; -use futures::StreamExt; - -pub struct Scheduler { - arbiter: Arbiter, -} - -impl Default for Scheduler { - fn default() -> Self { - Self::new() - } -} - -impl Scheduler { - pub fn new() -> Self { - Scheduler { - arbiter: Arbiter::new(), +use std::time::Duration; + +pub fn schedule(interval: Duration, mut task: F) +where + F: FnMut() -> R + Send + 'static, + R: std::future::Future + Send + 'static, +{ + tokio::task::spawn(async move { + let mut interval_stream = tokio::time::interval(interval); + loop { + interval_stream.tick().await; + task().await; } - } - - pub fn run(&mut self, interval: std::time::Duration, mut task: F) - where - F: FnMut() -> R + Send + 'static, - R: std::future::Future + Send + 'static, - { - let future = IntervalStream::new(actix_rt::time::interval(interval)) - .for_each_concurrent(2, move |_| task()); - - self.arbiter.spawn(future); - } -} - -impl Drop for Scheduler { - fn drop(&mut self) { - self.arbiter.stop(); - } + }); } -use log::{info, warn}; - -pub fn schedule_versions( - scheduler: &mut Scheduler, - pool: sqlx::Pool, - redis: RedisPool, -) { +pub fn schedule_versions(pool: sqlx::Pool, redis: RedisPool) { let version_index_interval = std::time::Duration::from_secs( parse_var("VERSION_INDEX_INTERVAL").unwrap_or(1800), ); - scheduler.run(version_index_interval, move || { + schedule(version_index_interval, move || { let pool_ref = pool.clone(); let redis = redis.clone(); async move { @@ -78,8 +50,8 @@ use crate::{ util::env::parse_var, }; use chrono::{DateTime, Utc}; +use log::{info, warn}; use serde::Deserialize; -use tokio_stream::wrappers::IntervalStream; #[derive(Deserialize)] struct InputFormat<'a> { diff --git a/apps/labrinth/src/search/indexing/mod.rs b/apps/labrinth/src/search/indexing/mod.rs index 679473038..1385a4df2 100644 --- a/apps/labrinth/src/search/indexing/mod.rs +++ b/apps/labrinth/src/search/indexing/mod.rs @@ -54,8 +54,8 @@ pub async fn remove_documents( } pub async fn index_projects( - pool: PgPool, - redis: RedisPool, + pool: &PgPool, + redis: &RedisPool, config: &SearchConfig, ) -> Result<(), IndexingError> { info!("Indexing projects."); @@ -73,7 +73,7 @@ pub async fn index_projects( let all_loader_fields = crate::database::models::loader_fields::LoaderField::get_fields_all( - &pool, &redis, + pool, redis, ) .await? .into_iter() diff --git a/apps/labrinth/src/search/mod.rs b/apps/labrinth/src/search/mod.rs index 244928f25..3281e0776 100644 --- a/apps/labrinth/src/search/mod.rs +++ b/apps/labrinth/src/search/mod.rs @@ -1,10 +1,10 @@ use crate::models::error::ApiError; use crate::models::projects::SearchRequest; -use actix_web::http::StatusCode; -use actix_web::HttpResponse; use chrono::{DateTime, Utc}; use itertools::Itertools; use meilisearch_sdk::client::Client; +use ntex::http::StatusCode; +use ntex::web::{HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; use serde_json::Value; use std::borrow::Cow; @@ -30,7 +30,7 @@ pub enum SearchError { InvalidIndex(String), } -impl actix_web::ResponseError for SearchError { +impl ntex::web::WebResponseError for SearchError { fn status_code(&self) -> StatusCode { match self { SearchError::Env(..) => StatusCode::INTERNAL_SERVER_ERROR, @@ -42,8 +42,8 @@ impl actix_web::ResponseError for SearchError { } } - fn error_response(&self) -> HttpResponse { - HttpResponse::build(self.status_code()).json(ApiError { + fn error_response(&self, _req: &HttpRequest) -> HttpResponse { + HttpResponse::build(self.status_code()).json(&ApiError { error: match self { SearchError::Env(..) => "environment_error", SearchError::MeiliSearch(..) => "meilisearch_error", diff --git a/apps/labrinth/src/util/actix.rs b/apps/labrinth/src/util/actix.rs index d89eb17ef..78c630e2d 100644 --- a/apps/labrinth/src/util/actix.rs +++ b/apps/labrinth/src/util/actix.rs @@ -1,5 +1,6 @@ -use actix_web::test::TestRequest; use bytes::{Bytes, BytesMut}; +use image::EncodableLayout; +use ntex::web::test::TestRequest; // Multipart functionality for actix // Primarily for testing or some implementations of route-redirection @@ -31,12 +32,14 @@ impl AppendsMultipart for TestRequest { self, data: impl IntoIterator, ) -> Self { - let (boundary, payload) = generate_multipart(data); - self.append_header(( - "Content-Type", - format!("multipart/form-data; boundary={}", boundary), - )) - .set_payload(payload) + // TODO: fix me + // let (boundary, payload) = generate_multipart(data); + // self.header( + // "Content-Type", + // format!("multipart/form-data; boundary={}", boundary), + // ) + // .set_payload(payload.as_bytes()) + self } } diff --git a/apps/labrinth/src/util/captcha.rs b/apps/labrinth/src/util/captcha.rs index 8527e94b1..56990c7b2 100644 --- a/apps/labrinth/src/util/captcha.rs +++ b/apps/labrinth/src/util/captcha.rs @@ -1,6 +1,6 @@ use crate::routes::ApiError; use crate::util::env::parse_var; -use actix_web::HttpRequest; +use ntex::web::HttpRequest; use serde::Deserialize; use std::collections::HashMap; @@ -8,15 +8,14 @@ pub async fn check_hcaptcha( req: &HttpRequest, challenge: &str, ) -> Result { - let conn_info = req.connection_info().clone(); let ip_addr = if parse_var("CLOUDFLARE_INTEGRATION").unwrap_or(false) { if let Some(header) = req.headers().get("CF-Connecting-IP") { - header.to_str().ok() + header.to_str().ok().map(|x| x.to_string()) } else { - conn_info.peer_addr() + req.peer_addr().map(|x| x.to_string()) } } else { - conn_info.peer_addr() + req.peer_addr().map(|x| x.to_string()) }; let ip_addr = ip_addr.ok_or(ApiError::Turnstile)?; @@ -33,7 +32,7 @@ pub async fn check_hcaptcha( let secret = dotenvy::var("HCAPTCHA_SECRET")?; form.insert("response", challenge); form.insert("secret", &*secret); - form.insert("remoteip", ip_addr); + form.insert("remoteip", &ip_addr); let val: Response = client .post("https://api.hcaptcha.com/siteverify") diff --git a/apps/labrinth/src/util/cors.rs b/apps/labrinth/src/util/cors.rs index 5f35b2bc5..520f042d8 100644 --- a/apps/labrinth/src/util/cors.rs +++ b/apps/labrinth/src/util/cors.rs @@ -1,10 +1,5 @@ -use actix_cors::Cors; +use ntex_cors::{Cors, CorsFactory}; -pub fn default_cors() -> Cors { +pub fn default_cors() -> CorsFactory { Cors::default() - .allow_any_origin() - .allow_any_header() - .allow_any_method() - .max_age(3600) - .send_wildcard() } diff --git a/apps/labrinth/src/util/guards.rs b/apps/labrinth/src/util/guards.rs index f7ad43ccf..c4376c62c 100644 --- a/apps/labrinth/src/util/guards.rs +++ b/apps/labrinth/src/util/guards.rs @@ -1,12 +1,13 @@ -use actix_web::guard::GuardContext; - -pub const ADMIN_KEY_HEADER: &str = "Modrinth-Admin"; -pub fn admin_key_guard(ctx: &GuardContext) -> bool { - let admin_key = std::env::var("LABRINTH_ADMIN_KEY").expect( - "No admin key provided, this should have been caught by check_env_vars", - ); - ctx.head() - .headers() - .get(ADMIN_KEY_HEADER) - .map_or(false, |it| it.as_bytes() == admin_key.as_bytes()) -} +// TODO: fix me +// use actix_web::guard::GuardContext; +// +// pub const ADMIN_KEY_HEADER: &str = "Modrinth-Admin"; +// pub fn admin_key_guard(ctx: &GuardContext) -> bool { +// let admin_key = std::env::var("LABRINTH_ADMIN_KEY").expect( +// "No admin key provided, this should have been caught by check_env_vars", +// ); +// ctx.head() +// .headers() +// .get(ADMIN_KEY_HEADER) +// .map_or(false, |it| it.as_bytes() == admin_key.as_bytes()) +// } diff --git a/apps/labrinth/src/util/ratelimit.rs b/apps/labrinth/src/util/ratelimit.rs index f20fb51f3..cf581d0e3 100644 --- a/apps/labrinth/src/util/ratelimit.rs +++ b/apps/labrinth/src/util/ratelimit.rs @@ -5,13 +5,9 @@ use std::sync::Arc; use crate::routes::ApiError; use crate::util::env::parse_var; -use actix_web::{ - body::EitherBody, - dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, - Error, ResponseError, -}; -use futures_util::future::LocalBoxFuture; -use futures_util::future::{ready, Ready}; +use ntex::service::{Middleware, Service, ServiceCtx}; +use ntex::web; +use ntex::web::{WebResponse, WebResponseError}; pub type KeyedRateLimiter< K = String, @@ -22,23 +18,14 @@ pub type KeyedRateLimiter< pub struct RateLimit(pub KeyedRateLimiter); -impl Transform for RateLimit -where - S: Service, Error = Error>, - S::Future: 'static, - B: 'static, -{ - type Response = ServiceResponse>; - type Error = Error; - type Transform = RateLimitService; - type InitError = (); - type Future = Ready>; - - fn new_transform(&self, service: S) -> Self::Future { - ready(Ok(RateLimitService { +impl Middleware for RateLimit { + type Service = RateLimitService; + + fn create(&self, service: S) -> Self::Service { + RateLimitService { service, rate_limiter: Arc::clone(&self.0), - })) + } } } @@ -48,41 +35,42 @@ pub struct RateLimitService { rate_limiter: KeyedRateLimiter, } -impl Service for RateLimitService +impl Service> for RateLimitService where - S: Service, Error = Error>, - S::Future: 'static, - B: 'static, + S: Service< + web::WebRequest, + Response = web::WebResponse, + Error = web::Error, + >, + Err: web::ErrorRenderer, { - type Response = ServiceResponse>; - type Error = Error; - type Future = LocalBoxFuture<'static, Result>; + type Response = web::WebResponse; + type Error = web::Error; - forward_ready!(service); + ntex::forward_ready!(service); - fn call(&self, req: ServiceRequest) -> Self::Future { + async fn call( + &self, + req: web::WebRequest, + ctx: ServiceCtx<'_, Self>, + ) -> Result { if let Some(key) = req.headers().get("x-ratelimit-key") { if key.to_str().ok() == dotenvy::var("RATE_LIMIT_IGNORE_KEY").ok().as_deref() { - let res = self.service.call(req); - - return Box::pin(async move { - let service_response = res.await?; - Ok(service_response.map_into_left_body()) - }); + let res = ctx.call(&self.service, req).await?; + return Ok(res); } } - let conn_info = req.connection_info().clone(); let ip = if parse_var("CLOUDFLARE_INTEGRATION").unwrap_or(false) { if let Some(header) = req.headers().get("CF-Connecting-IP") { - header.to_str().ok() + header.to_str().ok().map(|x| x.to_string()) } else { - conn_info.peer_addr() + req.peer_addr().map(|x| x.to_string()) } } else { - conn_info.peer_addr() + req.peer_addr().map(|x| x.to_string()) }; if let Some(ip) = ip { @@ -90,98 +78,85 @@ where match self.rate_limiter.check_key(&ip) { Ok(snapshot) => { - let fut = self.service.call(req); - - Box::pin(async move { - match fut.await { - Ok(mut service_response) => { - // Now you have a mutable reference to the ServiceResponse, so you can modify its headers. - let headers = service_response.headers_mut(); - headers.insert( - actix_web::http::header::HeaderName::from_str( - "x-ratelimit-limit", - ) - .unwrap(), - snapshot.quota().burst_size().get().into(), - ); - headers.insert( - actix_web::http::header::HeaderName::from_str( - "x-ratelimit-remaining", - ) - .unwrap(), - snapshot.remaining_burst_capacity().into(), - ); - - headers.insert( - actix_web::http::header::HeaderName::from_str( - "x-ratelimit-reset", - ) - .unwrap(), - snapshot - .quota() - .burst_size_replenished_in() - .as_secs() - .into(), - ); - - // Return the modified response as Ok. - Ok(service_response.map_into_left_body()) - } - Err(e) => { - // Handle error case - Err(e) - } - } - }) + let mut service_response = + ctx.call(&self.service, req).await?; + + let headers = service_response.headers_mut(); + headers.insert( + ntex::http::header::HeaderName::from_str( + "x-ratelimit-limit", + ) + .unwrap(), + snapshot.quota().burst_size().get().into(), + ); + headers.insert( + ntex::http::header::HeaderName::from_str( + "x-ratelimit-remaining", + ) + .unwrap(), + snapshot.remaining_burst_capacity().into(), + ); + + headers.insert( + ntex::http::header::HeaderName::from_str( + "x-ratelimit-reset", + ) + .unwrap(), + snapshot + .quota() + .burst_size_replenished_in() + .as_secs() + .into(), + ); + + Ok(service_response) } Err(negative) => { let wait_time = negative.wait_time_from(DefaultClock::default().now()); + let (req, _) = req.into_parts(); let mut response = ApiError::RateLimitError( wait_time.as_millis(), negative.quota().burst_size().get(), ) - .error_response(); + .error_response(&req); let headers = response.headers_mut(); headers.insert( - actix_web::http::header::HeaderName::from_str( + ntex::http::header::HeaderName::from_str( "x-ratelimit-limit", ) .unwrap(), negative.quota().burst_size().get().into(), ); headers.insert( - actix_web::http::header::HeaderName::from_str( + ntex::http::header::HeaderName::from_str( "x-ratelimit-remaining", ) .unwrap(), 0.into(), ); headers.insert( - actix_web::http::header::HeaderName::from_str( + ntex::http::header::HeaderName::from_str( "x-ratelimit-reset", ) .unwrap(), wait_time.as_secs().into(), ); - Box::pin(async { - Ok(req.into_response(response.map_into_right_body())) - }) + Ok(WebResponse::new(response, req)) } } } else { + let (req, _) = req.into_parts(); let response = ApiError::CustomAuthentication( "Unable to obtain user IP address!".to_string(), ) - .error_response(); + .error_response(&req); - Box::pin(async { - Ok(req.into_response(response.map_into_right_body())) - }) + Ok(WebResponse::new(response, req)) } } } diff --git a/apps/labrinth/src/util/routes.rs b/apps/labrinth/src/util/routes.rs index f12e07d97..e78d682e5 100644 --- a/apps/labrinth/src/util/routes.rs +++ b/apps/labrinth/src/util/routes.rs @@ -1,9 +1,9 @@ -use crate::routes::v3::project_creation::CreateError; +// use crate::routes::v3::project_creation::CreateError; use crate::routes::ApiError; -use actix_multipart::Field; -use actix_web::web::Payload; use bytes::BytesMut; use futures::StreamExt; +use ntex::web::types::Payload; +use ntex_multipart::Field; pub async fn read_from_payload( payload: &mut Payload, @@ -25,18 +25,19 @@ pub async fn read_from_payload( Ok(bytes) } -pub async fn read_from_field( - field: &mut Field, - cap: usize, - err_msg: &'static str, -) -> Result { - let mut bytes = BytesMut::new(); - while let Some(chunk) = field.next().await { - if bytes.len() >= cap { - return Err(CreateError::InvalidInput(String::from(err_msg))); - } else { - bytes.extend_from_slice(&chunk?); - } - } - Ok(bytes) -} +// TODO: fix me +// pub async fn read_from_field( +// field: &mut Field, +// cap: usize, +// err_msg: &'static str, +// ) -> Result { +// let mut bytes = BytesMut::new(); +// while let Some(chunk) = field.next().await { +// if bytes.len() >= cap { +// return Err(CreateError::InvalidInput(String::from(err_msg))); +// } else { +// bytes.extend_from_slice(&chunk?); +// } +// } +// Ok(bytes) +// } diff --git a/apps/labrinth/src/validate/mod.rs b/apps/labrinth/src/validate/mod.rs index 7f699e940..ee85306ee 100644 --- a/apps/labrinth/src/validate/mod.rs +++ b/apps/labrinth/src/validate/mod.rs @@ -45,7 +45,7 @@ pub enum ValidationError { #[error("Invalid Input: {0}")] InvalidInput(std::borrow::Cow<'static, str>), #[error("Error while managing threads")] - Blocking(#[from] actix_web::error::BlockingError), + Blocking, #[error("Error while querying database")] Database(#[from] DatabaseError), } @@ -152,7 +152,7 @@ async fn validate_minecraft_file( all_game_versions: Vec, file_type: Option, ) -> Result { - actix_web::web::block(move || { + ntex::web::block(move || { let reader = Cursor::new(data); let mut zip = ZipArchive::new(reader)?; @@ -216,7 +216,7 @@ async fn validate_minecraft_file( Ok(ValidationResult::Pass) } }) - .await? + .await.map_err(|_| ValidationError::Blocking) } // Write tests for this diff --git a/apps/labrinth/tests/analytics.rs b/apps/labrinth/tests/analytics.rs index 96e2a440a..53020357e 100644 --- a/apps/labrinth/tests/analytics.rs +++ b/apps/labrinth/tests/analytics.rs @@ -14,7 +14,7 @@ use rust_decimal::{prelude::ToPrimitive, Decimal}; mod common; -#[actix_rt::test] +#[ntex::test] pub async fn analytics_revenue() { with_test_environment( None, @@ -153,7 +153,7 @@ fn to_f64_vec_rounded_up(d: Vec) -> Vec { d.into_iter().map(to_f64_rounded_up).collect_vec() } -#[actix_rt::test] +#[ntex::test] pub async fn permissions_analytics_revenue() { with_test_environment( None, diff --git a/apps/labrinth/tests/common/api_common/mod.rs b/apps/labrinth/tests/common/api_common/mod.rs index aca326b37..20e42cc69 100644 --- a/apps/labrinth/tests/common/api_common/mod.rs +++ b/apps/labrinth/tests/common/api_common/mod.rs @@ -479,8 +479,8 @@ pub trait ApiVersion { pub trait AppendsOptionalPat { fn append_pat(self, pat: Option<&str>) -> Self; } -// Impl this on all actix_web::test::TestRequest -impl AppendsOptionalPat for actix_web::test::TestRequest { +// Impl this on all ntex::web::test::TestRequest +impl AppendsOptionalPat for ntex::web::test::TestRequest { fn append_pat(self, pat: Option<&str>) -> Self { if let Some(pat) = pat { self.append_header(("Authorization", pat)) diff --git a/apps/labrinth/tests/common/api_v2/mod.rs b/apps/labrinth/tests/common/api_v2/mod.rs index a3d52ba01..9010f8e7a 100644 --- a/apps/labrinth/tests/common/api_v2/mod.rs +++ b/apps/labrinth/tests/common/api_v2/mod.rs @@ -41,7 +41,7 @@ impl Api for ApiV2 { } async fn reset_search_index(&self) -> ServiceResponse { - let req = actix_web::test::TestRequest::post() + let req = ntex::web::test::TestRequest::post() .uri("/v2/admin/_force_reindex") .append_header(( "Modrinth-Admin", diff --git a/apps/labrinth/tests/common/api_v3/mod.rs b/apps/labrinth/tests/common/api_v3/mod.rs index f4a0d889a..058bebaf5 100644 --- a/apps/labrinth/tests/common/api_v3/mod.rs +++ b/apps/labrinth/tests/common/api_v3/mod.rs @@ -45,7 +45,7 @@ impl Api for ApiV3 { } async fn reset_search_index(&self) -> ServiceResponse { - let req = actix_web::test::TestRequest::post() + let req = ntex::web::test::TestRequest::post() .uri("/_internal/admin/_force_reindex") .append_header(( "Modrinth-Admin", diff --git a/apps/labrinth/tests/common/api_v3/oauth.rs b/apps/labrinth/tests/common/api_v3/oauth.rs index acd5e1732..35833ec03 100644 --- a/apps/labrinth/tests/common/api_v3/oauth.rs +++ b/apps/labrinth/tests/common/api_v3/oauth.rs @@ -154,7 +154,7 @@ pub async fn get_access_token(response: ServiceResponse) -> String { pub fn get_redirect_location_query_params( response: &ServiceResponse, -) -> actix_web::web::Query> { +) -> actix_web::web::types::Query> { let redirect_location = response .headers() .get(LOCATION) diff --git a/apps/labrinth/tests/common/dummy_data.rs b/apps/labrinth/tests/common/dummy_data.rs index 5dbe21a01..2a1107435 100644 --- a/apps/labrinth/tests/common/dummy_data.rs +++ b/apps/labrinth/tests/common/dummy_data.rs @@ -2,13 +2,13 @@ use std::io::{Cursor, Write}; use actix_http::StatusCode; -use actix_web::test::{self, TestRequest}; use labrinth::models::{ oauth_clients::OAuthClient, organizations::Organization, pats::Scopes, projects::{Project, ProjectId, Version}, }; +use ntex::web::test::{self, TestRequest}; use serde_json::json; use sqlx::Executor; use zip::{write::FileOptions, CompressionMethod, ZipWriter}; diff --git a/apps/labrinth/tests/common/environment.rs b/apps/labrinth/tests/common/environment.rs index 7747916ac..9888b3160 100644 --- a/apps/labrinth/tests/common/environment.rs +++ b/apps/labrinth/tests/common/environment.rs @@ -61,7 +61,7 @@ pub async fn with_test_environment_all( } // A complete test environment, with a test actix app and a database. -// Must be called in an #[actix_rt::test] context. It also simulates a +// Must be called in an #[ntex::test] context. It also simulates a // temporary sqlx db like #[sqlx::test] would. // Use .call(req) on it directly to make a test call as if test::call_service(req) were being used. #[derive(Clone)] diff --git a/apps/labrinth/tests/error.rs b/apps/labrinth/tests/error.rs index b92e774c1..e7e35359b 100644 --- a/apps/labrinth/tests/error.rs +++ b/apps/labrinth/tests/error.rs @@ -1,7 +1,7 @@ use actix_http::StatusCode; -use actix_web::test; use bytes::Bytes; use common::api_common::ApiProject; +use ntex::web::test; use common::api_v3::ApiV3; use common::database::USER_USER_PAT; @@ -9,7 +9,7 @@ use common::environment::{with_test_environment, TestEnvironment}; mod common; -#[actix_rt::test] +#[ntex::test] pub async fn error_404_body() { with_test_environment( None, diff --git a/apps/labrinth/tests/games.rs b/apps/labrinth/tests/games.rs index c078f9946..23b47d212 100644 --- a/apps/labrinth/tests/games.rs +++ b/apps/labrinth/tests/games.rs @@ -7,7 +7,7 @@ use common::{ mod common; -#[actix_rt::test] +#[ntex::test] async fn get_games() { with_test_environment( None, diff --git a/apps/labrinth/tests/loader_fields.rs b/apps/labrinth/tests/loader_fields.rs index 78ee67a40..0590625e2 100644 --- a/apps/labrinth/tests/loader_fields.rs +++ b/apps/labrinth/tests/loader_fields.rs @@ -1,12 +1,12 @@ use std::collections::HashSet; use actix_http::StatusCode; -use actix_web::test; use common::api_v3::ApiV3; use common::environment::{with_test_environment, TestEnvironment}; use itertools::Itertools; use labrinth::database::models::legacy_loader_fields::MinecraftGameVersion; use labrinth::models::v3; +use ntex::web::test; use serde_json::json; use crate::common::api_common::{ApiProject, ApiVersion}; @@ -20,7 +20,7 @@ use crate::common::dummy_data::{ // importing common module. mod common; -#[actix_rt::test] +#[ntex::test] async fn creating_loader_fields() { with_test_environment(None, |test_env: TestEnvironment| async move { @@ -378,7 +378,7 @@ async fn creating_loader_fields() { .await } -#[actix_rt::test] +#[ntex::test] async fn get_loader_fields_variants() { with_test_environment(None, |test_env: TestEnvironment| async move { let api = &test_env.api; @@ -414,7 +414,7 @@ async fn get_loader_fields_variants() { .await } -#[actix_rt::test] +#[ntex::test] async fn get_available_loader_fields() { // Get available loader fields for a given loader // (ie: which fields are relevant for 'fabric', etc) @@ -475,7 +475,7 @@ async fn get_available_loader_fields() { .await; } -#[actix_rt::test] +#[ntex::test] async fn test_multi_get_redis_cache() { // Ensures a multi-project get including both modpacks and mods ddoes not // incorrectly cache loader fields @@ -576,7 +576,7 @@ async fn test_multi_get_redis_cache() { .await; } -#[actix_rt::test] +#[ntex::test] async fn minecraft_game_version_update() { // We simulate adding a Minecraft game version, to ensure other data doesn't get overwritten // This is basically a test for the insertion/concatenation query diff --git a/apps/labrinth/tests/notifications.rs b/apps/labrinth/tests/notifications.rs index d63fc819a..740bab3dc 100644 --- a/apps/labrinth/tests/notifications.rs +++ b/apps/labrinth/tests/notifications.rs @@ -7,7 +7,7 @@ use crate::common::api_common::ApiTeams; mod common; -#[actix_rt::test] +#[ntex::test] pub async fn get_user_notifications_after_team_invitation_returns_notification() { with_test_environment_all(None, |test_env| async move { @@ -39,7 +39,7 @@ pub async fn get_user_notifications_after_team_invitation_returns_notification() .await; } -#[actix_rt::test] +#[ntex::test] pub async fn get_user_notifications_after_reading_indicates_notification_read() { with_test_environment_all(None, |test_env| async move { @@ -69,7 +69,7 @@ pub async fn get_user_notifications_after_reading_indicates_notification_read() .await; } -#[actix_rt::test] +#[ntex::test] pub async fn get_user_notifications_after_deleting_does_not_show_notification() { with_test_environment_all(None, |test_env| async move { diff --git a/apps/labrinth/tests/oauth.rs b/apps/labrinth/tests/oauth.rs index 4ff3fc5c6..dca3c106b 100644 --- a/apps/labrinth/tests/oauth.rs +++ b/apps/labrinth/tests/oauth.rs @@ -1,5 +1,4 @@ use actix_http::StatusCode; -use actix_web::test; use common::{ api_v3::oauth::get_redirect_location_query_params, api_v3::{ @@ -14,11 +13,12 @@ use common::{ environment::{with_test_environment, TestEnvironment}, }; use labrinth::auth::oauth::TokenResponse; +use ntex::web::test; use reqwest::header::{CACHE_CONTROL, PRAGMA}; mod common; -#[actix_rt::test] +#[ntex::test] async fn oauth_flow_happy_path() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { @@ -80,7 +80,7 @@ async fn oauth_flow_happy_path() { .await; } -#[actix_rt::test] +#[ntex::test] async fn oauth_authorize_for_already_authorized_scopes_returns_auth_code() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { client_id, .. } = @@ -114,7 +114,7 @@ async fn oauth_authorize_for_already_authorized_scopes_returns_auth_code() { .await; } -#[actix_rt::test] +#[ntex::test] async fn get_oauth_token_with_already_used_auth_code_fails() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { @@ -152,7 +152,7 @@ async fn get_oauth_token_with_already_used_auth_code_fails() { .await; } -#[actix_rt::test] +#[ntex::test] async fn authorize_with_broader_scopes_can_complete_flow() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { @@ -213,7 +213,7 @@ async fn authorize_with_broader_scopes_can_complete_flow() { .await; } -#[actix_rt::test] +#[ntex::test] async fn oauth_authorize_with_broader_scopes_requires_user_accept() { with_test_environment(None, |env: TestEnvironment| async move { let client_id = env.dummy.oauth_client_alpha.client_id; @@ -247,7 +247,7 @@ async fn oauth_authorize_with_broader_scopes_requires_user_accept() { .await; } -#[actix_rt::test] +#[ntex::test] async fn reject_authorize_ends_authorize_flow() { with_test_environment(None, |env: TestEnvironment| async move { let client_id = env.dummy.oauth_client_alpha.client_id; @@ -266,7 +266,7 @@ async fn reject_authorize_ends_authorize_flow() { .await; } -#[actix_rt::test] +#[ntex::test] async fn accept_authorize_after_already_accepting_fails() { with_test_environment(None, |env: TestEnvironment| async move { let client_id = env.dummy.oauth_client_alpha.client_id; @@ -284,7 +284,7 @@ async fn accept_authorize_after_already_accepting_fails() { .await; } -#[actix_rt::test] +#[ntex::test] async fn revoke_authorization_after_issuing_token_revokes_token() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { diff --git a/apps/labrinth/tests/oauth_clients.rs b/apps/labrinth/tests/oauth_clients.rs index 335dbca44..5833bcff8 100644 --- a/apps/labrinth/tests/oauth_clients.rs +++ b/apps/labrinth/tests/oauth_clients.rs @@ -1,5 +1,4 @@ use actix_http::StatusCode; -use actix_web::test; use common::{ api_v3::ApiV3, database::{FRIEND_USER_ID, FRIEND_USER_PAT, USER_USER_ID, USER_USER_PAT}, @@ -14,12 +13,13 @@ use labrinth::{ }, routes::v3::oauth_clients::OAuthClientEdit, }; +use ntex::web::test; use common::database::USER_USER_ID_PARSED; mod common; -#[actix_rt::test] +#[ntex::test] async fn can_create_edit_get_oauth_client() { with_test_environment(None, |env: TestEnvironment| async move { let client_name = "test_client".to_string(); @@ -75,7 +75,7 @@ async fn can_create_edit_get_oauth_client() { .await; } -#[actix_rt::test] +#[ntex::test] async fn create_oauth_client_with_restricted_scopes_fails() { with_test_environment(None, |env: TestEnvironment| async move { let resp = env @@ -93,7 +93,7 @@ async fn create_oauth_client_with_restricted_scopes_fails() { .await; } -#[actix_rt::test] +#[ntex::test] async fn get_oauth_client_for_client_creator_succeeds() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { client_id, .. } = @@ -111,7 +111,7 @@ async fn get_oauth_client_for_client_creator_succeeds() { .await; } -#[actix_rt::test] +#[ntex::test] async fn can_delete_oauth_client() { with_test_environment(None, |env: TestEnvironment| async move { let client_id = env.dummy.oauth_client_alpha.client_id.clone(); @@ -127,7 +127,7 @@ async fn can_delete_oauth_client() { .await; } -#[actix_rt::test] +#[ntex::test] async fn delete_oauth_client_after_issuing_access_tokens_revokes_tokens() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { @@ -159,7 +159,7 @@ async fn delete_oauth_client_after_issuing_access_tokens_revokes_tokens() { .await; } -#[actix_rt::test] +#[ntex::test] async fn can_list_user_oauth_authorizations() { with_test_environment(None, |env: TestEnvironment| async move { let DummyOAuthClientAlpha { diff --git a/apps/labrinth/tests/organizations.rs b/apps/labrinth/tests/organizations.rs index 1a570b358..76e29aab0 100644 --- a/apps/labrinth/tests/organizations.rs +++ b/apps/labrinth/tests/organizations.rs @@ -26,7 +26,7 @@ use serde_json::json; mod common; -#[actix_rt::test] +#[ntex::test] async fn create_organization() { with_test_environment( None, @@ -125,7 +125,7 @@ async fn create_organization() { .await; } -#[actix_rt::test] +#[ntex::test] async fn get_project_organization() { with_test_environment( None, @@ -158,7 +158,7 @@ async fn get_project_organization() { .await; } -#[actix_rt::test] +#[ntex::test] async fn patch_organization() { with_test_environment( None, @@ -262,7 +262,7 @@ async fn patch_organization() { } // add/remove icon -#[actix_rt::test] +#[ntex::test] async fn add_remove_icon() { with_test_environment( Some(10), @@ -326,7 +326,7 @@ async fn add_remove_icon() { } // delete org -#[actix_rt::test] +#[ntex::test] async fn delete_org() { with_test_environment( None, @@ -351,7 +351,7 @@ async fn delete_org() { } // add/remove organization projects -#[actix_rt::test] +#[ntex::test] async fn add_remove_organization_projects() { with_test_environment( None, @@ -457,7 +457,7 @@ async fn add_remove_organization_projects() { } // Like above, but specifically regarding ownership transferring -#[actix_rt::test] +#[ntex::test] async fn add_remove_organization_project_ownership_to_user() { with_test_environment( None, @@ -731,7 +731,7 @@ async fn add_remove_organization_project_ownership_to_user() { .await; } -#[actix_rt::test] +#[ntex::test] async fn delete_organization_means_all_projects_to_org_owner() { with_test_environment( None, @@ -910,7 +910,7 @@ async fn delete_organization_means_all_projects_to_org_owner() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_patch_organization() { with_test_environment( None, @@ -952,7 +952,7 @@ async fn permissions_patch_organization() { } // Not covered by PATCH /organization -#[actix_rt::test] +#[ntex::test] async fn permissions_edit_details() { with_test_environment( Some(12), @@ -1002,7 +1002,7 @@ async fn permissions_edit_details() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_manage_invites() { // Add member, remove member, edit member with_test_environment_all(None, |test_env| async move { @@ -1104,7 +1104,7 @@ async fn permissions_manage_invites() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_add_remove_project() { with_test_environment( None, @@ -1181,7 +1181,7 @@ async fn permissions_add_remove_project() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_delete_organization() { with_test_environment( None, @@ -1211,7 +1211,7 @@ async fn permissions_delete_organization() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_add_default_project_permissions() { with_test_environment_all(None, |test_env| async move { let zeta_organization_id = @@ -1291,7 +1291,7 @@ async fn permissions_add_default_project_permissions() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_organization_permissions_consistency_test() { with_test_environment( None, diff --git a/apps/labrinth/tests/pats.rs b/apps/labrinth/tests/pats.rs index 07b130f9e..1c32e8536 100644 --- a/apps/labrinth/tests/pats.rs +++ b/apps/labrinth/tests/pats.rs @@ -1,7 +1,7 @@ use actix_http::StatusCode; -use actix_web::test; use chrono::{Duration, Utc}; use common::{database::*, environment::with_test_environment_all}; +use ntex::web::test; use labrinth::models::pats::Scopes; use serde_json::json; @@ -17,7 +17,7 @@ mod common; // - ensure PAT can be patched to change expiry // - ensure expired PATs cannot be used // - ensure PATs can be deleted -#[actix_rt::test] +#[ntex::test] pub async fn pat_full_test() { with_test_environment_all(None, |test_env| async move { // Create a PAT for a full test @@ -165,7 +165,7 @@ pub async fn pat_full_test() { } // Test illegal PAT setting, both in POST and PATCH -#[actix_rt::test] +#[ntex::test] pub async fn bad_pats() { with_test_environment_all(None, |test_env| async move { // Creating a PAT with no name should fail diff --git a/apps/labrinth/tests/project.rs b/apps/labrinth/tests/project.rs index 11c63abbc..8a98a4b8c 100644 --- a/apps/labrinth/tests/project.rs +++ b/apps/labrinth/tests/project.rs @@ -1,8 +1,8 @@ use actix_http::StatusCode; -use actix_web::test; use common::api_v3::ApiV3; use common::database::*; use common::dummy_data::DUMMY_CATEGORIES; +use ntex::web::test; use common::environment::{ with_test_environment, with_test_environment_all, TestEnvironment, @@ -27,7 +27,7 @@ use crate::common::dummy_data::{ }; mod common; -#[actix_rt::test] +#[ntex::test] async fn test_get_project() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -99,7 +99,7 @@ async fn test_get_project() { .await; } -#[actix_rt::test] +#[ntex::test] async fn test_add_remove_project() { // Test setup and dummy data with_test_environment( @@ -303,7 +303,7 @@ async fn test_add_remove_project() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_patch_project() { with_test_environment( None, @@ -489,7 +489,7 @@ pub async fn test_patch_project() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_patch_v3() { // Hits V3-specific patchable fields with_test_environment( @@ -525,7 +525,7 @@ pub async fn test_patch_v3() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_bulk_edit_categories() { with_test_environment_all(None, |test_env| async move { let api = &test_env.api; @@ -566,7 +566,7 @@ pub async fn test_bulk_edit_categories() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_bulk_edit_links() { with_test_environment( None, @@ -627,7 +627,7 @@ pub async fn test_bulk_edit_links() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_patch_project_v3() { with_test_environment(Some(8), |test_env: TestEnvironment| async move { let alpha_project_id = &test_env.dummy.project_alpha.project_id; @@ -746,7 +746,7 @@ async fn permissions_patch_project_v3() { } // TODO: Project scheduling has been temporarily disabled, so this test is disabled as well -// #[actix_rt::test] +// #[ntex::test] // async fn permissions_schedule() { // with_test_environment(None, |test_env : TestEnvironment| async move { // let DummyProjectAlpha { @@ -796,7 +796,7 @@ async fn permissions_patch_project_v3() { // } // Not covered by PATCH /project -#[actix_rt::test] +#[ntex::test] async fn permissions_edit_details() { with_test_environment_all(Some(10), |test_env| async move { let DummyProjectAlpha { @@ -907,7 +907,7 @@ async fn permissions_edit_details() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_upload_version() { with_test_environment( None, @@ -1010,7 +1010,7 @@ async fn permissions_upload_version() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_manage_invites() { // Add member, remove member, edit member with_test_environment_all(None, |test_env| async move { @@ -1112,7 +1112,7 @@ async fn permissions_manage_invites() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_delete_project() { // Add member, remove member, edit member with_test_environment_all(None, |test_env| async move { @@ -1136,7 +1136,7 @@ async fn permissions_delete_project() { .await; } -#[actix_rt::test] +#[ntex::test] async fn project_permissions_consistency_test() { with_test_environment_all(Some(10), |test_env| async move { // Test that the permissions are consistent with each other @@ -1183,7 +1183,7 @@ async fn project_permissions_consistency_test() { } // TODO: Re-add this if we want to match v3 Projects structure to v3 Search Result structure, otherwise, delete -// #[actix_rt::test] +// #[ntex::test] // async fn align_search_projects() { // // Test setup and dummy data // with_test_environment(Some(10), |test_env: TestEnvironment| async move { @@ -1219,7 +1219,7 @@ async fn project_permissions_consistency_test() { // .await // } -#[actix_rt::test] +#[ntex::test] async fn projects_various_visibility() { // For testing the filter_visible_projects and is_visible_project with_test_environment( diff --git a/apps/labrinth/tests/scopes.rs b/apps/labrinth/tests/scopes.rs index 1d19d2b4f..0835576a1 100644 --- a/apps/labrinth/tests/scopes.rs +++ b/apps/labrinth/tests/scopes.rs @@ -7,7 +7,6 @@ use crate::common::dummy_data::{ DummyImage, DummyProjectAlpha, DummyProjectBeta, }; use actix_http::StatusCode; -use actix_web::test; use chrono::{Duration, Utc}; use common::api_common::models::CommonItemType; use common::api_common::Api; @@ -22,6 +21,7 @@ use labrinth::models::ids::base62_impl::parse_base62; use labrinth::models::pats::Scopes; use labrinth::models::projects::ProjectId; use labrinth::models::users::UserId; +use ntex::web::test; use serde_json::json; // For each scope, we (using test_scope): @@ -33,7 +33,7 @@ use serde_json::json; mod common; // Test for users, emails, and payout scopes (not user auth scope or notifs) -#[actix_rt::test] +#[ntex::test] async fn user_scopes() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -113,7 +113,7 @@ async fn user_scopes() { } // Notifications -#[actix_rt::test] +#[ntex::test] pub async fn notifications_scopes() { with_test_environment_all(None, |test_env| async move { let api = &test_env.api; @@ -237,7 +237,7 @@ pub async fn notifications_scopes() { } // Project version creation scopes -#[actix_rt::test] +#[ntex::test] pub async fn project_version_create_scopes_v3() { with_test_environment( None, @@ -284,7 +284,7 @@ pub async fn project_version_create_scopes_v3() { } // Project management scopes -#[actix_rt::test] +#[ntex::test] pub async fn project_version_reads_scopes() { with_test_environment_all(None, |test_env| async move { let api = &test_env.api; @@ -511,7 +511,7 @@ pub async fn project_version_reads_scopes() { } // Project writing -#[actix_rt::test] +#[ntex::test] pub async fn project_write_scopes() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -689,7 +689,7 @@ pub async fn project_write_scopes() { } // Version write -#[actix_rt::test] +#[ntex::test] pub async fn version_write_scopes() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -759,7 +759,7 @@ pub async fn version_write_scopes() { } // Report scopes -#[actix_rt::test] +#[ntex::test] pub async fn report_scopes() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -841,7 +841,7 @@ pub async fn report_scopes() { } // Thread scopes -#[actix_rt::test] +#[ntex::test] pub async fn thread_scopes() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -889,7 +889,7 @@ pub async fn thread_scopes() { } // Pat scopes -#[actix_rt::test] +#[ntex::test] pub async fn pat_scopes() { with_test_environment_all(None, |test_env| async move { let api = &test_env.api; @@ -960,7 +960,7 @@ pub async fn pat_scopes() { } // Collection scopes -#[actix_rt::test] +#[ntex::test] pub async fn collections_scopes() { // Test setup and dummy data with_test_environment( @@ -1065,7 +1065,7 @@ pub async fn collections_scopes() { } // Organization scopes (and a couple PROJECT_WRITE scopes that are only allowed for orgs) -#[actix_rt::test] +#[ntex::test] pub async fn organization_scopes() { // Test setup and dummy data with_test_environment( diff --git a/apps/labrinth/tests/search.rs b/apps/labrinth/tests/search.rs index d0c5fb14c..f27030ccf 100644 --- a/apps/labrinth/tests/search.rs +++ b/apps/labrinth/tests/search.rs @@ -19,7 +19,7 @@ mod common; // TODO: Revisit this wit h the new modify_json in the version maker // That change here should be able to simplify it vastly -#[actix_rt::test] +#[ntex::test] async fn search_projects() { // Test setup and dummy data with_test_environment( @@ -125,7 +125,7 @@ async fn search_projects() { .await; } -#[actix_rt::test] +#[ntex::test] async fn index_swaps() { with_test_environment( Some(10), diff --git a/apps/labrinth/tests/tags.rs b/apps/labrinth/tests/tags.rs index 264c7e29e..f65e07ea1 100644 --- a/apps/labrinth/tests/tags.rs +++ b/apps/labrinth/tests/tags.rs @@ -11,7 +11,7 @@ use crate::common::api_common::ApiTags; mod common; -#[actix_rt::test] +#[ntex::test] async fn get_tags() { with_test_environment_all(None, |test_env| async move { let api = &test_env.api; @@ -40,7 +40,7 @@ async fn get_tags() { .await; } -#[actix_rt::test] +#[ntex::test] async fn get_tags_v3() { with_test_environment( None, diff --git a/apps/labrinth/tests/teams.rs b/apps/labrinth/tests/teams.rs index 4743ecf4c..17e876277 100644 --- a/apps/labrinth/tests/teams.rs +++ b/apps/labrinth/tests/teams.rs @@ -12,7 +12,7 @@ use serde_json::json; mod common; -#[actix_rt::test] +#[ntex::test] async fn test_get_team() { // Test setup and dummy data // Perform get_team related tests for a project team @@ -163,7 +163,7 @@ async fn test_get_team() { .await; } -#[actix_rt::test] +#[ntex::test] async fn test_get_team_organization() { // Test setup and dummy data // Perform get_team related tests for an organization team @@ -322,7 +322,7 @@ async fn test_get_team_organization() { .await; } -#[actix_rt::test] +#[ntex::test] async fn test_get_team_project_orgs() { // Test setup and dummy data with_test_environment( @@ -390,7 +390,7 @@ async fn test_get_team_project_orgs() { } // edit team member (Varying permissions, varying roles) -#[actix_rt::test] +#[ntex::test] async fn test_patch_project_team_member() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -461,7 +461,7 @@ async fn test_patch_project_team_member() { } // edit team member (Varying permissions, varying roles) -#[actix_rt::test] +#[ntex::test] async fn test_patch_organization_team_member() { // Test setup and dummy data with_test_environment(None, |test_env: TestEnvironment| async move { @@ -554,7 +554,7 @@ async fn test_patch_organization_team_member() { } // trasnfer ownership (requires being owner, etc) -#[actix_rt::test] +#[ntex::test] async fn transfer_ownership_v3() { // Test setup and dummy data with_test_environment( @@ -688,7 +688,7 @@ async fn transfer_ownership_v3() { } // This test is currently not working. -// #[actix_rt::test] +// #[ntex::test] // pub async fn no_acceptance_permissions() { // // Adding a user to a project team in an organization, when that user is in the organization but not the team, // // should have those permissions apply regardless of whether the user has accepted the invite or not. diff --git a/apps/labrinth/tests/user.rs b/apps/labrinth/tests/user.rs index b1b7bfd01..296fd7071 100644 --- a/apps/labrinth/tests/user.rs +++ b/apps/labrinth/tests/user.rs @@ -16,7 +16,7 @@ mod common; // patch user icon // user follows -#[actix_rt::test] +#[ntex::test] pub async fn get_user_projects_after_creating_project_returns_new_project() { with_test_environment_all(None, |test_env| async move { let api = test_env.api; @@ -40,7 +40,7 @@ pub async fn get_user_projects_after_creating_project_returns_new_project() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn get_user_projects_after_deleting_project_shows_removal() { with_test_environment_all(None, |test_env| async move { let api = test_env.api; @@ -66,7 +66,7 @@ pub async fn get_user_projects_after_deleting_project_shows_removal() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn get_user_projects_after_joining_team_shows_team_projects() { with_test_environment_all(None, |test_env| async move { let alpha_team_id = &test_env.dummy.project_alpha.team_id; @@ -101,7 +101,7 @@ pub async fn get_user_projects_after_joining_team_shows_team_projects() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn get_user_projects_after_leaving_team_shows_no_team_projects() { with_test_environment_all(None, |test_env| async move { let alpha_team_id = &test_env.dummy.project_alpha.team_id; diff --git a/apps/labrinth/tests/v2/error.rs b/apps/labrinth/tests/v2/error.rs index 1ae56a719..e7eb930bf 100644 --- a/apps/labrinth/tests/v2/error.rs +++ b/apps/labrinth/tests/v2/error.rs @@ -2,15 +2,15 @@ use crate::assert_status; use crate::common::api_common::ApiProject; use actix_http::StatusCode; -use actix_web::test; use bytes::Bytes; +use ntex::web::test; use crate::common::database::USER_USER_PAT; use crate::common::{ api_v2::ApiV2, environment::{with_test_environment, TestEnvironment}, }; -#[actix_rt::test] +#[ntex::test] pub async fn error_404_empty() { with_test_environment( None, diff --git a/apps/labrinth/tests/v2/notifications.rs b/apps/labrinth/tests/v2/notifications.rs index 692ae1388..7e3a6b76a 100644 --- a/apps/labrinth/tests/v2/notifications.rs +++ b/apps/labrinth/tests/v2/notifications.rs @@ -5,7 +5,7 @@ use crate::common::{ environment::{with_test_environment, TestEnvironment}, }; -#[actix_rt::test] +#[ntex::test] pub async fn get_user_notifications_after_team_invitation_returns_notification() { with_test_environment( diff --git a/apps/labrinth/tests/v2/project.rs b/apps/labrinth/tests/v2/project.rs index 5e9006af7..8c60fe6cb 100644 --- a/apps/labrinth/tests/v2/project.rs +++ b/apps/labrinth/tests/v2/project.rs @@ -15,7 +15,6 @@ use crate::{ }, }; use actix_http::StatusCode; -use actix_web::test; use futures::StreamExt; use itertools::Itertools; use labrinth::{ @@ -26,9 +25,10 @@ use labrinth::{ }, util::actix::{AppendsMultipart, MultipartSegment, MultipartSegmentData}, }; +use ntex::web::test; use serde_json::json; -#[actix_rt::test] +#[ntex::test] async fn test_project_type_sanity() { with_test_environment( None, @@ -109,7 +109,7 @@ async fn test_project_type_sanity() { .await; } -#[actix_rt::test] +#[ntex::test] async fn test_add_remove_project() { // Test setup and dummy data with_test_environment( @@ -293,7 +293,7 @@ async fn test_add_remove_project() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_upload_version() { with_test_environment( None, @@ -402,7 +402,7 @@ async fn permissions_upload_version() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_patch_v2() { // Hits V3-specific patchable fields // Other fields are tested in test_patch_project (the v2 version of that test) @@ -441,7 +441,7 @@ pub async fn test_patch_v2() { .await; } -#[actix_rt::test] +#[ntex::test] async fn permissions_patch_project_v2() { with_test_environment( Some(8), @@ -519,7 +519,7 @@ async fn permissions_patch_project_v2() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_bulk_edit_links() { with_test_environment( None, diff --git a/apps/labrinth/tests/v2/scopes.rs b/apps/labrinth/tests/v2/scopes.rs index be53bc20e..11af6e3ba 100644 --- a/apps/labrinth/tests/v2/scopes.rs +++ b/apps/labrinth/tests/v2/scopes.rs @@ -11,7 +11,7 @@ use labrinth::models::pats::Scopes; use labrinth::models::projects::ProjectId; // Project version creation scopes -#[actix_rt::test] +#[ntex::test] pub async fn project_version_create_scopes() { with_test_environment( None, @@ -57,7 +57,7 @@ pub async fn project_version_create_scopes() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn project_version_reads_scopes() { with_test_environment( None, diff --git a/apps/labrinth/tests/v2/search.rs b/apps/labrinth/tests/v2/search.rs index 622bbcab1..7977f383f 100644 --- a/apps/labrinth/tests/v2/search.rs +++ b/apps/labrinth/tests/v2/search.rs @@ -16,7 +16,7 @@ use serde_json::json; use std::collections::HashMap; use std::sync::Arc; -#[actix_rt::test] +#[ntex::test] async fn search_projects() { // Test setup and dummy data with_test_environment(Some(10), |test_env: TestEnvironment| async move { diff --git a/apps/labrinth/tests/v2/tags.rs b/apps/labrinth/tests/v2/tags.rs index 1171e6502..ac5137982 100644 --- a/apps/labrinth/tests/v2/tags.rs +++ b/apps/labrinth/tests/v2/tags.rs @@ -8,7 +8,7 @@ use crate::common::{ environment::{with_test_environment, TestEnvironment}, }; -#[actix_rt::test] +#[ntex::test] async fn get_tags() { with_test_environment( None, @@ -69,7 +69,7 @@ async fn get_tags() { .await; } -#[actix_rt::test] +#[ntex::test] async fn get_donation_platforms() { with_test_environment( None, diff --git a/apps/labrinth/tests/v2/teams.rs b/apps/labrinth/tests/v2/teams.rs index 545b821de..482cb6207 100644 --- a/apps/labrinth/tests/v2/teams.rs +++ b/apps/labrinth/tests/v2/teams.rs @@ -16,7 +16,7 @@ use crate::{ }; // trasnfer ownership (requires being owner, etc) -#[actix_rt::test] +#[ntex::test] async fn transfer_ownership_v2() { // Test setup and dummy data with_test_environment( diff --git a/apps/labrinth/tests/v2/version.rs b/apps/labrinth/tests/v2/version.rs index b4195bef6..64a33aa65 100644 --- a/apps/labrinth/tests/v2/version.rs +++ b/apps/labrinth/tests/v2/version.rs @@ -1,11 +1,11 @@ use actix_http::StatusCode; -use actix_web::test; use futures::StreamExt; use labrinth::models::projects::VersionId; use labrinth::{ models::projects::{Loader, VersionStatus, VersionType}, routes::v2::version_file::FileUpdateData, }; +use ntex::web::test; use serde_json::json; use crate::assert_status; @@ -20,7 +20,7 @@ use crate::common::{ dummy_data::TestFile, }; -#[actix_rt::test] +#[ntex::test] pub async fn test_patch_version() { with_test_environment( None, @@ -141,7 +141,7 @@ pub async fn test_patch_version() { .await; } -#[actix_rt::test] +#[ntex::test] async fn version_updates() { // Test setup and dummy data with_test_environment( @@ -447,7 +447,7 @@ async fn version_updates() { .await; } -#[actix_rt::test] +#[ntex::test] async fn add_version_project_types_v2() { with_test_environment( None, @@ -518,7 +518,7 @@ async fn add_version_project_types_v2() { .await; } -#[actix_rt::test] +#[ntex::test] async fn test_incorrect_file_parts() { // Ensures that a version get that 'should' have mrpack_loaders does still display them // if the file is 'mrpack' but the file_parts are incorrect diff --git a/apps/labrinth/tests/version.rs b/apps/labrinth/tests/version.rs index b085c435d..a6027294e 100644 --- a/apps/labrinth/tests/version.rs +++ b/apps/labrinth/tests/version.rs @@ -7,7 +7,6 @@ use crate::common::dummy_data::{ }; use crate::common::get_json_val_str; use actix_http::StatusCode; -use actix_web::test; use common::api_v3::ApiV3; use common::asserts::assert_common_version_ids; use common::database::USER_USER_PAT; @@ -19,12 +18,13 @@ use labrinth::models::projects::{ Dependency, DependencyType, VersionId, VersionStatus, VersionType, }; use labrinth::routes::v3::version_file::FileUpdateData; +use ntex::web::test; use serde_json::json; // importing common module. mod common; -#[actix_rt::test] +#[ntex::test] async fn test_get_version() { // Test setup and dummy data with_test_environment_all(None, |test_env| async move { @@ -84,7 +84,7 @@ async fn test_get_version() { .await; } -#[actix_rt::test] +#[ntex::test] async fn version_updates() { // Test setup and dummy data with_test_environment( @@ -401,7 +401,7 @@ async fn version_updates() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_patch_version() { with_test_environment_all(None, |test_env| async move { let api = &test_env.api; @@ -528,7 +528,7 @@ pub async fn test_patch_version() { .await; } -#[actix_rt::test] +#[ntex::test] pub async fn test_project_versions() { with_test_environment_all(None, |test_env| async move { let api = &test_env.api; @@ -554,7 +554,7 @@ pub async fn test_project_versions() { .await; } -#[actix_rt::test] +#[ntex::test] async fn can_create_version_with_ordering() { with_test_environment( None, @@ -589,7 +589,7 @@ async fn can_create_version_with_ordering() { .await; } -#[actix_rt::test] +#[ntex::test] async fn edit_version_ordering_works() { with_test_environment( None, @@ -619,7 +619,7 @@ async fn edit_version_ordering_works() { .await; } -#[actix_rt::test] +#[ntex::test] async fn version_ordering_for_specified_orderings_orders_lower_order_first() { with_test_environment_all(None, |env| async move { let alpha_project_id_parsed = env.dummy.project_alpha.project_id_parsed; @@ -657,7 +657,7 @@ async fn version_ordering_for_specified_orderings_orders_lower_order_first() { .await; } -#[actix_rt::test] +#[ntex::test] async fn version_ordering_when_unspecified_orders_oldest_first() { with_test_environment_all(None, |env| async move { let alpha_project_id_parsed = env.dummy.project_alpha.project_id_parsed; @@ -692,7 +692,7 @@ async fn version_ordering_when_unspecified_orders_oldest_first() { .await } -#[actix_rt::test] +#[ntex::test] async fn version_ordering_when_specified_orders_specified_before_unspecified() { with_test_environment_all(None, |env| async move { let alpha_project_id_parsed = env.dummy.project_alpha.project_id_parsed;