Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84f98521c8
|
||
|
|
c7e85b3664
|
||
|
|
742393c25b
|
||
|
|
e9cb1f6c45
|
||
|
|
37d08d54fa
|
||
|
|
08e50b132f
|
||
|
|
944b6f9c75
|
||
|
|
0f5730f242
|
||
|
|
dd5ec8a5be
|
No files matched your search
@@ -1,73 +0,0 @@
|
|||||||
name: simodels Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
name: Check
|
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: 1.99
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
- run: cargo check
|
|
||||||
|
|
||||||
test:
|
|
||||||
name: Test Suite
|
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: 1.99
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
- run: cargo test
|
|
||||||
|
|
||||||
fmt:
|
|
||||||
name: Rustfmt
|
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: 1.99
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
- run: rustup component add rustfmt
|
|
||||||
- run: cargo fmt --all -- --check
|
|
||||||
|
|
||||||
clippy:
|
|
||||||
name: Clippy
|
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: 1.99
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
- run: rustup component add clippy
|
|
||||||
- run: cargo clippy -- -D warnings
|
|
||||||
|
|
||||||
build:
|
|
||||||
name: build
|
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: 1.99
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
- run: cargo build
|
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.99
|
toolchain: 1.97
|
||||||
components: cargo
|
components: cargo
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
|
|||||||
Generated
+366
-376
File diff suppressed because it is too large.
Load diff
+6
-6
@@ -1,13 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "labyrinth"
|
name = "labyrinth"
|
||||||
version = "0.0.7"
|
version = "0.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "Library for managing soaricarus storage"
|
description = "Library for managing soaricarus storage"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aws-config = { version = "1.13.0", features = ["behavior-version-latest"] }
|
aws-config = { version = "1.9.0", features = ["behavior-version-latest"] }
|
||||||
aws-sdk-s3 = { version = "1.157.0" }
|
aws-sdk-s3 = { version = "1.138.1" }
|
||||||
time = "0.3.55"
|
time = "0.3.53"
|
||||||
tokio = { version = "1.54.1", features = ["full"] }
|
tokio = { version = "1.53.0", features = ["full"] }
|
||||||
uuid = "1.27.0"
|
uuid = "1.24.0"
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2025 Kun Deng
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
+5
-52
@@ -37,7 +37,8 @@ pub async fn init_client(config: &config::Config) -> aws_sdk_s3::Client {
|
|||||||
.force_path_style(true)
|
.force_path_style(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
aws_sdk_s3::Client::from_conf(s3_config)
|
let client = aws_sdk_s3::Client::from_conf(s3_config);
|
||||||
|
client
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -47,17 +48,16 @@ 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,
|
||||||
data: &Data,
|
data: &Data,
|
||||||
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Box<Error>> {
|
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
||||||
let client = init_client(&self.config).await;
|
let client = init_client(&self.config).await;
|
||||||
let data_content = if data.raw_data.is_empty() {
|
let data_content = if data.raw_data.is_empty() {
|
||||||
match load_data(&data.filepath).await {
|
match load_data(&data.filepath).await {
|
||||||
Ok(content) => content,
|
Ok(content) => content,
|
||||||
Err(err) => return Err(Box::new(Error::Info(err.to_string()))),
|
Err(err) => return Err(Error::Info(err.to_string())),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data.raw_data.to_owned()
|
data.raw_data.to_owned()
|
||||||
@@ -74,54 +74,7 @@ impl Labyrinth {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => Ok(response),
|
Ok(response) => Ok(response),
|
||||||
Err(err) => Err(Box::new(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>, Box<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(Box::new(Error::Info(err.to_string()))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => Err(Box::new(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, Box<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(Box::new(Error::Info(err.to_string()))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user