Compare commits

..
Author SHA1 Message Date
phoenix f99a77ece0 Code formatting
simodels Build / Rustfmt (pull_request) Successful in 1m21s
simodels Build / Clippy (pull_request) Successful in 1m32s
simodels Build / Check (pull_request) Successful in 1m40s
simodels Build / Test Suite (pull_request) Successful in 1m42s
labyrinth release Tagging / release (pull_request) Successful in 2m25s
simodels Build / build (pull_request) Successful in 3m7s
2026-08-11 10:20:44 -04:00
phoenix 3d3568d5a5 Added code for deleting object from storage 2026-08-11 10:20:29 -04:00
phoenix 6ed1d00a32 Download (#2)
simodels Build / Test Suite (push) Successful in 1m18s
simodels Build / build (push) Successful in 1m21s
simodels Build / Check (push) Successful in 1m25s
labyrinth release Tagging / release (push) Successful in 1m46s
simodels Build / Rustfmt (push) Successful in 1m54s
simodels Build / Clippy (push) Successful in 2m36s
Reviewed-on: #2
2026-08-10 17:41:33 -04:00
3 changed files with 51 additions and 4 deletions
Generated
+1 -1
View File
@@ -1370,7 +1370,7 @@ dependencies = [
[[package]] [[package]]
name = "labyrinth" name = "labyrinth"
version = "0.0.2" version = "0.0.3"
dependencies = [ dependencies = [
"aws-config", "aws-config",
"aws-sdk-s3", "aws-sdk-s3",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "labyrinth" name = "labyrinth"
version = "0.0.2" version = "0.0.3"
edition = "2024" edition = "2024"
license = "MIT" license = "MIT"
description = "Library for managing soaricarus storage" description = "Library for managing soaricarus storage"
+49 -2
View File
@@ -37,8 +37,7 @@ pub async fn init_client(config: &config::Config) -> aws_sdk_s3::Client {
.force_path_style(true) .force_path_style(true)
.build(); .build();
let client = aws_sdk_s3::Client::from_conf(s3_config); aws_sdk_s3::Client::from_conf(s3_config)
client
} }
#[derive(Debug)] #[derive(Debug)]
@@ -48,6 +47,7 @@ pub enum Error {
} }
impl Labyrinth { impl Labyrinth {
/// Upload object to the bucket
pub async fn upload( pub async fn upload(
&self, &self,
file_key: &str, file_key: &str,
@@ -77,4 +77,51 @@ impl Labyrinth {
Err(err) => Err(Error::Info(err.to_string())), Err(err) => Err(Error::Info(err.to_string())),
} }
} }
/// Download object from the bucket
pub async fn download(&self, file_key: &str) -> Result<Vec<u8>, Error> {
let client = init_client(&self.config).await;
match client
.get_object()
.bucket(self.config.bucket.clone())
.key(file_key)
.send()
.await
{
Ok(response) => {
let body = response.body;
// Get the body as ByteStream
match body.collect().await {
Ok(data) => {
let bytes = data.into_bytes();
let raw_data = bytes.to_vec();
Ok(raw_data)
}
Err(err) => Err(Error::Info(err.to_string())),
}
}
Err(err) => Err(Error::Info(err.to_string())),
}
}
/// Delete an object from the bucket
pub async fn delete(
&self,
file_key: &str,
) -> Result<aws_sdk_s3::operation::delete_object::DeleteObjectOutput, Error> {
let client = init_client(&self.config).await;
match client
.delete_object()
.bucket(self.config.bucket.clone())
.key(file_key)
.send()
.await
{
Ok(response) => Ok(response),
Err(err) => Err(Error::Info(err.to_string())),
}
}
} }