Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,096 changes: 1,044 additions & 52 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
5 changes: 3 additions & 2 deletions apps/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
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 = [
Expand Down
2 changes: 1 addition & 1 deletion crates/cloud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 7 additions & 0 deletions crates/db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "db"
version = "0.1.0"
edition = "2021"

[dependencies]
libsql = "0.6.0"
17 changes: 17 additions & 0 deletions crates/db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion crates/diarizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 15 additions & 0 deletions crates/s3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
16 changes: 16 additions & 0 deletions crates/s3/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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"
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 5s
timeout: 5s
retries: 5
178 changes: 178 additions & 0 deletions crates/s3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
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> {
client: &'a Client,
user_id: String,
}

pub struct Config {
pub endpoint_url: String,
pub bucket: String,
pub access_key_id: String,
pub secret_access_key: String,
}

#[derive(Debug, thiserror::Error)]
pub enum ApiError {
#[error("Error while deleting object: {0}")]
DeleteObjectError(#[from] SdkError<DeleteObjectError>),
#[error("Error while getting object: {0}")]
GetObjectError(#[from] SdkError<GetObjectError>),
#[error("Error while putting object: {0}")]
PutObjectError(#[from] SdkError<PutObjectError>),
#[error("Error while creating bucket: {0}")]
CreateBucketError(#[from] SdkError<CreateBucketError>),
#[error("Error while collecting bytes: {0}")]
CollectBytesError(#[from] ByteStreamError),
}

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(config.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,
bucket: config.bucket,
}
}

pub fn for_user<'a>(&'a self, user_id: impl Into<String>) -> UserClient<'a> {
UserClient {
client: self,
user_id: user_id.into(),
}
}

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(())
}
}

impl<'a> Deref for UserClient<'a> {
type Target = Client;

fn deref(&self) -> &Self::Target {
&self.client
}
}

impl<'a> UserClient<'a> {
fn folder(&self) -> String {
format!("user_{}", self.user_id)
}

pub async fn get(&self, file_name: &str) -> Result<AggregatedBytes, ApiError> {
let res = self
.s3
.get_object()
.bucket(&self.bucket)
.key(format!("{}/{}", self.folder(), file_name))
.send()
.await?;

let data = res.body.collect().await?;
Ok(data)
}

pub async fn put(
&self,
file_name: &str,
content: impl Into<aws_sdk_s3::primitives::ByteStream>,
) -> 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, file_name: &str) -> Result<(), ApiError> {
let _ = self
.s3
.delete_object()
.bucket(&self.bucket)
.key(format!("{}/{}", self.folder(), file_name))
.send()
.await?;

Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[ignore]
#[tokio::test]
async fn test_client() {
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;

if !client.get_bucket().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());
}
}
7 changes: 7 additions & 0 deletions crates/turso/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "turso"
version = "0.1.0"
edition = "2021"

[dependencies]
reqwest = { workspace = true, features = ["json"] }
1 change: 1 addition & 0 deletions crates/turso/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// https://docs.turso.tech/api-reference/databases/list
Loading