Skip to content

Commit

Permalink
Well.... I guess this crappy tool is production ready x)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blutsh committed May 9, 2024
1 parent 4f3b567 commit 4e8ca8d
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 124 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Deploy

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: write

jobs:
build-and-upload:
name: Build and upload
runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-musl

- build: windows
os: windows-latest
target: x86_64-pc-windows-msvc

- build: macos-arm64
os: macos-latest
target: aarch64-apple-darwin

- build: macos-x86_64
os: macos-latest
target: x86_64-apple-darwin

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get the release version from the tag
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --verbose --release --target ${{ matrix.target }}

- name: Build archive
shell: bash
run: |
# Replace with the name of your binary
binary_name="swish"
dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}"
mkdir "$dirname"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
mv "target/${{ matrix.target }}/release/$binary_name.exe" "$dirname"
else
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
fi
if [ "${{ matrix.os }}" = "windows-latest" ]; then
7z a "$dirname.zip" "$dirname"
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
else
tar -czf "$dirname.tar.gz" "$dirname"
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
fi
- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
${{ env.ASSET }}
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ regex = "1.10.3"
serde_json = "1.0.114"
sha2 = "0.10.8"
simple_logger = "4.3.3"
openssl-sys = { version = "0.9", features = ["vendored"] }
5 changes: 0 additions & 5 deletions src/api/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ pub struct DataHandler {
pub data: Vec<u8>,
}

impl DataHandler {
pub fn new() -> Self {
Self { data: Vec::new() }
}
}

impl Handler for DataHandler {
fn write(&mut self, data: &[u8]) -> Result<usize, WriteError> {
Expand Down
5 changes: 3 additions & 2 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// Man... told you this was a mess
use curl::easy::Easy2;
use std::fs::File;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -56,9 +58,8 @@ pub fn new_easy2_download(
url: String,
custom_headers: Option<Vec<String>>,
file: File,
file_size: u64,
) -> Result<Easy2<DownloadHandler<File>>, curl::Error> {
let file_metadata = file.metadata().unwrap();
let file_size = file_metadata.len();

let progress_bar = ProgressBar::new(file_size as u64);
progress_bar.set_style(ProgressStyle::default_bar()
Expand Down
10 changes: 2 additions & 8 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ use std::fmt;
#[derive(Debug)]
pub enum SwishError {
InvalidUrl { url: String },
InavlidArg { arg: String },
InvalidJson { json: String },
InvalidResponse { response: String },
InvalidFile { file: String },
InvalidPath { path: String },
CurlError { error: CurlError },
FileError { error: std::io::Error },
JSONError { error: serde_json::Error },
NotFound { url: String },
PasswordRequired,
InvalidPassword,
DownloadNumberExceeded,
}

impl fmt::Display for SwishError {
Expand All @@ -24,15 +21,12 @@ impl fmt::Display for SwishError {
SwishError::InvalidUrl { url } => write!(f, "Invalid URL: {}", url),
SwishError::InvalidJson { json } => write!(f, "Invalid JSON: {}", json),
SwishError::NotFound { url } => write!(f, "Not Found: {}, Maybe link has expired", url),
SwishError::InvalidFile { file } => write!(f, "Invalid File: {}", file),
SwishError::InvalidPath { path } => write!(f, "Invalid Path: {}", path),
SwishError::CurlError { error } => write!(f, "Curl Error: {}", error),
SwishError::InvalidResponse { response } => write!(f, "Invalid Response: {}", response),
SwishError::FileError { error } => write!(f, "File Error: {}", error),
SwishError::JSONError { error } => write!(f, "JSON Error: {}", error),
SwishError::InavlidArg { arg } => write!(f, "Invalid Argument: {}", arg),
SwishError::PasswordRequired => write!(f, "A password is required to download this file please provide it using the -p flag or --password flag"),
SwishError::InvalidPassword => write!(f, "The password provided is incorrect"),
SwishError::DownloadNumberExceeded => write!(f, "The number of download has been exceeded"),
}
}
}
Expand Down
Loading

0 comments on commit 4e8ca8d

Please sign in to comment.