Skip to content

Commit

Permalink
feat: http api for upload/download
Browse files Browse the repository at this point in the history
  • Loading branch information
cupen committed Nov 24, 2024
1 parent 47694f9 commit b2003bd
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 113 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- "v*"


env:
CARGO_TERM_COLOR: always

jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create Release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false

publish:
name: publish ${{ matrix.name }}
needs:
- release
strategy:
fail-fast: true
matrix:
include:
- target: x86_64-pc-windows-gnu
suffix: windows-x86_64
archive: zip
name: x86_64-pc-windows-gnu
- target: x86_64-unknown-linux-gnu
suffix: linux-x86_64
archive: tar.xz
name: x86_64-unknown-linux-gnu
- target: x86_64-apple-darwin
suffix: darwin-x86_64
archive: tar.gz
name: x86_64-apple-darwin
runs-on: ubuntu-latest
steps:
- name: Clone test repository
uses: actions/checkout@v2
- uses: xhaiker/[email protected]
name: build ${{ matrix.name }}
with:
release: ${{ github.ref_name }}
rust_target: ${{ matrix.target }}
archive_suffix: ${{ matrix.suffix }}
archive_types: ${{ matrix.archive }}
extra_files: "README.md"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ target/
.venv/
__pycache__/
*.html
*.css
*.js
*.tar.gz


# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
Expand Down
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ name = "fake-cdn"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true
# [lib]
# proc-macro = true

[dependencies]
actix-files = "0.6.6"
actix-multipart = "0.7.2"
actix-web = "4.9.0"
clap = "4.5.18"
clap = "4.5.20"
colog = "1.3.0"
flate2 = "1.0.34"
lazy_static = "1.5.0"
log = "0.4.22"
# rocket = "0.5.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.122"
serde_json = "1.0.132"
structopt = "0.3.26"
tokio = { version = "1.40.0", features= ["fs"] }
tar = "0.4.42"
tokio = { version = "1.41.1", features= ["fs"] }
toml = "0.8.19"
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Fake CDN

# Features
* Upload files
* Download files
* Upload / Download files
* Serve static site

# Dependencies
Expand Down
37 changes: 31 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
use serde::{Serialize};
use structopt::StructOpt;

use std::sync::OnceLock;


#[derive(Debug, StructOpt)]
#[structopt(name = "args")]
pub struct Args {
#[structopt(subcommand)]
pub command: Command,

#[structopt(short, long)]
pub verbose: bool,
// #[structopt(short, long)]
// pub verbose: bool,
}

#[derive(StructOpt, Debug)]
pub enum Command {
Web {
#[structopt(long)]
#[structopt(long, env="FAKECDN_LISTEN", default_value="127.0.0.1:9527")]
listen: String,

#[structopt(long, env="FAKECDN_DIR", default_value=".uploads")]
dir: String,

#[structopt(long, env="FAKECDN_TOKEN", default_value="")]
token: String,
},
}

pub fn get_args() -> &'static Args {
static ARGS: OnceLock<Args> = OnceLock::new();
return ARGS.get_or_init(|| parse_args());
}


pub fn get_args_token() -> &'static String {
let args = get_args();
match &args.command {
Command::Web { token, .. } => return token,
}
}

pub fn parse_args() -> Args {
return Args::from_args()
}
return Args::from_args();
}

// pub fn parse_args() -> &'static Mutex<Args> {
// // return Args::from_args()
// static ARGS: OnceLock<Mutex<Args>> = OnceLock::new();
// return ARGS.get_or_init(|| Mutex::new(Args::from_args()))
// }
15 changes: 15 additions & 0 deletions src/files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::fs::File;
use std::path::Path;
use std::path::PathBuf;
use flate2::read::GzDecoder;
use tar::Archive;

pub(crate) fn uncompress_tgz(path: &PathBuf, dest: &Path) -> Result<(), std::io::Error> {
// let path = "archive.tar.gz";
let tar_gz = File::open(path)?;
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack(dest)?;

Ok(())
}
Empty file removed src/lib.rs
Empty file.
Loading

0 comments on commit b2003bd

Please sign in to comment.