From c125a79661f610331bea6cfa9ca9c99c3210f771 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 26 Dec 2024 21:24:37 +0900 Subject: [PATCH 1/4] basic structure in place --- Cargo.lock | 614 ++++++++++++++++++++++++++++++++++++++++- apps/server/Cargo.toml | 2 +- crates/s3/Cargo.toml | 15 + crates/s3/src/lib.rs | 78 ++++++ 4 files changed, 699 insertions(+), 10 deletions(-) create mode 100644 crates/s3/Cargo.toml create mode 100644 crates/s3/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index f16a79432b..fce331b9cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -586,6 +586,380 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "aws-config" +version = "1.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d1c2c88936a73c699225d0bc00684a534166b0cebc2659c3cdf08de8edc64c" +dependencies = [ + "aws-credential-types", + "aws-runtime", + "aws-sdk-sso", + "aws-sdk-ssooidc", + "aws-sdk-sts", + "aws-smithy-async", + "aws-smithy-http", + "aws-smithy-json", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-types", + "bytes", + "fastrand 2.3.0", + "hex", + "http 0.2.12", + "ring 0.17.8", + "time", + "tokio", + "tracing", + "url", + "zeroize", +] + +[[package]] +name = "aws-credential-types" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e8f6b615cb5fc60a98132268508ad104310f0cfb25a1c22eee76efdf9154da" +dependencies = [ + "aws-smithy-async", + "aws-smithy-runtime-api", + "aws-smithy-types", + "zeroize", +] + +[[package]] +name = "aws-runtime" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300a12520b4e6d08b73f77680f12c16e8ae43250d55100e0b2be46d78da16a48" +dependencies = [ + "aws-credential-types", + "aws-sigv4", + "aws-smithy-async", + "aws-smithy-eventstream", + "aws-smithy-http", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-types", + "bytes", + "fastrand 2.3.0", + "http 0.2.12", + "http-body 0.4.6", + "once_cell", + "percent-encoding", + "pin-project-lite", + "tracing", + "uuid 1.11.0", +] + +[[package]] +name = "aws-sdk-s3" +version = "1.66.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "154488d16ab0d627d15ab2832b57e68a16684c8c902f14cb8a75ec933fc94852" +dependencies = [ + "aws-credential-types", + "aws-runtime", + "aws-sigv4", + "aws-smithy-async", + "aws-smithy-checksums", + "aws-smithy-eventstream", + "aws-smithy-http", + "aws-smithy-json", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-smithy-xml", + "aws-types", + "bytes", + "fastrand 2.3.0", + "hex", + "hmac", + "http 0.2.12", + "http-body 0.4.6", + "lru", + "once_cell", + "percent-encoding", + "regex-lite", + "sha2", + "tracing", + "url", +] + +[[package]] +name = "aws-sdk-sso" +version = "1.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74995133da38f109a0eb8e8c886f9e80c713b6e9f2e6e5a6a1ba4450ce2ffc46" +dependencies = [ + "aws-credential-types", + "aws-runtime", + "aws-smithy-async", + "aws-smithy-http", + "aws-smithy-json", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-types", + "bytes", + "http 0.2.12", + "once_cell", + "regex-lite", + "tracing", +] + +[[package]] +name = "aws-sdk-ssooidc" +version = "1.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7062a779685cbf3b2401eb36151e2c6589fd5f3569b8a6bc2d199e5aaa1d059" +dependencies = [ + "aws-credential-types", + "aws-runtime", + "aws-smithy-async", + "aws-smithy-http", + "aws-smithy-json", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-types", + "bytes", + "http 0.2.12", + "once_cell", + "regex-lite", + "tracing", +] + +[[package]] +name = "aws-sdk-sts" +version = "1.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "299dae7b1dc0ee50434453fa5a229dc4b22bd3ee50409ff16becf1f7346e0193" +dependencies = [ + "aws-credential-types", + "aws-runtime", + "aws-smithy-async", + "aws-smithy-http", + "aws-smithy-json", + "aws-smithy-query", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-smithy-xml", + "aws-types", + "http 0.2.12", + "once_cell", + "regex-lite", + "tracing", +] + +[[package]] +name = "aws-sigv4" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d3820e0c08d0737872ff3c7c1f21ebbb6693d832312d6152bf18ef50a5471c2" +dependencies = [ + "aws-credential-types", + "aws-smithy-eventstream", + "aws-smithy-http", + "aws-smithy-runtime-api", + "aws-smithy-types", + "bytes", + "crypto-bigint 0.5.5", + "form_urlencoded", + "hex", + "hmac", + "http 0.2.12", + "http 1.2.0", + "once_cell", + "p256", + "percent-encoding", + "ring 0.17.8", + "sha2", + "subtle", + "time", + "tracing", + "zeroize", +] + +[[package]] +name = "aws-smithy-async" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aa8ff1492fd9fb99ae28e8467af0dbbb7c31512b16fabf1a0f10d7bb6ef78bb" +dependencies = [ + "futures-util", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "aws-smithy-checksums" +version = "0.60.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1a71073fca26775c8b5189175ea8863afb1c9ea2cceb02a5de5ad9dfbaa795" +dependencies = [ + "aws-smithy-http", + "aws-smithy-types", + "bytes", + "crc32c", + "crc32fast", + "hex", + "http 0.2.12", + "http-body 0.4.6", + "md-5", + "pin-project-lite", + "sha1", + "sha2", + "tracing", +] + +[[package]] +name = "aws-smithy-eventstream" +version = "0.60.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cef7d0a272725f87e51ba2bf89f8c21e4df61b9e49ae1ac367a6d69916ef7c90" +dependencies = [ + "aws-smithy-types", + "bytes", + "crc32fast", +] + +[[package]] +name = "aws-smithy-http" +version = "0.60.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8bc3e8fdc6b8d07d976e301c02fe553f72a39b7a9fea820e023268467d7ab6" +dependencies = [ + "aws-smithy-eventstream", + "aws-smithy-runtime-api", + "aws-smithy-types", + "bytes", + "bytes-utils", + "futures-core", + "http 0.2.12", + "http-body 0.4.6", + "once_cell", + "percent-encoding", + "pin-project-lite", + "pin-utils", + "tracing", +] + +[[package]] +name = "aws-smithy-json" +version = "0.61.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4e69cc50921eb913c6b662f8d909131bb3e6ad6cb6090d3a39b66fc5c52095" +dependencies = [ + "aws-smithy-types", +] + +[[package]] +name = "aws-smithy-query" +version = "0.60.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fbd61ceb3fe8a1cb7352e42689cec5335833cd9f94103a61e98f9bb61c64bb" +dependencies = [ + "aws-smithy-types", + "urlencoding", +] + +[[package]] +name = "aws-smithy-runtime" +version = "1.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "431a10d0e07e09091284ef04453dae4069283aa108d209974d67e77ae1caa658" +dependencies = [ + "aws-smithy-async", + "aws-smithy-http", + "aws-smithy-runtime-api", + "aws-smithy-types", + "bytes", + "fastrand 2.3.0", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "http-body 1.0.1", + "httparse", + "hyper 0.14.32", + "hyper-rustls 0.24.2", + "once_cell", + "pin-project-lite", + "pin-utils", + "rustls 0.21.12", + "tokio", + "tracing", +] + +[[package]] +name = "aws-smithy-runtime-api" +version = "1.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92165296a47a812b267b4f41032ff8069ab7ff783696d217f0994a0d7ab585cd" +dependencies = [ + "aws-smithy-async", + "aws-smithy-types", + "bytes", + "http 0.2.12", + "http 1.2.0", + "pin-project-lite", + "tokio", + "tracing", + "zeroize", +] + +[[package]] +name = "aws-smithy-types" +version = "1.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecbf4d5dfb169812e2b240a4350f15ad3c6b03a54074e5712818801615f2dc5" +dependencies = [ + "base64-simd", + "bytes", + "bytes-utils", + "futures-core", + "http 0.2.12", + "http 1.2.0", + "http-body 0.4.6", + "http-body 1.0.1", + "http-body-util", + "itoa 1.0.14", + "num-integer", + "pin-project-lite", + "pin-utils", + "ryu", + "serde", + "time", + "tokio", + "tokio-util", +] + +[[package]] +name = "aws-smithy-xml" +version = "0.60.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab0b0166827aa700d3dc519f72f8b3a91c35d0b8d042dc5d643a91e6f80648fc" +dependencies = [ + "xmlparser", +] + +[[package]] +name = "aws-types" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5221b91b3e441e6675310829fd8984801b772cb1546ef6c0e54dec9f1ac13fef" +dependencies = [ + "aws-credential-types", + "aws-smithy-async", + "aws-smithy-runtime-api", + "aws-smithy-types", + "rustc_version", + "tracing", +] + [[package]] name = "axum" version = "0.6.20" @@ -634,6 +1008,7 @@ dependencies = [ "matchit", "memchr", "mime", + "multer", "percent-encoding", "pin-project-lite", "rustversion", @@ -742,6 +1117,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + [[package]] name = "base64" version = "0.13.1" @@ -760,6 +1141,16 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64-simd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339abbe78e73178762e23bea9dfd08e697eb3f3301cd4be981c0f78ba5859195" +dependencies = [ + "outref", + "vsimd", +] + [[package]] name = "base64ct" version = "1.6.0" @@ -1063,6 +1454,16 @@ dependencies = [ "serde", ] +[[package]] +name = "bytes-utils" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dafe3a8757b027e2be6e4e5601ed563c55989fcf1546e933c66c8eb3a058d35" +dependencies = [ + "bytes", + "either", +] + [[package]] name = "cairo-rs" version = "0.18.5" @@ -2077,6 +2478,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" +[[package]] +name = "crc32c" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a47af21622d091a8f0fb295b88bc886ac74efcc613efc19f5d0b21de5c89e47" +dependencies = [ + "rustc_version", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -2182,6 +2592,28 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-bigint" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -2502,6 +2934,16 @@ dependencies = [ "uuid 1.11.0", ] +[[package]] +name = "der" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "der" version = "0.7.9" @@ -2901,6 +3343,18 @@ dependencies = [ "reborrow", ] +[[package]] +name = "ecdsa" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +dependencies = [ + "der 0.6.1", + "elliptic-curve", + "rfc6979", + "signature 1.6.4", +] + [[package]] name = "either" version = "1.13.0" @@ -2910,6 +3364,26 @@ dependencies = [ "serde", ] +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct", + "crypto-bigint 0.4.9", + "der 0.6.1", + "digest", + "ff", + "generic-array", + "group", + "pkcs8 0.9.0", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "embed-resource" version = "2.5.1" @@ -3168,6 +3642,16 @@ dependencies = [ "log", ] +[[package]] +name = "ff" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "ffmpeg-next" version = "7.1.0" @@ -3988,6 +4472,17 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "group" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "gtk" version = "0.18.2" @@ -6566,12 +7061,29 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "outref" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4030760ffd992bef45b0ae3f10ce1aba99e33464c90d14dd7c039884963ddc7a" + [[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "p256" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51f44edd08f51e2ade572f141051021c5af22677e42b7dd28a88155151c33594" +dependencies = [ + "ecdsa", + "elliptic-curve", + "sha2", +] + [[package]] name = "pango" version = "0.18.3" @@ -6935,9 +7447,19 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" dependencies = [ - "der", - "pkcs8", - "spki", + "der 0.7.9", + "pkcs8 0.10.2", + "spki 0.7.3", +] + +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der 0.6.1", + "spki 0.6.0", ] [[package]] @@ -6946,8 +7468,8 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der", - "spki", + "der 0.7.9", + "spki 0.7.3", ] [[package]] @@ -7622,6 +8144,12 @@ dependencies = [ "regex-syntax 0.8.5", ] +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + [[package]] name = "regex-syntax" version = "0.6.29" @@ -7841,6 +8369,17 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "rfc6979" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +dependencies = [ + "crypto-bigint 0.4.9", + "hmac", + "zeroize", +] + [[package]] name = "rfd" version = "0.15.0" @@ -8002,10 +8541,10 @@ dependencies = [ "num-integer", "num-traits", "pkcs1", - "pkcs8", + "pkcs8 0.10.2", "rand_core 0.6.4", - "signature", - "spki", + "signature 2.2.0", + "spki 0.7.3", "subtle", "zeroize", ] @@ -8217,6 +8756,17 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "s3" +version = "0.1.0" +dependencies = [ + "aws-config", + "aws-credential-types", + "aws-sdk-s3", + "thiserror 2.0.9", + "tokio", +] + [[package]] name = "safetensors" version = "0.4.5" @@ -8393,6 +8943,20 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct", + "der 0.6.1", + "generic-array", + "pkcs8 0.9.0", + "subtle", + "zeroize", +] + [[package]] name = "secrecy" version = "0.8.0" @@ -9110,6 +9674,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + [[package]] name = "signature" version = "2.2.0" @@ -9346,6 +9920,16 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der 0.6.1", +] + [[package]] name = "spki" version = "0.7.3" @@ -9353,7 +9937,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der", + "der 0.7.9", ] [[package]] @@ -11613,6 +12197,12 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vsimd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" + [[package]] name = "vswhom" version = "0.1.0" @@ -12714,6 +13304,12 @@ version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" +[[package]] +name = "xmlparser" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" + [[package]] name = "yansi-term" version = "0.1.2" diff --git a/apps/server/Cargo.toml b/apps/server/Cargo.toml index 0cb3668b0c..5bc6e79f49 100644 --- a/apps/server/Cargo.toml +++ b/apps/server/Cargo.toml @@ -17,7 +17,7 @@ shuttle-stt = { path = "../../crates/shuttle-stt" } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } futures = { workspace = true } -axum = { version = "0.7.4", features = ["ws"] } +axum = { version = "0.7.4", features = ["ws", "multipart"] } tower-http = { version = "0.6.2", features = ["fs", "timeout"] } reqwest = "0.12.9" async-openai = { version = "0.26.0", default-features = false } diff --git a/crates/s3/Cargo.toml b/crates/s3/Cargo.toml new file mode 100644 index 0000000000..09fb6e01c3 --- /dev/null +++ b/crates/s3/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "s3" +version = "0.1.0" +edition = "2021" + +[dependencies] +thiserror = { workspace = true } +aws-sdk-s3 = { version = "1.66.0", features = ["behavior-version-latest"] } +aws-config = { version = "1.5.11", features = ["behavior-version-latest"] } +aws-credential-types = { version = "1.2.1", features = [ + "hardcoded-credentials", +] } + +[dev-dependencies] +tokio = { workspace = true, features = ["macros", "rt"] } diff --git a/crates/s3/src/lib.rs b/crates/s3/src/lib.rs new file mode 100644 index 0000000000..779259aae3 --- /dev/null +++ b/crates/s3/src/lib.rs @@ -0,0 +1,78 @@ +use std::ops::Deref; + +pub struct Client { + s3: aws_sdk_s3::Client, +} + +pub struct UserClient<'a> { + client: &'a Client, + user_id: String, +} + +pub struct Config {} + +impl Client { + pub async fn new(_config: Config) -> Self { + let endpoint_url = "https://fly.storage.tigris.dev"; + let access_key_id = "TODO"; + let secret_access_key = "TODO"; + + let creds = + aws_credential_types::Credentials::from_keys(access_key_id, secret_access_key, None); + + let cfg = aws_config::from_env() + .endpoint_url(endpoint_url) + // https://www.tigrisdata.com/docs/concepts/regions/ + .region(aws_config::Region::new("auto")) + .credentials_provider(creds) + .load() + .await; + + let s3 = aws_sdk_s3::Client::new(&cfg); + + Self { s3 } + } + + pub fn for_user<'a>(&'a self, user_id: impl Into) -> UserClient<'a> { + UserClient { + client: self, + user_id: user_id.into(), + } + } +} + +impl<'a> Deref for UserClient<'a> { + type Target = aws_sdk_s3::Client; + + fn deref(&self) -> &Self::Target { + &self.client.s3 + } +} + +impl<'a> UserClient<'a> { + pub async fn get(&self) { + let _ = self + .get_object() + .bucket(self.user_id.to_string()) + .key("test") + .send() + .await; + } + + pub async fn put(&self) {} + + pub async fn delete(&self) {} + + pub async fn delete_all(&self) {} +} + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn test_client() { + let client = Client::new(Config {}).await; + client.for_user("123").get().await; + } +} From c81a2f91a122e6abb2cad5c0ba25722e456e996a Mon Sep 17 00:00:00 2001 From: yujonglee Date: Fri, 27 Dec 2024 07:42:45 +0900 Subject: [PATCH 2/4] bunch of deps update --- Cargo.lock | 412 +++++++++++++++++++++++++++++- Cargo.toml | 1 + apps/desktop/src-tauri/Cargo.toml | 2 +- apps/server/Cargo.toml | 3 +- crates/cloud/Cargo.toml | 2 +- crates/db/Cargo.toml | 7 + crates/db/src/lib.rs | 17 ++ crates/diarizer/Cargo.toml | 2 +- crates/turso/Cargo.toml | 7 + crates/turso/src/lib.rs | 1 + 10 files changed, 442 insertions(+), 12 deletions(-) create mode 100644 crates/db/Cargo.toml create mode 100644 crates/db/src/lib.rs create mode 100644 crates/turso/Cargo.toml create mode 100644 crates/turso/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index fce331b9cb..f60f2a3d71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,6 +33,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if 1.0.0", + "cipher", + "cpufeatures", +] + [[package]] name = "ahash" version = "0.7.8" @@ -1157,6 +1168,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bindgen" version = "0.56.0" @@ -1177,7 +1197,30 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex 0.1.1", - "which", + "which 3.1.1", +] + +[[package]] +name = "bindgen" +version = "0.66.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" +dependencies = [ + "bitflags 2.6.0", + "cexpr 0.6.0", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex 1.3.0", + "syn 2.0.91", + "which 4.4.2", ] [[package]] @@ -1297,6 +1340,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-padding" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +dependencies = [ + "generic-array", +] + [[package]] name = "block2" version = "0.5.1" @@ -1833,6 +1885,15 @@ dependencies = [ "toml 0.8.2", ] +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.2.5" @@ -1957,6 +2018,16 @@ name = "cidre-macros" version = "0.1.0" source = "git+https://github.com/yury/cidre?rev=23efaabee6bf75bfb57a9e7739b2beb83cb93942#23efaabee6bf75bfb57a9e7739b2beb83cb93942" +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "clang-sys" version = "1.8.1" @@ -2853,6 +2924,13 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "db" +version = "0.1.0" +dependencies = [ + "libsql", +] + [[package]] name = "db-client" version = "0.1.0" @@ -3598,6 +3676,18 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "fancy-regex" version = "0.13.0" @@ -4626,6 +4716,15 @@ dependencies = [ "foldhash", ] +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown 0.14.5", +] + [[package]] name = "hashlink" version = "0.9.1" @@ -4864,6 +4963,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" + [[package]] name = "http-range-header" version = "0.4.2" @@ -4965,11 +5070,29 @@ dependencies = [ "hyper 0.14.32", "log", "rustls 0.21.12", - "rustls-native-certs", + "rustls-native-certs 0.6.3", "tokio", "tokio-rustls 0.24.1", ] +[[package]] +name = "hyper-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "399c78f9338483cb7e630c8474b07268983c6bd5acee012e4211f9f7bb21b070" +dependencies = [ + "futures-util", + "http 0.2.12", + "hyper 0.14.32", + "log", + "rustls 0.22.4", + "rustls-native-certs 0.7.3", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.25.0", + "webpki-roots 0.26.7", +] + [[package]] name = "hyper-rustls" version = "0.27.5" @@ -5192,6 +5315,16 @@ dependencies = [ "cfb", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "block-padding", + "generic-array", +] + [[package]] name = "instant" version = "0.1.13" @@ -5688,6 +5821,138 @@ dependencies = [ "system-deps", ] +[[package]] +name = "libsql" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe18646e4ef8db446bc3e3f5fb96131483203bc5f4998ff149f79a067530c01c" +dependencies = [ + "anyhow", + "async-stream", + "async-trait", + "base64 0.21.7", + "bincode", + "bitflags 2.6.0", + "bytes", + "fallible-iterator 0.3.0", + "futures", + "http 0.2.12", + "hyper 0.14.32", + "hyper-rustls 0.25.0", + "libsql-hrana", + "libsql-sqlite3-parser", + "libsql-sys", + "libsql_replication", + "parking_lot 0.12.3", + "serde", + "serde_json", + "thiserror 1.0.69", + "tokio", + "tokio-stream", + "tokio-util", + "tonic 0.11.0", + "tonic-web", + "tower 0.4.13", + "tower-http 0.4.4", + "tracing", + "uuid 1.11.0", + "zerocopy", +] + +[[package]] +name = "libsql-ffi" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f2a50a585a1184a43621a9133b7702ba5cb7a87ca5e704056b19d8005de6faf" +dependencies = [ + "bindgen 0.66.1", + "cc", +] + +[[package]] +name = "libsql-hrana" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeaf5d19e365465e1c23d687a28c805d7462531b3f619f0ba49d3cf369890a3e" +dependencies = [ + "base64 0.21.7", + "bytes", + "prost 0.12.6", + "serde", +] + +[[package]] +name = "libsql-rusqlite" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae65c66088dcd309abbd5617ae046abac2a2ee0a7fdada5127353bd68e0a27ea" +dependencies = [ + "bitflags 2.6.0", + "fallible-iterator 0.2.0", + "fallible-streaming-iterator", + "hashlink 0.8.4", + "libsql-ffi", + "smallvec", +] + +[[package]] +name = "libsql-sqlite3-parser" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a90128c708356af8f7d767c9ac2946692c9112b4f74f07b99a01a60680e413" +dependencies = [ + "bitflags 2.6.0", + "cc", + "fallible-iterator 0.3.0", + "indexmap 2.7.0", + "log", + "memchr", + "phf 0.11.2", + "phf_codegen 0.11.2", + "phf_shared 0.11.2", + "uncased", +] + +[[package]] +name = "libsql-sys" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c05b61c226781d6f5e26e3e7364617f19c0c1d5332035802e9229d6024cec05" +dependencies = [ + "bytes", + "libsql-ffi", + "libsql-rusqlite", + "once_cell", + "tracing", + "zerocopy", +] + +[[package]] +name = "libsql_replication" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf40c4c2c01462da758272976de0a23d19b4e9c714db08efecf262d896655b5" +dependencies = [ + "aes", + "async-stream", + "async-trait", + "bytes", + "cbc", + "libsql-rusqlite", + "libsql-sys", + "parking_lot 0.12.3", + "prost 0.12.6", + "serde", + "thiserror 1.0.69", + "tokio", + "tokio-stream", + "tokio-util", + "tonic 0.11.0", + "tracing", + "uuid 1.11.0", + "zerocopy", +] + [[package]] name = "libsqlite3-sys" version = "0.30.1" @@ -7286,6 +7551,16 @@ dependencies = [ "phf_shared 0.10.0", ] +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + [[package]] name = "phf_generator" version = "0.8.0" @@ -7368,6 +7643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ "siphasher", + "uncased", ] [[package]] @@ -7556,7 +7832,7 @@ dependencies = [ "base64 0.21.7", "byteorder", "bytes", - "fallible-iterator", + "fallible-iterator 0.2.0", "hmac", "md-5", "memchr", @@ -7572,7 +7848,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d2234cdee9408b523530a9b6d2d6b373d1db34f6a8e51dc03ded1828d7fb67c" dependencies = [ "bytes", - "fallible-iterator", + "fallible-iterator 0.2.0", "postgres-protocol", ] @@ -8669,6 +8945,19 @@ dependencies = [ "security-framework", ] +[[package]] +name = "rustls-native-certs" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5bfb394eeed242e909609f56089eecfe5fda225042e8b171791b9c95f5931e5" +dependencies = [ + "openssl-probe", + "rustls-pemfile 2.2.0", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -9378,6 +9667,7 @@ dependencies = [ "db-server", "futures", "reqwest 0.12.9", + "s3", "schemars 1.0.0-alpha.17", "sentry", "serde", @@ -9390,7 +9680,7 @@ dependencies = [ "shuttle-stt", "sqlx", "tokio", - "tower-http", + "tower-http 0.6.2", ] [[package]] @@ -9994,7 +10284,7 @@ dependencies = [ "futures-io", "futures-util", "hashbrown 0.14.5", - "hashlink", + "hashlink 0.9.1", "hex", "indexmap 2.7.0", "log", @@ -11363,7 +11653,7 @@ dependencies = [ "async-trait", "byteorder", "bytes", - "fallible-iterator", + "fallible-iterator 0.2.0", "futures-channel", "futures-util", "log", @@ -11390,6 +11680,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls 0.22.4", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.1" @@ -11551,6 +11852,33 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" +dependencies = [ + "async-stream", + "async-trait", + "axum 0.6.20", + "base64 0.21.7", + "bytes", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.32", + "hyper-timeout 0.4.1", + "percent-encoding", + "pin-project", + "prost 0.12.6", + "tokio", + "tokio-stream", + "tower 0.4.13", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tonic" version = "0.12.3" @@ -11597,6 +11925,26 @@ dependencies = [ "syn 2.0.91", ] +[[package]] +name = "tonic-web" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc3b0e1cedbf19fdfb78ef3d672cb9928e0a91a9cb4629cc0c916e8cff8aaaa1" +dependencies = [ + "base64 0.21.7", + "bytes", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.32", + "pin-project", + "tokio-stream", + "tonic 0.11.0", + "tower-http 0.4.4", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -11633,6 +11981,26 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower-http" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" +dependencies = [ + "bitflags 2.6.0", + "bytes", + "futures-core", + "futures-util", + "http 0.2.12", + "http-body 0.4.6", + "http-range-header 0.3.1", + "pin-project-lite", + "tower 0.4.13", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-http" version = "0.6.2" @@ -11645,7 +12013,7 @@ dependencies = [ "http 1.2.0", "http-body 1.0.1", "http-body-util", - "http-range-header", + "http-range-header 0.4.2", "httpdate", "mime", "mime_guess", @@ -11853,6 +12221,13 @@ dependencies = [ "utf-8", ] +[[package]] +name = "turso" +version = "0.1.0" +dependencies = [ + "reqwest 0.12.9", +] + [[package]] name = "typeid" version = "1.0.2" @@ -11935,6 +12310,15 @@ dependencies = [ "libc", ] +[[package]] +name = "uncased" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b88fcfe09e89d3866a5c11019378088af2d24c3fbd4f0543f96b479ec90697" +dependencies = [ + "version_check", +] + [[package]] name = "unic-char-property" version = "0.9.0" @@ -12667,6 +13051,18 @@ dependencies = [ "libc", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "whoami" version = "1.5.2" diff --git a/Cargo.toml b/Cargo.toml index 8ff9c64f40..fc615049c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ futures-core = "0.3.31" futures-util = "0.3.31" futures-channel = "0.3.31" tokio-stream = "0.1.17" +reqwest = "0.12" anyhow = "1" thiserror = "2" diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 0db229b65d..106cd22371 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -50,7 +50,7 @@ uuid = { workspace = true } dotenvy_macro = "0.15.7" log = "0.4.22" -reqwest = { version = "0.12", features = ["stream"] } +reqwest = { workspace = true, features = ["json", "stream"] } tokio = { workspace = true, features = ["rt", "macros"] } futures = { workspace = true } diff --git a/apps/server/Cargo.toml b/apps/server/Cargo.toml index 5bc6e79f49..77a0644c0e 100644 --- a/apps/server/Cargo.toml +++ b/apps/server/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] hypr-bridge = { path = "../../crates/bridge", package = "bridge" } hypr-db-server = { path = "../../crates/db-server", package = "db-server" } +hypr-s3 = { path = "../../crates/s3", package = "s3" } shuttle-axum = "0.49.0" shuttle-runtime = "0.49.0" @@ -16,10 +17,10 @@ shuttle-stt = { path = "../../crates/shuttle-stt" } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } futures = { workspace = true } +reqwest = { workspace = true, features = ["json"] } axum = { version = "0.7.4", features = ["ws", "multipart"] } tower-http = { version = "0.6.2", features = ["fs", "timeout"] } -reqwest = "0.12.9" async-openai = { version = "0.26.0", default-features = false } sentry = { workspace = true } sqlx = { workspace = true, features = [ diff --git a/crates/cloud/Cargo.toml b/crates/cloud/Cargo.toml index 164f97ebd9..e4cf4595e7 100644 --- a/crates/cloud/Cargo.toml +++ b/crates/cloud/Cargo.toml @@ -10,6 +10,6 @@ anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } url = "2" -reqwest = { version = "0.12.9", features = ["json"] } +reqwest = { workspace = true, features = ["json"] } tokio-tungstenite = { version = "0.26.0", features = ["native-tls-vendored"] } futures-util = "0.3.31" diff --git a/crates/db/Cargo.toml b/crates/db/Cargo.toml new file mode 100644 index 0000000000..aaa96e800b --- /dev/null +++ b/crates/db/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "db" +version = "0.1.0" +edition = "2021" + +[dependencies] +libsql = "0.6.0" diff --git a/crates/db/src/lib.rs b/crates/db/src/lib.rs new file mode 100644 index 0000000000..cabb1d1203 --- /dev/null +++ b/crates/db/src/lib.rs @@ -0,0 +1,17 @@ +// https://github.com/tursodatabase/libsql/tree/main/libsql/examples + +pub async fn exploring() { + let db_path = "test.db".to_string(); + let sync_url = "https://localhost:50051".to_string(); + let auth_token = "test".to_string(); + + let db = libsql::Builder::new_remote_replica(db_path, sync_url, auth_token) + .build() + .await + .unwrap(); + + let conn = db.connect().unwrap(); + + let _rows = conn.query("SELECT * FROM test", ()).await.unwrap(); + // println!("{:?}", rows); +} diff --git a/crates/diarizer/Cargo.toml b/crates/diarizer/Cargo.toml index c4a77412f8..d8f19f281f 100644 --- a/crates/diarizer/Cargo.toml +++ b/crates/diarizer/Cargo.toml @@ -10,6 +10,6 @@ ndarray = { workspace = true } ort = { workspace = true, features = ["coreml"] } [dev-dependencies] -reqwest = "0.12" +reqwest = { workspace = true } hound = "3.5.1" approx = "0.5.1" diff --git a/crates/turso/Cargo.toml b/crates/turso/Cargo.toml new file mode 100644 index 0000000000..dbf923343a --- /dev/null +++ b/crates/turso/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "turso" +version = "0.1.0" +edition = "2021" + +[dependencies] +reqwest = { workspace = true, features = ["json"] } diff --git a/crates/turso/src/lib.rs b/crates/turso/src/lib.rs new file mode 100644 index 0000000000..8572de5a5e --- /dev/null +++ b/crates/turso/src/lib.rs @@ -0,0 +1 @@ +// https://docs.turso.tech/api-reference/databases/list From 1ed447d2e6685ac022746082afb7a838fad7494a Mon Sep 17 00:00:00 2001 From: yujonglee Date: Fri, 27 Dec 2024 08:29:17 +0900 Subject: [PATCH 3/4] simple test passed --- crates/s3/docker-compose.yaml | 20 +++++ crates/s3/src/lib.rs | 133 ++++++++++++++++++++++++++++------ 2 files changed, 131 insertions(+), 22 deletions(-) create mode 100644 crates/s3/docker-compose.yaml diff --git a/crates/s3/docker-compose.yaml b/crates/s3/docker-compose.yaml new file mode 100644 index 0000000000..a4f5190413 --- /dev/null +++ b/crates/s3/docker-compose.yaml @@ -0,0 +1,20 @@ +version: '3.8' +services: + minio: + image: minio/minio:RELEASE.2024-12-18T13-15-44Z + ports: + - "9000:9000" + - "9001:9001" + environment: + MINIO_ROOT_USER: minio-user + MINIO_ROOT_PASSWORD: minio-password + command: server /data --console-address ":9001" + volumes: + - minio_data:/data + healthcheck: + test: ["CMD", "mc", "ready", "local"] + interval: 5s + timeout: 5s + retries: 5 +volumes: + minio_data: diff --git a/crates/s3/src/lib.rs b/crates/s3/src/lib.rs index 779259aae3..601c05267f 100644 --- a/crates/s3/src/lib.rs +++ b/crates/s3/src/lib.rs @@ -1,7 +1,15 @@ use std::ops::Deref; +use aws_sdk_s3::error::SdkError; +use aws_sdk_s3::operation::create_bucket::CreateBucketError; +use aws_sdk_s3::operation::delete_object::DeleteObjectError; +use aws_sdk_s3::operation::get_object::GetObjectError; +use aws_sdk_s3::operation::put_object::PutObjectError; +use aws_sdk_s3::primitives::{AggregatedBytes, ByteStreamError}; + pub struct Client { s3: aws_sdk_s3::Client, + bucket: String, } pub struct UserClient<'a> { @@ -9,19 +17,37 @@ pub struct UserClient<'a> { user_id: String, } -pub struct Config {} +pub struct Config { + pub endpoint_url: String, + pub bucket: String, + pub access_key_id: String, + pub secret_access_key: String, +} -impl Client { - pub async fn new(_config: Config) -> Self { - let endpoint_url = "https://fly.storage.tigris.dev"; - let access_key_id = "TODO"; - let secret_access_key = "TODO"; +#[derive(Debug, thiserror::Error)] +pub enum ApiError { + #[error("Error while deleting object: {0}")] + DeleteObjectError(#[from] SdkError), + #[error("Error while getting object: {0}")] + GetObjectError(#[from] SdkError), + #[error("Error while putting object: {0}")] + PutObjectError(#[from] SdkError), + #[error("Error while creating bucket: {0}")] + CreateBucketError(#[from] SdkError), + #[error("Error while collecting bytes: {0}")] + CollectBytesError(#[from] ByteStreamError), +} - let creds = - aws_credential_types::Credentials::from_keys(access_key_id, secret_access_key, None); +impl Client { + pub async fn new(config: Config) -> Self { + let creds = aws_credential_types::Credentials::from_keys( + config.access_key_id, + config.secret_access_key, + None, + ); let cfg = aws_config::from_env() - .endpoint_url(endpoint_url) + .endpoint_url(config.endpoint_url) // https://www.tigrisdata.com/docs/concepts/regions/ .region(aws_config::Region::new("auto")) .credentials_provider(creds) @@ -30,7 +56,10 @@ impl Client { let s3 = aws_sdk_s3::Client::new(&cfg); - Self { s3 } + Self { + s3, + bucket: config.bucket, + } } pub fn for_user<'a>(&'a self, user_id: impl Into) -> UserClient<'a> { @@ -39,40 +68,100 @@ impl Client { user_id: user_id.into(), } } + + pub async fn create_bucket(&self) -> Result<(), ApiError> { + let _ = self.s3.create_bucket().bucket(&self.bucket).send().await?; + Ok(()) + } } impl<'a> Deref for UserClient<'a> { - type Target = aws_sdk_s3::Client; + type Target = Client; fn deref(&self) -> &Self::Target { - &self.client.s3 + &self.client } } impl<'a> UserClient<'a> { - pub async fn get(&self) { - let _ = self + fn folder(&self) -> String { + format!("user_{}", self.user_id) + } + + pub async fn get(&self, file_name: &str) -> Result { + let res = self + .s3 .get_object() - .bucket(self.user_id.to_string()) - .key("test") + .bucket(&self.bucket) + .key(format!("{}/{}", self.folder(), file_name)) .send() - .await; + .await?; + + let data = res.body.collect().await?; + Ok(data) } - pub async fn put(&self) {} + pub async fn put( + &self, + file_name: &str, + content: impl Into, + ) -> Result<(), ApiError> { + let _ = self + .s3 + .put_object() + .bucket(&self.bucket) + .key(format!("{}/{}", self.folder(), file_name)) + .body(content.into()) + .content_type("audio/mpeg") + .send() + .await?; + + Ok(()) + } - pub async fn delete(&self) {} + pub async fn delete(&self, file_name: &str) -> Result<(), ApiError> { + let _ = self + .s3 + .delete_object() + .bucket(&self.bucket) + .key(format!("{}/{}", self.folder(), file_name)) + .send() + .await?; - pub async fn delete_all(&self) {} + Ok(()) + } } #[cfg(test)] mod tests { use super::*; + #[ignore] #[tokio::test] async fn test_client() { - let client = Client::new(Config {}).await; - client.for_user("123").get().await; + let endpoint_url = "http://127.0.0.1:9000"; + let access_key_id = "minio-user"; + let secret_access_key = "minio-password"; + + let client = Client::new(Config { + endpoint_url: endpoint_url.to_string(), + bucket: "hyprnote".to_string(), + access_key_id: access_key_id.to_string(), + secret_access_key: secret_access_key.to_string(), + }) + .await; + + // client.create_bucket().await.unwrap(); + + let user_client = client.for_user("123"); + + user_client + .put("test.mp3", "test".as_bytes().to_vec()) + .await + .unwrap(); + + let res = user_client.get("test.mp3").await.unwrap(); + let data = res.into_bytes(); + assert_eq!(data, "test".as_bytes()); } } From 04ebcc6c38a8a6c0e2d5f191624826e850fefcd0 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Fri, 27 Dec 2024 09:48:29 +0900 Subject: [PATCH 4/4] small fixes --- crates/s3/docker-compose.yaml | 4 ---- crates/s3/src/lib.rs | 13 ++++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/s3/docker-compose.yaml b/crates/s3/docker-compose.yaml index a4f5190413..6d6608aa1f 100644 --- a/crates/s3/docker-compose.yaml +++ b/crates/s3/docker-compose.yaml @@ -9,12 +9,8 @@ services: MINIO_ROOT_USER: minio-user MINIO_ROOT_PASSWORD: minio-password command: server /data --console-address ":9001" - volumes: - - minio_data:/data healthcheck: test: ["CMD", "mc", "ready", "local"] interval: 5s timeout: 5s retries: 5 -volumes: - minio_data: diff --git a/crates/s3/src/lib.rs b/crates/s3/src/lib.rs index 601c05267f..9fcd92dc8b 100644 --- a/crates/s3/src/lib.rs +++ b/crates/s3/src/lib.rs @@ -69,6 +69,15 @@ impl Client { } } + pub async fn get_bucket(&self) -> bool { + self.s3 + .head_bucket() + .bucket(&self.bucket) + .send() + .await + .is_ok() + } + pub async fn create_bucket(&self) -> Result<(), ApiError> { let _ = self.s3.create_bucket().bucket(&self.bucket).send().await?; Ok(()) @@ -151,7 +160,9 @@ mod tests { }) .await; - // client.create_bucket().await.unwrap(); + if !client.get_bucket().await { + client.create_bucket().await.unwrap(); + } let user_client = client.for_user("123");