From 6ed1d00a32c62d5add4adbcc73a49027c53e697c Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 10 Aug 2026 17:41:33 -0400 Subject: [PATCH] Download (#2) Reviewed-on: http://git.kundeng.us/phoenix/labyrinth/pulls/2 --- .gitea/workflows/ci.yml | 73 +++++++++++++++++++++++++++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- LICENSE | 21 ++++++++++++ src/lib.rs | 30 +++++++++++++++-- 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 LICENSE diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index e69de29..9b2ba0f 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,73 @@ +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.97 + - 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.97 + - 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.97 + - 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.97 + - 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.97 + - uses: Swatinem/rust-cache@v2 + - run: cargo build + diff --git a/Cargo.lock b/Cargo.lock index 16c1c34..0bac2f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1370,7 +1370,7 @@ dependencies = [ [[package]] name = "labyrinth" -version = "0.0.2" +version = "0.0.3" dependencies = [ "aws-config", "aws-sdk-s3", diff --git a/Cargo.toml b/Cargo.toml index 4c34a54..c9690f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "labyrinth" -version = "0.0.2" +version = "0.0.3" edition = "2024" license = "MIT" description = "Library for managing soaricarus storage" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f5a66d1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +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. diff --git a/src/lib.rs b/src/lib.rs index 11270d3..d308129 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,8 +37,7 @@ pub async fn init_client(config: &config::Config) -> aws_sdk_s3::Client { .force_path_style(true) .build(); - let client = aws_sdk_s3::Client::from_conf(s3_config); - client + aws_sdk_s3::Client::from_conf(s3_config) } #[derive(Debug)] @@ -77,4 +76,31 @@ impl Labyrinth { Err(err) => Err(Error::Info(err.to_string())), } } + + pub async fn download(&self, file_key: &str) -> Result, 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())), + } + } }