From 455e144ffb9d27473541148ebdcff9e8410e121f Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sun, 2 Nov 2025 09:31:01 +0100 Subject: [PATCH] init --- .gitignore | 3 + Cargo.lock | 2646 +++++++++++++++++ Cargo.toml | 3 + libertas_api/.env.example | 1 + libertas_api/.gitignore | 4 + libertas_api/Cargo.toml | 32 + .../20251102072244_create_users_table.sql | 9 + .../20251102073606_create_media_table.sql | 16 + .../20251102081244_create_albums_tables.sql | 23 + libertas_api/src/config.rs | 34 + libertas_api/src/error.rs | 43 + libertas_api/src/factory.rs | 105 + libertas_api/src/handlers/album_handlers.rs | 64 + libertas_api/src/handlers/auth_handlers.rs | 79 + libertas_api/src/handlers/media_handlers.rs | 77 + libertas_api/src/handlers/mod.rs | 3 + libertas_api/src/main.rs | 53 + libertas_api/src/middleware/auth.rs | 49 + libertas_api/src/middleware/mod.rs | 1 + .../src/repositories/album_repository.rs | 91 + .../src/repositories/media_repository.rs | 93 + libertas_api/src/repositories/mod.rs | 3 + .../src/repositories/user_repository.rs | 96 + libertas_api/src/security.rs | 115 + libertas_api/src/services/album_service.rs | 113 + libertas_api/src/services/media_service.rs | 112 + libertas_api/src/services/mod.rs | 3 + libertas_api/src/services/user_service.rs | 89 + libertas_api/src/state.rs | 13 + libertas_core/.gitignore | 1 + libertas_core/Cargo.toml | 13 + libertas_core/src/error.rs | 30 + libertas_core/src/lib.rs | 5 + libertas_core/src/models.rs | 67 + libertas_core/src/repositories.rs | 31 + libertas_core/src/schema.rs | 38 + libertas_core/src/services.rs | 35 + 37 files changed, 4193 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 libertas_api/.env.example create mode 100644 libertas_api/.gitignore create mode 100644 libertas_api/Cargo.toml create mode 100644 libertas_api/migrations/20251102072244_create_users_table.sql create mode 100644 libertas_api/migrations/20251102073606_create_media_table.sql create mode 100644 libertas_api/migrations/20251102081244_create_albums_tables.sql create mode 100644 libertas_api/src/config.rs create mode 100644 libertas_api/src/error.rs create mode 100644 libertas_api/src/factory.rs create mode 100644 libertas_api/src/handlers/album_handlers.rs create mode 100644 libertas_api/src/handlers/auth_handlers.rs create mode 100644 libertas_api/src/handlers/media_handlers.rs create mode 100644 libertas_api/src/handlers/mod.rs create mode 100644 libertas_api/src/main.rs create mode 100644 libertas_api/src/middleware/auth.rs create mode 100644 libertas_api/src/middleware/mod.rs create mode 100644 libertas_api/src/repositories/album_repository.rs create mode 100644 libertas_api/src/repositories/media_repository.rs create mode 100644 libertas_api/src/repositories/mod.rs create mode 100644 libertas_api/src/repositories/user_repository.rs create mode 100644 libertas_api/src/security.rs create mode 100644 libertas_api/src/services/album_service.rs create mode 100644 libertas_api/src/services/media_service.rs create mode 100644 libertas_api/src/services/mod.rs create mode 100644 libertas_api/src/services/user_service.rs create mode 100644 libertas_api/src/state.rs create mode 100644 libertas_core/.gitignore create mode 100644 libertas_core/Cargo.toml create mode 100644 libertas_core/src/error.rs create mode 100644 libertas_core/src/lib.rs create mode 100644 libertas_core/src/models.rs create mode 100644 libertas_core/src/repositories.rs create mode 100644 libertas_core/src/schema.rs create mode 100644 libertas_core/src/services.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea1187e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target/ +.sqlx/ +media_library/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..024400d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2646 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + +[[package]] +name = "argon2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" +dependencies = [ + "base64ct", + "blake2", + "cpufeatures", + "password-hash", +] + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "axum" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18ed336352031311f4e0b4dd2ff392d4fbb370777c9d18d7fc9d7359f73871" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "multer", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59446ce19cd142f8833f856eb31f3eb097812d1479ab224f54d72428ca21ea22" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-extra" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460c45604cb25834835e3b4d3468510322852783dac36261d642424d75562ff3" +dependencies = [ + "axum", + "axum-core", + "bytes", + "futures-core", + "futures-util", + "headers", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" + +[[package]] +name = "bitflags" +version = "2.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +dependencies = [ + "serde", +] + +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + +[[package]] +name = "cc" +version = "1.2.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37521ac7aabe3d13122dc382493e20c9416f299d2ccd5b3a5340a2570cdeb0f3" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" +dependencies = [ + "curve25519-dalek", + "ed25519", + "serde", + "sha2", + "subtle", + "zeroize", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "hkdf", + "pem-rfc7468", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "ff" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + +[[package]] +name = "find-msvc-tools" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" + +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "headers" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3314d5adb5d94bcdf56771f2e50dbbc80bb4bdf88967526706205ac9eff24eb" +dependencies = [ + "base64", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4" +dependencies = [ + "http", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3aa54a13a0dfe7fbe3a59e0c76093041720fdc77b110cc0fc260fafb4dc51e" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c6995591a8f1380fcb4ba966a252a4b29188d51d2b89e3a252f5305be65aea8" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" +dependencies = [ + "equivalent", + "hashbrown 0.16.0", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "js-sys" +version = "0.3.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "jsonwebtoken" +version = "10.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d119c6924272d16f0ab9ce41f7aa0bfef9340c00b0bb7ca3dd3b263d4a9150b" +dependencies = [ + "base64", + "ed25519-dalek", + "getrandom 0.2.16", + "hmac", + "js-sys", + "p256", + "p384", + "pem", + "rand", + "rsa", + "serde", + "serde_json", + "sha2", + "signature", + "simple_asn1", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.177" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" + +[[package]] +name = "libertas_api" +version = "0.1.0" +dependencies = [ + "anyhow", + "argon2", + "async-trait", + "axum", + "axum-extra", + "bytes", + "chrono", + "futures", + "headers", + "jsonwebtoken", + "libertas_core", + "once_cell", + "rand_core 0.9.3", + "serde", + "serde_json", + "sha2", + "sqlx", + "tokio", + "uuid", +] + +[[package]] +name = "libertas_core" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "bytes", + "chrono", + "futures", + "thiserror", + "uuid", +] + +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + +[[package]] +name = "libredox" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +dependencies = [ + "bitflags", + "libc", + "redox_syscall", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "multer" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http", + "httparse", + "memchr", + "mime", + "spin", + "version_check", +] + +[[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]] +name = "num-bigint-dig" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82c79c15c05d4bf82b6f5ef163104cc81a760d8e874d38ac50ab67c8877b647b" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] + +[[package]] +name = "p384" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe42f1670a52a47d448f14b6a5c61dd78fce51856e68edaa38f7ae3a46b8d6b6" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "password-hash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" +dependencies = [ + "base64ct", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "pem" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" +dependencies = [ + "base64", + "serde_core", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + +[[package]] +name = "proc-macro2" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.16", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "rsa" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78928ac1ed176a5ca1d17e578a1825f3d81ca54cf41053a592584b020cfd691b" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", + "serde_core", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" +dependencies = [ + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + +[[package]] +name = "simple_asn1" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "297f631f50729c8c99b84667867963997ec0b50f32b2a7dbcab828ef0541e8bb" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror", + "time", +] + +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] + +[[package]] +name = "socket2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "url" +version = "2.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" +dependencies = [ + "getrandom 0.3.4", + "js-sys", + "serde", + "wasm-bindgen", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d834181 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "3" +members = ["libertas_api", "libertas_core"] diff --git a/libertas_api/.env.example b/libertas_api/.env.example new file mode 100644 index 0000000..1dd7e45 --- /dev/null +++ b/libertas_api/.env.example @@ -0,0 +1 @@ +DATABASE_URL="postgres://postgres:postgres@localhost:5432/libertas_db" \ No newline at end of file diff --git a/libertas_api/.gitignore b/libertas_api/.gitignore new file mode 100644 index 0000000..4c71c3e --- /dev/null +++ b/libertas_api/.gitignore @@ -0,0 +1,4 @@ +/target +media_library/ +.sqlx/ +.env \ No newline at end of file diff --git a/libertas_api/Cargo.toml b/libertas_api/Cargo.toml new file mode 100644 index 0000000..752619a --- /dev/null +++ b/libertas_api/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "libertas_api" +version = "0.1.0" +edition = "2024" + +[dependencies] +axum = { version = "0.8.6", features = ["multipart"] } +tokio = { version = "1.48.0", features = ["full"] } + +libertas_core = { path = "../libertas_core" } +serde = { version = "1.0.228", features = ["derive"] } +sqlx = { version = "0.8.6", features = [ + "runtime-tokio", + "postgres", + "uuid", + "chrono", + "sqlite", +] } +async-trait = "0.1.89" +chrono = { version = "0.4.42", features = ["serde"] } +uuid = { version = "1.18.1", features = ["v4", "serde"] } +anyhow = "1.0.100" +argon2 = "0.5.3" +jsonwebtoken = { version = "10.1.0", features = ["rust_crypto"] } +once_cell = "1.21.3" +serde_json = "1.0.145" +headers = "0.4.1" +axum-extra = { version = "0.12.0", features = ["typed-header"] } +rand_core = { version = "0.9.3", features = ["std"] } +sha2 = "0.10.9" +futures = "0.3.31" +bytes = "1.10.1" diff --git a/libertas_api/migrations/20251102072244_create_users_table.sql b/libertas_api/migrations/20251102072244_create_users_table.sql new file mode 100644 index 0000000..d19eada --- /dev/null +++ b/libertas_api/migrations/20251102072244_create_users_table.sql @@ -0,0 +1,9 @@ +-- Active: 1762068220033@@127.0.0.1@5432@libertas_db +CREATE TABLE users ( + id UUID PRIMARY KEY, + username TEXT NOT NULL UNIQUE, + email TEXT NOT NULL UNIQUE, + hashed_password TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); \ No newline at end of file diff --git a/libertas_api/migrations/20251102073606_create_media_table.sql b/libertas_api/migrations/20251102073606_create_media_table.sql new file mode 100644 index 0000000..20e87a4 --- /dev/null +++ b/libertas_api/migrations/20251102073606_create_media_table.sql @@ -0,0 +1,16 @@ +CREATE TABLE media ( + id UUID PRIMARY KEY, + owner_id UUID NOT NULL REFERENCES users(id), + storage_path TEXT NOT NULL, + original_filename TEXT NOT NULL, + mime_type TEXT NOT NULL, + hash TEXT NOT NULL UNIQUE, -- For duplicate checking + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + +-- Optional fields from the model +extracted_location TEXT, width INTEGER, height INTEGER ); + +-- Indexes for faster lookups +CREATE INDEX idx_media_owner_id ON media (owner_id); + +CREATE INDEX idx_media_hash ON media (hash); \ No newline at end of file diff --git a/libertas_api/migrations/20251102081244_create_albums_tables.sql b/libertas_api/migrations/20251102081244_create_albums_tables.sql new file mode 100644 index 0000000..3448c76 --- /dev/null +++ b/libertas_api/migrations/20251102081244_create_albums_tables.sql @@ -0,0 +1,23 @@ +-- Create the 'albums' table +CREATE TABLE albums ( + id UUID PRIMARY KEY, + owner_id UUID NOT NULL REFERENCES users (id), + name TEXT NOT NULL, + description TEXT, + is_public BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +-- Create the 'album_media' join table +-- This links media items to albums +CREATE TABLE album_media ( + album_id UUID NOT NULL REFERENCES albums (id) ON DELETE CASCADE, + media_id UUID NOT NULL REFERENCES media (id) ON DELETE CASCADE, + PRIMARY KEY (album_id, media_id) -- Ensures no duplicates +); + +-- Indexes for faster lookups +CREATE INDEX idx_albums_owner_id ON albums (owner_id); + +CREATE INDEX idx_album_media_media_id ON album_media (media_id); \ No newline at end of file diff --git a/libertas_api/src/config.rs b/libertas_api/src/config.rs new file mode 100644 index 0000000..c9ef7d9 --- /dev/null +++ b/libertas_api/src/config.rs @@ -0,0 +1,34 @@ +use libertas_core::error::CoreResult; +use serde::Deserialize; + +#[derive(Deserialize, Clone)] +pub enum DatabaseType { + Postgres, + Sqlite, +} + +#[derive(Deserialize, Clone)] +pub struct DatabaseConfig { + pub db_type: DatabaseType, + pub url: String, +} + +#[derive(Deserialize, Clone)] +pub struct Config { + pub database: DatabaseConfig, + pub server_address: String, + pub jwt_secret: String, + pub media_library_path: String, +} + +pub fn load_config() -> CoreResult { + Ok(Config { + database: DatabaseConfig { + db_type: DatabaseType::Postgres, + url: "postgres://postgres:postgres@localhost:5432/libertas_db".to_string(), + }, + server_address: "127.0.0.1:8080".to_string(), + jwt_secret: "super_secret_jwt_key".to_string(), + media_library_path: "media_library".to_string(), + }) +} diff --git a/libertas_api/src/error.rs b/libertas_api/src/error.rs new file mode 100644 index 0000000..6567409 --- /dev/null +++ b/libertas_api/src/error.rs @@ -0,0 +1,43 @@ +use axum::{ + Json, + http::StatusCode, + response::{IntoResponse, Response}, +}; +use libertas_core::error::CoreError; +use serde_json::json; + +pub struct ApiError(CoreError); + +impl IntoResponse for ApiError { + fn into_response(self) -> Response { + let (status, error_message) = match self.0 { + CoreError::Database(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Database error: {}", e), + ), + CoreError::Validation(e) => (StatusCode::BAD_REQUEST, e), + CoreError::NotFound(res, id) => ( + StatusCode::NOT_FOUND, + format!("{} with id {} not found", res, id), + ), + CoreError::Duplicate(e) => (StatusCode::CONFLICT, e), + CoreError::Auth(e) => (StatusCode::UNAUTHORIZED, e), + _ => ( + StatusCode::INTERNAL_SERVER_ERROR, + "An unknown error occurred".to_string(), + ), + }; + + let body = Json(json!({ "error": error_message })); + (status, body).into_response() + } +} + +impl From for ApiError +where + E: Into, +{ + fn from(err: E) -> Self { + Self(err.into()) + } +} diff --git a/libertas_api/src/factory.rs b/libertas_api/src/factory.rs new file mode 100644 index 0000000..5b40fbd --- /dev/null +++ b/libertas_api/src/factory.rs @@ -0,0 +1,105 @@ +use std::sync::Arc; + +use libertas_core::{ + error::{CoreError, CoreResult}, + repositories::UserRepository, +}; +use sqlx::{Pool, Postgres, Sqlite}; + +use crate::{ + config::{Config, DatabaseConfig, DatabaseType}, + repositories::user_repository::{PostgresUserRepository, SqliteUserRepository}, + security::{Argon2Hasher, JwtGenerator}, + services::{ + album_service::AlbumServiceImpl, media_service::MediaServiceImpl, + user_service::UserServiceImpl, + }, + state::AppState, +}; + +#[derive(Clone)] +enum DatabasePool { + Postgres(Pool), + Sqlite(Pool), +} + +pub async fn build_app_state(config: Config) -> CoreResult { + let db_pool = build_database_pool(&config.database).await?; + + let user_repo = build_user_repository(&config.database, db_pool.clone()).await?; + let media_repo = build_media_repository(&config.database, db_pool.clone()).await?; + let album_repo = build_album_repository(&config.database, db_pool.clone()).await?; + + let hasher = Arc::new(Argon2Hasher::default()); + let tokenizer = Arc::new(JwtGenerator::new(config.jwt_secret.clone())); + + let user_service = Arc::new(UserServiceImpl::new(user_repo, hasher, tokenizer.clone())); + let media_service = Arc::new(MediaServiceImpl::new(media_repo.clone(), config.clone())); + let album_service = Arc::new(AlbumServiceImpl::new(album_repo, media_repo)); + + Ok(AppState { + user_service, + media_service, + album_service, + token_generator: tokenizer, + }) +} + +async fn build_database_pool(db_config: &DatabaseConfig) -> CoreResult { + match db_config.db_type { + DatabaseType::Postgres => { + let pool = sqlx::postgres::PgPoolOptions::new() + .max_connections(50) + .connect(&db_config.url) + .await + .map_err(|e| CoreError::Database(e.to_string()))?; + Ok(DatabasePool::Postgres(pool)) + } + DatabaseType::Sqlite => { + let pool = sqlx::sqlite::SqlitePoolOptions::new() + .max_connections(2) + .connect(&db_config.url) + .await + .map_err(|e| CoreError::Database(e.to_string()))?; + Ok(DatabasePool::Sqlite(pool)) + } + } +} + +async fn build_user_repository( + _db_config: &DatabaseConfig, + pool: DatabasePool, +) -> CoreResult> { + match pool { + DatabasePool::Postgres(pg_pool) => Ok(Arc::new(PostgresUserRepository::new(pg_pool))), + DatabasePool::Sqlite(sqlite_pool) => Ok(Arc::new(SqliteUserRepository::new(sqlite_pool))), + } +} + +async fn build_media_repository( + _db_config: &DatabaseConfig, + pool: DatabasePool, +) -> CoreResult> { + match pool { + DatabasePool::Postgres(pg_pool) => Ok(Arc::new( + crate::repositories::media_repository::PostgresMediaRepository::new(pg_pool), + )), + DatabasePool::Sqlite(_sqlite_pool) => Err(CoreError::Database( + "Sqlite media repository not implemented".to_string(), + )), + } +} + +async fn build_album_repository( + _db_config: &DatabaseConfig, + pool: DatabasePool, +) -> CoreResult> { + match pool { + DatabasePool::Postgres(pg_pool) => Ok(Arc::new( + crate::repositories::album_repository::PostgresAlbumRepository::new(pg_pool), + )), + DatabasePool::Sqlite(_sqlite_pool) => Err(CoreError::Database( + "Sqlite album repository not implemented".to_string(), + )), + } +} diff --git a/libertas_api/src/handlers/album_handlers.rs b/libertas_api/src/handlers/album_handlers.rs new file mode 100644 index 0000000..02d28dd --- /dev/null +++ b/libertas_api/src/handlers/album_handlers.rs @@ -0,0 +1,64 @@ +use axum::{ + Json, Router, + extract::{Path, State}, + http::StatusCode, +}; +use libertas_core::schema::{AddMediaToAlbumData, CreateAlbumData}; +use serde::Deserialize; +use uuid::Uuid; + +use crate::{error::ApiError, middleware::auth::UserId, state::AppState}; + +#[derive(Deserialize)] +pub struct CreateAlbumRequest { + name: String, + description: Option, + is_public: Option, +} + +async fn create_album( + State(state): State, + UserId(user_id): UserId, + Json(payload): Json, +) -> Result { + let album_data = CreateAlbumData { + owner_id: user_id, + name: &payload.name, + description: payload.description.as_deref(), + is_public: payload.is_public.unwrap_or(false), + }; + + state.album_service.create_album(album_data).await?; + + Ok(StatusCode::CREATED) +} + +#[derive(Deserialize)] +pub struct AddMediaToAlbumRequest { + media_ids: Vec, +} + +async fn add_media_to_album( + State(state): State, + UserId(user_id): UserId, + Path(album_id): Path, + Json(payload): Json, +) -> Result { + let data = AddMediaToAlbumData { + album_id, + media_ids: payload.media_ids, + }; + + state + .album_service + .add_media_to_album(data, user_id) + .await?; + + Ok(StatusCode::OK) +} + +pub fn album_routes() -> Router { + Router::new() + .route("/", axum::routing::post(create_album)) + .route("/{album_id}/media", axum::routing::post(add_media_to_album)) +} diff --git a/libertas_api/src/handlers/auth_handlers.rs b/libertas_api/src/handlers/auth_handlers.rs new file mode 100644 index 0000000..46893ce --- /dev/null +++ b/libertas_api/src/handlers/auth_handlers.rs @@ -0,0 +1,79 @@ +use axum::{Json, extract::State, http::StatusCode}; +use libertas_core::schema::{CreateUserData, LoginUserData}; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +use crate::{error::ApiError, middleware::auth::UserId, state::AppState}; + +#[derive(Deserialize)] +pub struct RegisterRequest { + pub username: String, + pub email: String, + pub password: String, +} + +#[derive(Serialize)] +pub struct UserResponse { + id: Uuid, + username: String, + email: String, +} + +pub async fn register( + State(state): State, + Json(payload): Json, +) -> Result<(StatusCode, Json), ApiError> { + let user_data = CreateUserData { + username: &payload.username, + email: &payload.email, + password: &payload.password, + }; + + let user = state.user_service.register(user_data).await?; + + let response = UserResponse { + id: user.id, + username: user.username, + email: user.email, + }; + + Ok((StatusCode::CREATED, Json(response))) +} + +#[derive(Deserialize)] +pub struct LoginRequest { + pub username_or_email: String, + pub password: String, +} + +#[derive(Serialize)] +pub struct LoginResponse { + token: String, +} + +pub async fn login( + State(state): State, + Json(payload): Json, +) -> Result, ApiError> { + let login_data = LoginUserData { + username_or_email: &payload.username_or_email, + password: &payload.password, + }; + + let token = state.user_service.login(login_data).await?; + Ok(Json(LoginResponse { token })) +} + +pub async fn get_me( + State(state): State, + UserId(user_id): UserId, +) -> Result, ApiError> { + let user = state.user_service.get_user_details(user_id).await?; + + let response = UserResponse { + id: user.id, + username: user.username, + email: user.email, + }; + Ok(Json(response)) +} diff --git a/libertas_api/src/handlers/media_handlers.rs b/libertas_api/src/handlers/media_handlers.rs new file mode 100644 index 0000000..a9644a2 --- /dev/null +++ b/libertas_api/src/handlers/media_handlers.rs @@ -0,0 +1,77 @@ +use axum::{ + Router, + extract::{DefaultBodyLimit, Multipart, State}, + http::StatusCode, + response::Json, + routing::post, +}; +use futures::TryStreamExt; +use libertas_core::{error::CoreError, models::Media, schema::UploadMediaData}; +use serde::Serialize; +use std::io; + +use crate::{error::ApiError, middleware::auth::UserId, state::AppState}; + +#[derive(Serialize)] +pub struct MediaResponse { + id: uuid::Uuid, + storage_path: String, + original_filename: String, + mime_type: String, + hash: String, +} + +impl From for MediaResponse { + fn from(media: Media) -> Self { + Self { + id: media.id, + storage_path: media.storage_path, + original_filename: media.original_filename, + mime_type: media.mime_type, + hash: media.hash, + } + } +} + +pub fn media_routes() -> Router { + Router::new() + .route("/", post(upload_media)) + .layer(DefaultBodyLimit::max(250 * 1024 * 1024)) +} + +async fn upload_media( + State(state): State, + UserId(user_id): UserId, + mut multipart: Multipart, +) -> Result<(StatusCode, Json), ApiError> { + let field = multipart + .next_field() + .await + .map_err(|e| CoreError::Validation(format!("Multipart error: {}", e)))? + .ok_or(ApiError::from(CoreError::Validation( + "No file provided in 'file' field".to_string(), + )))?; + + let filename = field.file_name().unwrap_or("unknown_file").to_string(); + let mime_type = field + .content_type() + .unwrap_or("application/octet-stream") + .to_string(); + + let stream = field.map_err(|e| io::Error::new(io::ErrorKind::Other, e)); + + let boxed_stream: Box< + dyn futures::Stream> + Send + Unpin, + > = Box::new(stream); + + let upload_data = UploadMediaData { + owner_id: user_id, + filename, + mime_type, + stream: boxed_stream, + }; + + let media = state.media_service.upload_media(upload_data).await?; + + Ok((StatusCode::CREATED, Json(media.into()))) +} diff --git a/libertas_api/src/handlers/mod.rs b/libertas_api/src/handlers/mod.rs new file mode 100644 index 0000000..435e7ac --- /dev/null +++ b/libertas_api/src/handlers/mod.rs @@ -0,0 +1,3 @@ +pub mod album_handlers; +pub mod auth_handlers; +pub mod media_handlers; diff --git a/libertas_api/src/main.rs b/libertas_api/src/main.rs new file mode 100644 index 0000000..b0a515c --- /dev/null +++ b/libertas_api/src/main.rs @@ -0,0 +1,53 @@ +use std::net::SocketAddr; + +use axum::{ + Router, + routing::{get, post}, +}; + +use crate::handlers::{ + album_handlers, auth_handlers, + media_handlers::{self}, +}; + +pub mod config; +pub mod error; +pub mod factory; +pub mod handlers; +pub mod middleware; +pub mod repositories; +pub mod security; +pub mod services; +pub mod state; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let config = config::load_config()?; + let addr: SocketAddr = config.server_address.parse()?; + + let app_state = factory::build_app_state(config).await?; + + let auth_routes = Router::new() + .route("/register", post(auth_handlers::register)) + .route("/login", post(auth_handlers::login)); + + let user_routes = Router::new().route("/me", get(auth_handlers::get_me)); + let media_routes = media_handlers::media_routes(); + let album_routes = album_handlers::album_routes(); + + let app = Router::new() + .route("/api/v1/health", get(|| async { "OK" })) + .nest("/api/v1/auth", auth_routes) + .nest("/api/v1/users", user_routes) + .nest("/api/v1/media", media_routes) + .nest("/api/v1/albums", album_routes) + .with_state(app_state); + + println!("Starting server at http://{}", addr); + + let listner = tokio::net::TcpListener::bind(addr).await?; + + axum::serve(listner, app.into_make_service()).await?; + + Ok(()) +} diff --git a/libertas_api/src/middleware/auth.rs b/libertas_api/src/middleware/auth.rs new file mode 100644 index 0000000..bf301bd --- /dev/null +++ b/libertas_api/src/middleware/auth.rs @@ -0,0 +1,49 @@ +use axum::{ + RequestPartsExt, + extract::FromRequestParts, + http::{StatusCode, request::Parts}, + response::{IntoResponse, Response}, +}; +use axum_extra::TypedHeader; +use axum_extra::headers::{Authorization, authorization::Bearer}; +use libertas_core::error::{CoreError, CoreResult}; +use uuid::Uuid; + +use crate::{security::TokenGenerator, state::AppState}; +use std::sync::Arc; + +pub struct UserId(pub Uuid); + +impl FromRequestParts for UserId { + type Rejection = Response; + + async fn from_request_parts( + parts: &mut Parts, + state: &AppState, + ) -> Result { + let tokenizer: Arc = state.token_generator.clone(); + + let result = (async || -> CoreResult { + let TypedHeader(Authorization(bearer)) = parts + .extract::>>() + .await + .map_err(|_| CoreError::Auth("Missing Authorization header".to_string()))?; + + let user_id = tokenizer.verify_token(bearer.token())?; + + Ok(user_id) + })() + .await; + + match result { + Ok(user_id) => Ok(Self(user_id)), + Err(e) => { + let status = match e { + CoreError::Auth(_) => StatusCode::UNAUTHORIZED, + _ => StatusCode::INTERNAL_SERVER_ERROR, + }; + Err((status, e.to_string()).into_response()) + } + } + } +} diff --git a/libertas_api/src/middleware/mod.rs b/libertas_api/src/middleware/mod.rs new file mode 100644 index 0000000..0e4a05d --- /dev/null +++ b/libertas_api/src/middleware/mod.rs @@ -0,0 +1 @@ +pub mod auth; diff --git a/libertas_api/src/repositories/album_repository.rs b/libertas_api/src/repositories/album_repository.rs new file mode 100644 index 0000000..46fd502 --- /dev/null +++ b/libertas_api/src/repositories/album_repository.rs @@ -0,0 +1,91 @@ +use async_trait::async_trait; +use libertas_core::{ + error::{CoreError, CoreResult}, + models::Album, + repositories::AlbumRepository, +}; +use sqlx::PgPool; +use uuid::Uuid; + +#[derive(Clone)] +pub struct PostgresAlbumRepository { + pool: PgPool, +} + +impl PostgresAlbumRepository { + pub fn new(pool: PgPool) -> Self { + Self { pool } + } +} + +#[async_trait] +impl AlbumRepository for PostgresAlbumRepository { + async fn create(&self, album: Album) -> CoreResult<()> { + sqlx::query!( + r#" + INSERT INTO albums (id, owner_id, name, description, is_public, created_at, updated_at) + VALUES ($1, $2, $3, $4, $5, $6, $7) + "#, + album.id, + album.owner_id, + album.name, + album.description, + album.is_public, + album.created_at, + album.updated_at + ) + .execute(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string()))?; + + Ok(()) + } + + async fn find_by_id(&self, id: Uuid) -> CoreResult> { + sqlx::query_as!( + Album, + r#" + SELECT id, owner_id, name, description, is_public, created_at, updated_at + FROM albums + WHERE id = $1 + "#, + id + ) + .fetch_optional(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } + + async fn list_by_user(&self, user_id: Uuid) -> CoreResult> { + sqlx::query_as!( + Album, + r#" + SELECT id, owner_id, name, description, is_public, created_at, updated_at + FROM albums + WHERE owner_id = $1 + "#, + user_id + ) + .fetch_all(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } + + async fn add_media_to_album(&self, album_id: Uuid, media_ids: &[Uuid]) -> CoreResult<()> { + // Use sqlx's `unnest` feature to pass the Vec efficiently + sqlx::query!( + r#" + INSERT INTO album_media (album_id, media_id) + SELECT $1, media_id FROM unnest($2::uuid[]) as media_id + ON CONFLICT (album_id, media_id) DO NOTHING + "#, + album_id, + media_ids + ) + .execute(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string()))?; + + Ok(()) + } +} diff --git a/libertas_api/src/repositories/media_repository.rs b/libertas_api/src/repositories/media_repository.rs new file mode 100644 index 0000000..7983b73 --- /dev/null +++ b/libertas_api/src/repositories/media_repository.rs @@ -0,0 +1,93 @@ +use async_trait::async_trait; +use libertas_core::{ + error::{CoreError, CoreResult}, + models::Media, + repositories::MediaRepository, +}; +use sqlx::PgPool; +use uuid::Uuid; + +#[derive(Clone)] +pub struct PostgresMediaRepository { + pool: PgPool, +} + +impl PostgresMediaRepository { + pub fn new(pool: PgPool) -> Self { + Self { pool } + } +} + +#[async_trait] +impl MediaRepository for PostgresMediaRepository { + async fn create(&self, media: &Media) -> CoreResult<()> { + sqlx::query!( + r#" + INSERT INTO media (id, owner_id, storage_path, original_filename, mime_type, hash, created_at, width, height) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + "#, + media.id, + media.owner_id, + media.storage_path, + media.original_filename, + media.mime_type, + media.hash, + media.created_at, + media.width, + media.height + ) + .execute(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string()))?; + + Ok(()) + } + + async fn find_by_hash(&self, hash: &str) -> CoreResult> { + sqlx::query_as!( + Media, + r#" + SELECT id, owner_id, storage_path, original_filename, mime_type, hash, created_at, + extracted_location, width, height + FROM media + WHERE hash = $1 + "#, + hash + ) + .fetch_optional(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } + + async fn find_by_id(&self, id: Uuid) -> CoreResult> { + sqlx::query_as!( + Media, + r#" + SELECT id, owner_id, storage_path, original_filename, mime_type, hash, created_at, + extracted_location, width, height + FROM media + WHERE id = $1 + "#, + id + ) + .fetch_optional(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } + + async fn list_by_user(&self, user_id: Uuid) -> CoreResult> { + sqlx::query_as!( + Media, + r#" + SELECT id, owner_id, storage_path, original_filename, mime_type, hash, created_at, + extracted_location, width, height + FROM media + WHERE owner_id = $1 + "#, + user_id + ) + .fetch_all(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } +} diff --git a/libertas_api/src/repositories/mod.rs b/libertas_api/src/repositories/mod.rs new file mode 100644 index 0000000..f1f652d --- /dev/null +++ b/libertas_api/src/repositories/mod.rs @@ -0,0 +1,3 @@ +pub mod album_repository; +pub mod media_repository; +pub mod user_repository; diff --git a/libertas_api/src/repositories/user_repository.rs b/libertas_api/src/repositories/user_repository.rs new file mode 100644 index 0000000..b18cc0e --- /dev/null +++ b/libertas_api/src/repositories/user_repository.rs @@ -0,0 +1,96 @@ +use async_trait::async_trait; +use libertas_core::{ + error::{CoreError, CoreResult}, + models::User, + repositories::UserRepository, +}; +use sqlx::{PgPool, SqlitePool, types::Uuid}; + +#[derive(Clone)] +pub struct PostgresUserRepository { + pool: PgPool, +} + +impl PostgresUserRepository { + pub fn new(pool: PgPool) -> Self { + Self { pool } + } +} + +#[derive(Clone)] +pub struct SqliteUserRepository { + _pool: SqlitePool, +} + +impl SqliteUserRepository { + pub fn new(pool: SqlitePool) -> Self { + Self { _pool: pool } + } +} + +#[async_trait] +impl UserRepository for PostgresUserRepository { + async fn create(&self, user: User) -> CoreResult<()> { + sqlx::query!( + r#" + INSERT INTO users (id, username, email, hashed_password, created_at, updated_at) + VALUES ($1, $2, $3, $4, $5, $6) + "#, + user.id, + user.username, + user.email, + user.hashed_password, + user.created_at, + user.updated_at + ) + .execute(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string()))?; + + Ok(()) + } + + async fn find_by_email(&self, email: &str) -> CoreResult> { + sqlx::query_as!(User, "SELECT * FROM users WHERE email = $1", email) + .fetch_optional(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } + + async fn find_by_username(&self, username: &str) -> CoreResult> { + sqlx::query_as!(User, "SELECT * FROM users WHERE username = $1", username) + .fetch_optional(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } + + async fn find_by_id(&self, id: Uuid) -> CoreResult> { + sqlx::query_as!(User, "SELECT * FROM users WHERE id = $1", id) + .fetch_optional(&self.pool) + .await + .map_err(|e| CoreError::Database(e.to_string())) + } +} + +#[async_trait] +impl UserRepository for SqliteUserRepository { + async fn create(&self, _user: User) -> CoreResult<()> { + println!("SQLITE REPO: Creating user"); + Ok(()) + } + + async fn find_by_email(&self, _email: &str) -> CoreResult> { + println!("SQLITE REPO: Finding user by email"); + Ok(None) + } + + async fn find_by_username(&self, _username: &str) -> CoreResult> { + println!("SQLITE REPO: Finding user by username"); + Ok(None) + } + + async fn find_by_id(&self, _id: Uuid) -> CoreResult> { + println!("SQLITE REPO: Finding user by id"); + Ok(None) + } +} diff --git a/libertas_api/src/security.rs b/libertas_api/src/security.rs new file mode 100644 index 0000000..dc2d151 --- /dev/null +++ b/libertas_api/src/security.rs @@ -0,0 +1,115 @@ +use argon2::{ + Argon2, + password_hash::{ + PasswordHash, PasswordHasher as _, PasswordVerifier, SaltString, rand_core::OsRng, + }, +}; +use async_trait::async_trait; +use chrono::{Duration, Utc}; +use jsonwebtoken::{DecodingKey, EncodingKey, Header, Validation, decode, encode}; +use libertas_core::error::{CoreError, CoreResult}; +use once_cell::sync::Lazy; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +#[async_trait] +pub trait PasswordHasher: Send + Sync { + async fn hash_password(&self, password: &str) -> CoreResult; + async fn verify_password(&self, password: &str, hash: &str) -> CoreResult<()>; +} + +pub struct Argon2Hasher; + +impl Default for Argon2Hasher { + fn default() -> Self { + Self {} + } +} + +#[async_trait] +impl PasswordHasher for Argon2Hasher { + async fn hash_password(&self, password: &str) -> CoreResult { + let salt = SaltString::generate(&mut OsRng); + + let password_bytes = password.as_bytes().to_vec(); + + let hash_string = tokio::task::spawn_blocking(move || { + Argon2::default() + .hash_password(&password_bytes, &salt) + .map(|hash| hash.to_string()) + .map_err(|e| CoreError::Auth(format!("Password hashing failed: {}", e))) + }) + .await + .unwrap()?; + + Ok(hash_string) + } + + async fn verify_password(&self, password: &str, hash_str: &str) -> CoreResult<()> { + let hash = PasswordHash::new(hash_str) + .map_err(|e| CoreError::Auth(format!("Invalid password hash format: {}", e)))?; + + let (password_bytes, hash_bytes) = (password.as_bytes().to_vec(), hash.to_string()); + + tokio::task::spawn_blocking(move || { + Argon2::default() + .verify_password(&password_bytes, &PasswordHash::new(&hash_bytes).unwrap()) + .map_err(|_| CoreError::Auth("Invalid password".to_string())) + }) + .await + .unwrap() + } +} + +static JWT_HEADER: Lazy
= Lazy::new(Header::default); + +#[derive(Debug, Serialize, Deserialize, Clone)] +struct Claims { + sub: Uuid, + exp: usize, + iat: usize, +} + +#[async_trait] +pub trait TokenGenerator: Send + Sync { + fn generate_token(&self, user_id: Uuid) -> CoreResult; + fn verify_token(&self, token: &str) -> CoreResult; +} + +pub struct JwtGenerator { + encoding_key: EncodingKey, + decoding_key: DecodingKey, +} + +impl JwtGenerator { + pub fn new(secret: String) -> Self { + Self { + encoding_key: EncodingKey::from_secret(secret.as_bytes()), + decoding_key: DecodingKey::from_secret(secret.as_bytes()), + } + } +} + +#[async_trait] +impl TokenGenerator for JwtGenerator { + fn generate_token(&self, user_id: Uuid) -> CoreResult { + let now = Utc::now(); + let iat = now.timestamp() as usize; + let exp = (now + Duration::days(7)).timestamp() as usize; + + let claims = Claims { + sub: user_id, + iat, + exp, + }; + + encode(&JWT_HEADER, &claims, &self.encoding_key) + .map_err(|e| CoreError::Auth(format!("Token generation failed: {}", e))) + } + + fn verify_token(&self, token: &str) -> CoreResult { + decode::(token, &self.decoding_key, &Validation::default()) + .map(|data| data.claims.sub) + .map_err(|e| CoreError::Auth(format!("Token invalid: {}", e))) + } +} diff --git a/libertas_api/src/services/album_service.rs b/libertas_api/src/services/album_service.rs new file mode 100644 index 0000000..7eb0ca1 --- /dev/null +++ b/libertas_api/src/services/album_service.rs @@ -0,0 +1,113 @@ +use std::sync::Arc; + +use async_trait::async_trait; +use chrono::Utc; +use libertas_core::{ + error::{CoreError, CoreResult}, + models::Album, + repositories::{AlbumRepository, MediaRepository}, + schema::{AddMediaToAlbumData, CreateAlbumData, ShareAlbumData}, + services::AlbumService, +}; +use uuid::Uuid; + +pub struct AlbumServiceImpl { + album_repo: Arc, + media_repo: Arc, +} + +impl AlbumServiceImpl { + pub fn new(album_repo: Arc, media_repo: Arc) -> Self { + Self { + album_repo, + media_repo, + } + } + + async fn is_album_owner(&self, user_id: Uuid, album_id: Uuid) -> CoreResult { + let album = self + .album_repo + .find_by_id(album_id) + .await? + .ok_or(CoreError::NotFound("Album".to_string(), album_id))?; + + Ok(album.owner_id == user_id) + } +} + +#[async_trait] +impl AlbumService for AlbumServiceImpl { + async fn create_album(&self, data: CreateAlbumData<'_>) -> CoreResult<()> { + if data.name.is_empty() { + return Err(CoreError::Validation( + "Album name cannot be empty".to_string(), + )); + } + + let now = Utc::now(); + let album = Album { + id: Uuid::new_v4(), + owner_id: data.owner_id, + name: data.name.to_string(), + description: data.description.map(String::from), + is_public: data.is_public, + created_at: now, + updated_at: now, + }; + + self.album_repo.create(album).await + } + + async fn get_album_details(&self, album_id: Uuid, user_id: Uuid) -> CoreResult { + let album = self + .album_repo + .find_by_id(album_id) + .await? + .ok_or(CoreError::NotFound("Album".to_string(), album_id))?; + + // Security check: Only owner (for now) can see album details + if album.owner_id != user_id { + // Later, this would also check share permissions + return Err(CoreError::Auth("Access denied to album".to_string())); + } + + Ok(album) + } + + async fn add_media_to_album(&self, data: AddMediaToAlbumData, user_id: Uuid) -> CoreResult<()> { + // 1. Verify the user owns the album + if !self.is_album_owner(user_id, data.album_id).await? { + return Err(CoreError::Auth("User does not own this album".to_string())); + } + + // 2. Bonus: Verify the user owns all media items + for media_id in &data.media_ids { + let media = self + .media_repo + .find_by_id(*media_id) + .await? + .ok_or(CoreError::NotFound("Media".to_string(), *media_id))?; + + if media.owner_id != user_id { + return Err(CoreError::Auth(format!( + "Access denied to media item {}", + media_id + ))); + } + } + + // 3. Call the repository to add them + self.album_repo + .add_media_to_album(data.album_id, &data.media_ids) + .await + } + + async fn list_user_albums(&self, user_id: Uuid) -> CoreResult> { + self.album_repo.list_by_user(user_id).await + } + + async fn share_album(&self, _data: ShareAlbumData, _owner_id: Uuid) -> CoreResult<()> { + // This is not part of the MVP, but part of the trait + unimplemented!("Sharing will be implemented in a future phase") + } +} diff --git a/libertas_api/src/services/media_service.rs b/libertas_api/src/services/media_service.rs new file mode 100644 index 0000000..346dde0 --- /dev/null +++ b/libertas_api/src/services/media_service.rs @@ -0,0 +1,112 @@ +use std::{path::PathBuf, sync::Arc}; + +use async_trait::async_trait; +use chrono::Datelike; +use futures::stream::StreamExt; +use libertas_core::{ + error::{CoreError, CoreResult}, + models::Media, + repositories::MediaRepository, + schema::UploadMediaData, + services::MediaService, +}; +use sha2::{Digest, Sha256}; +use tokio::{fs, io::AsyncWriteExt}; +use uuid::Uuid; + +use crate::config::Config; + +pub struct MediaServiceImpl { + repo: Arc, + config: Config, +} + +impl MediaServiceImpl { + pub fn new(repo: Arc, config: Config) -> Self { + Self { repo, config } + } +} + +#[async_trait] +impl MediaService for MediaServiceImpl { + async fn upload_media(&self, mut data: UploadMediaData<'_>) -> CoreResult { + let mut hasher = Sha256::new(); + let mut file_bytes = Vec::new(); + + while let Some(chunk_result) = data.stream.next().await { + let chunk = chunk_result.map_err(|e| CoreError::Io(e))?; + hasher.update(&chunk); + file_bytes.extend_from_slice(&chunk); + } + + let hash = format!("{:x}", hasher.finalize()); + + if self.repo.find_by_hash(&hash).await?.is_some() { + return Err(CoreError::Duplicate( + "A file with this content already exists".to_string(), + )); + } + + let now = chrono::Utc::now(); + let year = now.year().to_string(); + let month = format!("{:02}", now.month()); + let mut dest_path = PathBuf::from(&self.config.media_library_path); + dest_path.push(year.clone()); + dest_path.push(month.clone()); + + fs::create_dir_all(&dest_path) + .await + .map_err(|e| CoreError::Io(e))?; + + dest_path.push(&data.filename); + + let storage_path_str = PathBuf::from(&year) + .join(&month) + .join(&data.filename) + .to_string_lossy() + .to_string(); + + let mut file = fs::File::create(&dest_path) + .await + .map_err(|e| CoreError::Io(e))?; + + file.write_all(&file_bytes) + .await + .map_err(|e| CoreError::Io(e))?; + + let media_model = Media { + id: Uuid::new_v4(), + owner_id: data.owner_id, + storage_path: storage_path_str, + original_filename: data.filename, + mime_type: data.mime_type, + hash, + created_at: now, + extracted_location: None, + width: None, + height: None, + }; + + self.repo.create(&media_model).await?; + + Ok(media_model) + } + + async fn get_media_details(&self, id: Uuid, user_id: Uuid) -> CoreResult { + let media = self + .repo + .find_by_id(id) + .await? + .ok_or(CoreError::NotFound("Media".to_string(), id))?; + + if media.owner_id != user_id { + return Err(CoreError::Auth("Access denied".to_string())); + } + + Ok(media) + } + + async fn list_user_media(&self, user_id: Uuid) -> CoreResult> { + self.repo.list_by_user(user_id).await + } +} diff --git a/libertas_api/src/services/mod.rs b/libertas_api/src/services/mod.rs new file mode 100644 index 0000000..2f30a25 --- /dev/null +++ b/libertas_api/src/services/mod.rs @@ -0,0 +1,3 @@ +pub mod album_service; +pub mod media_service; +pub mod user_service; diff --git a/libertas_api/src/services/user_service.rs b/libertas_api/src/services/user_service.rs new file mode 100644 index 0000000..d53db79 --- /dev/null +++ b/libertas_api/src/services/user_service.rs @@ -0,0 +1,89 @@ +use std::sync::Arc; + +use async_trait::async_trait; +use libertas_core::{ + error::{CoreError, CoreResult}, + models::User, + repositories::UserRepository, + schema::{CreateUserData, LoginUserData}, + services::UserService, +}; +use uuid::Uuid; + +use crate::security::{PasswordHasher, TokenGenerator}; + +pub struct UserServiceImpl { + repo: Arc, + hasher: Arc, + tokenizer: Arc, +} + +impl UserServiceImpl { + pub fn new( + repo: Arc, + hasher: Arc, + tokenizer: Arc, + ) -> Self { + Self { + repo, + hasher, + tokenizer, + } + } +} + +#[async_trait] +impl UserService for UserServiceImpl { + async fn register(&self, data: CreateUserData<'_>) -> CoreResult { + if data.username.is_empty() || data.email.is_empty() || data.password.is_empty() { + return Err(CoreError::Validation( + "Username, email, and password cannot be empty".to_string(), + )); + } + + if self.repo.find_by_email(data.email).await?.is_some() { + return Err(CoreError::Duplicate("Email already exists".to_string())); + } + if self.repo.find_by_username(data.username).await?.is_some() { + return Err(CoreError::Duplicate("Username already exists".to_string())); + } + + let hashed_password = self.hasher.hash_password(data.password).await?; + + let user = User { + id: Uuid::new_v4(), + username: data.username.to_string(), + email: data.email.to_string(), + hashed_password, + created_at: chrono::Utc::now(), + updated_at: chrono::Utc::now(), + }; + + self.repo.create(user.clone()).await?; + + Ok(user) + } + + async fn login(&self, data: LoginUserData<'_>) -> CoreResult { + let user = self + .repo + .find_by_email(data.username_or_email) // Allow login with email + .await? + .or(self.repo.find_by_username(data.username_or_email).await?) // Or username + .ok_or(CoreError::Auth("Invalid credentials".to_string()))?; + + self.hasher + .verify_password(data.password, &user.hashed_password) + .await?; + + // 3. Generate JWT token + self.tokenizer.generate_token(user.id) + } + + async fn get_user_details(&self, user_id: Uuid) -> CoreResult { + self.repo + .find_by_id(user_id) + .await? + .ok_or(CoreError::NotFound("User".to_string(), user_id)) + } +} diff --git a/libertas_api/src/state.rs b/libertas_api/src/state.rs new file mode 100644 index 0000000..6537dcf --- /dev/null +++ b/libertas_api/src/state.rs @@ -0,0 +1,13 @@ +use std::sync::Arc; + +use libertas_core::services::{AlbumService, MediaService, UserService}; + +use crate::security::TokenGenerator; + +#[derive(Clone)] +pub struct AppState { + pub user_service: Arc, + pub media_service: Arc, + pub album_service: Arc, + pub token_generator: Arc, +} diff --git a/libertas_core/.gitignore b/libertas_core/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/libertas_core/.gitignore @@ -0,0 +1 @@ +/target diff --git a/libertas_core/Cargo.toml b/libertas_core/Cargo.toml new file mode 100644 index 0000000..eed3d0e --- /dev/null +++ b/libertas_core/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "libertas_core" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1.0.100" +async-trait = "0.1.89" +bytes = "1.10.1" +chrono = "0.4.42" +futures = "0.3.31" +thiserror = "2.0.17" +uuid = "1.18.1" diff --git a/libertas_core/src/error.rs b/libertas_core/src/error.rs new file mode 100644 index 0000000..bc40939 --- /dev/null +++ b/libertas_core/src/error.rs @@ -0,0 +1,30 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum CoreError { + #[error("Configuration error: {0}")] + Config(String), + + #[error("I/O error: {0}")] + Io(#[from] std::io::Error), + + #[error("Database error: {0}")] + Database(String), + + #[error("Validation error: {0}")] + Validation(String), + + #[error("{0} not found with id: {1}")] + NotFound(String, uuid::Uuid), + + #[error("Duplicate resource: {0}")] + Duplicate(String), + + #[error("Authentication failed: {0}")] + Auth(String), + + #[error("An unknown error occurred")] + Unknown, +} + +pub type CoreResult = Result; diff --git a/libertas_core/src/lib.rs b/libertas_core/src/lib.rs new file mode 100644 index 0000000..e8f91e6 --- /dev/null +++ b/libertas_core/src/lib.rs @@ -0,0 +1,5 @@ +pub mod error; +pub mod models; +pub mod repositories; +pub mod schema; +pub mod services; diff --git a/libertas_core/src/models.rs b/libertas_core/src/models.rs new file mode 100644 index 0000000..7de80f7 --- /dev/null +++ b/libertas_core/src/models.rs @@ -0,0 +1,67 @@ +pub struct Media { + pub id: uuid::Uuid, + pub owner_id: uuid::Uuid, + pub storage_path: String, + pub original_filename: String, + pub mime_type: String, + pub hash: String, + pub created_at: chrono::DateTime, + pub extracted_location: Option, + pub width: Option, + pub height: Option, +} + +#[derive(Clone)] +pub struct User { + pub id: uuid::Uuid, + pub username: String, + pub email: String, + pub hashed_password: String, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, +} + +pub struct Album { + pub id: uuid::Uuid, + pub owner_id: uuid::Uuid, + pub name: String, + pub description: Option, + pub is_public: bool, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, +} + +pub struct Person { + pub id: uuid::Uuid, + pub owner_id: uuid::Uuid, + pub name: String, + pub thumbnail_media_id: Option, +} + +pub struct FaceRegion { + pub id: uuid::Uuid, + pub media_id: uuid::Uuid, + pub person_id: Option, + + pub x_min: f32, + pub y_min: f32, + pub x_max: f32, + pub y_max: f32, +} + +pub struct AlbumMedia { + pub album_id: uuid::Uuid, + pub media_id: uuid::Uuid, +} + +#[derive(Clone, Copy)] +pub enum AlbumPermission { + View, + Contribute, +} + +pub struct AlbumShare { + pub album_id: uuid::Uuid, + pub user_id: uuid::Uuid, + pub permission: AlbumPermission, +} diff --git a/libertas_core/src/repositories.rs b/libertas_core/src/repositories.rs new file mode 100644 index 0000000..345240f --- /dev/null +++ b/libertas_core/src/repositories.rs @@ -0,0 +1,31 @@ +use async_trait::async_trait; +use uuid::Uuid; + +use crate::{ + error::CoreResult, + models::{Album, Media, User}, +}; + +#[async_trait] +pub trait MediaRepository: Send + Sync { + async fn find_by_hash(&self, hash: &str) -> CoreResult>; + async fn create(&self, media: &Media) -> CoreResult<()>; + async fn find_by_id(&self, id: Uuid) -> CoreResult>; + async fn list_by_user(&self, user_id: Uuid) -> CoreResult>; +} + +#[async_trait] +pub trait UserRepository: Send + Sync { + async fn create(&self, user: User) -> CoreResult<()>; + async fn find_by_email(&self, email: &str) -> CoreResult>; + async fn find_by_username(&self, username: &str) -> CoreResult>; + async fn find_by_id(&self, id: Uuid) -> CoreResult>; +} + +#[async_trait] +pub trait AlbumRepository: Send + Sync { + async fn create(&self, album: Album) -> CoreResult<()>; + async fn find_by_id(&self, id: Uuid) -> CoreResult>; + async fn list_by_user(&self, user_id: Uuid) -> CoreResult>; + async fn add_media_to_album(&self, album_id: Uuid, media_ids: &[Uuid]) -> CoreResult<()>; +} diff --git a/libertas_core/src/schema.rs b/libertas_core/src/schema.rs new file mode 100644 index 0000000..e33f2ab --- /dev/null +++ b/libertas_core/src/schema.rs @@ -0,0 +1,38 @@ +use crate::models::AlbumPermission; + +pub struct UploadMediaData<'a> { + pub owner_id: uuid::Uuid, + pub filename: String, + pub mime_type: String, + pub stream: + Box> + Send + Unpin + 'a>, +} + +pub struct CreateUserData<'a> { + pub username: &'a str, + pub email: &'a str, + pub password: &'a str, +} + +pub struct LoginUserData<'a> { + pub username_or_email: &'a str, + pub password: &'a str, +} + +pub struct CreateAlbumData<'a> { + pub owner_id: uuid::Uuid, + pub name: &'a str, + pub description: Option<&'a str>, + pub is_public: bool, +} + +pub struct AddMediaToAlbumData { + pub album_id: uuid::Uuid, + pub media_ids: Vec, +} + +pub struct ShareAlbumData { + pub album_id: uuid::Uuid, + pub target_user_id: uuid::Uuid, + pub permission: AlbumPermission, +} diff --git a/libertas_core/src/services.rs b/libertas_core/src/services.rs new file mode 100644 index 0000000..60c1cee --- /dev/null +++ b/libertas_core/src/services.rs @@ -0,0 +1,35 @@ +use async_trait::async_trait; +use uuid::Uuid; + +use crate::{ + error::CoreResult, + models::{Album, Media, User}, + schema::{ + AddMediaToAlbumData, CreateAlbumData, CreateUserData, LoginUserData, ShareAlbumData, + UploadMediaData, + }, +}; + +#[async_trait] +pub trait MediaService: Send + Sync { + async fn upload_media(&self, data: UploadMediaData<'_>) -> CoreResult; + async fn get_media_details(&self, id: Uuid, user_id: Uuid) -> CoreResult; + async fn list_user_media(&self, user_id: Uuid) -> CoreResult>; +} + +#[async_trait] +pub trait UserService: Send + Sync { + async fn register(&self, data: CreateUserData<'_>) -> CoreResult; + async fn login(&self, data: LoginUserData<'_>) -> CoreResult; + async fn get_user_details(&self, user_id: uuid::Uuid) -> CoreResult; +} + +#[async_trait] +pub trait AlbumService: Send + Sync { + async fn create_album(&self, data: CreateAlbumData<'_>) -> CoreResult<()>; + async fn get_album_details(&self, album_id: Uuid, user_id: Uuid) -> CoreResult; + async fn add_media_to_album(&self, data: AddMediaToAlbumData, user_id: Uuid) -> CoreResult<()>; + async fn list_user_albums(&self, user_id: Uuid) -> CoreResult>; + + async fn share_album(&self, data: ShareAlbumData, owner_id: Uuid) -> CoreResult<()>; +}