Cleanup
This commit is contained in:
@@ -1,13 +1,3 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
pub async fn init_config(url: &str, region: String) -> Result<aws_config::SdkConfig, std::io::Error> {
|
|
||||||
let r = region.as_str();
|
|
||||||
let config = aws_config::from_env().endpoint_url(url).region(r).load().await;
|
|
||||||
|
|
||||||
Ok(config)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub bucket: String,
|
pub bucket: String,
|
||||||
|
|||||||
+17
-41
@@ -1,37 +1,37 @@
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
|
|
||||||
// use aws_sdk_s3::config::*;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub filepath: String,
|
pub filepath: String,
|
||||||
pub raw_data: Vec<u8>
|
pub raw_data: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct Labyrinth {
|
pub struct Labyrinth {
|
||||||
pub config: config::Config,
|
pub config: config::Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn load_data(filepath: &str) -> Result<Vec<u8>, std::io::Error> {
|
||||||
|
tokio::fs::read(filepath).await
|
||||||
|
}
|
||||||
|
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Info(String),
|
Info(String),
|
||||||
SError(aws_sdk_s3::operation::put_object::PutObjectError)
|
SError(aws_sdk_s3::operation::put_object::PutObjectError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Labyrinth {
|
impl Labyrinth {
|
||||||
pub async fn upload(&self, file_key: &str, data: &Data) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
pub async fn upload(
|
||||||
// let config = aws_config::from_env().endpoint_url(&self.config.url).region("").load().await;
|
&self,
|
||||||
|
file_key: &str,
|
||||||
|
data: &Data,
|
||||||
|
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
||||||
let config = aws_config::load_from_env().await;
|
let config = aws_config::load_from_env().await;
|
||||||
let client = aws_sdk_s3::Client::new(&config);
|
let client = aws_sdk_s3::Client::new(&config);
|
||||||
|
|
||||||
let data_content = if data.raw_data.is_empty() {
|
let data_content = if data.raw_data.is_empty() {
|
||||||
match tokio::fs::read(&data.filepath).await {
|
match load_data(&data.filepath).await {
|
||||||
Ok(content) => content,
|
Ok(content) => content,
|
||||||
Err(err) => {
|
Err(err) => return Err(Error::Info(err.to_string())),
|
||||||
eprintln!("Error: {err:?}");
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data.raw_data.to_owned()
|
data.raw_data.to_owned()
|
||||||
@@ -45,34 +45,10 @@ impl Labyrinth {
|
|||||||
.key(file_key)
|
.key(file_key)
|
||||||
.body(b_stream)
|
.body(b_stream)
|
||||||
.send()
|
.send()
|
||||||
.await {
|
.await
|
||||||
Ok(response) => {
|
{
|
||||||
println!("Response: {response:?}");
|
Ok(response) => Ok(response),
|
||||||
println!("Uploaded");
|
Err(err) => Err(Error::Info(err.to_string())),
|
||||||
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error: {err:?}");
|
|
||||||
// aws_sdk_s3::error::SdkError<aws_sdk_s3::operation::put_object::PutObjectError, >
|
|
||||||
Err(Error::Info(err.to_string()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn add(left: u64, right: u64) -> u64 {
|
|
||||||
left + right
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
let result = add(2, 2);
|
|
||||||
assert_eq!(result, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user