Compare commits

..
2 Commits
Author SHA1 Message Date
phoenix a29a9fa9f7 Cleanup 2026-07-22 17:10:36 -04:00
phoenix ceeec1d2cb Adding some code to upload object 2026-07-22 17:02:19 -04:00
3 changed files with 55 additions and 10 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ license = "MIT"
description = "Library for managing soaricarus storage"
[dependencies]
aws-config = { version = "1.9.0" }
aws-config = { version = "1.9.0", features = ["behavior-version-latest"] }
aws-sdk-s3 = { version = "1.138.1" }
time = "0.3.53"
tokio = { version = "1.53.0", features = ["full"] }
+5
View File
@@ -0,0 +1,5 @@
pub struct Config {
pub url: String,
pub bucket: String,
pub region: String,
}
+49 -9
View File
@@ -1,14 +1,54 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
pub mod config;
#[derive(Default)]
pub struct Data {
pub filepath: String,
pub raw_data: Vec<u8>,
}
#[cfg(test)]
mod tests {
use super::*;
pub struct Labyrinth {
pub config: config::Config,
}
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
pub async fn load_data(filepath: &str) -> Result<Vec<u8>, std::io::Error> {
tokio::fs::read(filepath).await
}
pub enum Error {
Info(String),
SError(aws_sdk_s3::operation::put_object::PutObjectError),
}
impl Labyrinth {
pub async fn upload(
&self,
file_key: &str,
data: &Data,
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
let config = aws_config::load_from_env().await;
let client = aws_sdk_s3::Client::new(&config);
let data_content = if data.raw_data.is_empty() {
match load_data(&data.filepath).await {
Ok(content) => content,
Err(err) => return Err(Error::Info(err.to_string())),
}
} else {
data.raw_data.to_owned()
};
let body = aws_sdk_s3::primitives::SdkBody::from(data_content);
let b_stream = aws_sdk_s3::primitives::ByteStream::from(body);
match client
.put_object()
.bucket(self.config.bucket.clone())
.key(file_key)
.body(b_stream)
.send()
.await
{
Ok(response) => Ok(response),
Err(err) => Err(Error::Info(err.to_string())),
}
}
}