Compare commits

..

2 Commits

Author SHA1 Message Date
504d10bccc b 2024-04-11 10:36:34 +02:00
d9ac349d58 a 2024-04-11 10:36:22 +02:00
5 changed files with 408 additions and 570 deletions

941
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,10 @@
[package]
name = "expose-dir-via-http"
version = "1.3.0"
edition = "2024"
[lints.rust]
unsafe_code = "forbid"
[lints.clippy]
pedantic = { level = "warn", priority = -1 }
todo = "warn"
unwrap_used = "warn"
version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = { version = "4" }
actix-web = { version = "4", features = ["experimental-io-uring"] }
actix-files = "0.6"
clap = { version = "4", features = ["cargo", "derive"] }

0
a Normal file
View File

0
b Normal file
View File

View File

@ -1,7 +1,6 @@
use std::{
env,
net::{IpAddr, SocketAddr},
num::NonZeroUsize,
path::PathBuf,
thread::available_parallelism,
};
@ -12,8 +11,8 @@ use clap::{crate_name, crate_version, Parser};
#[clap(name = crate_name!(), version = crate_version!())]
struct Args {
/// Directory to expose
#[clap(default_value = ".", value_parser = parse_valid_dir)]
dir: PathBuf,
#[clap(default_value = ".")]
dir: String,
/// IP address to use
#[clap(default_value = "0.0.0.0")]
@ -24,15 +23,6 @@ struct Args {
port: u16,
}
fn parse_valid_dir(dir: &str) -> Result<PathBuf, String> {
let path = std::path::Path::new(dir);
if path.is_dir() {
Ok(path.to_path_buf())
} else {
Err(format!("{} is not a valid directory", path.display()))
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let args = Args::parse();
@ -40,10 +30,7 @@ async fn main() -> std::io::Result<()> {
let dir = args.dir;
let sock = SocketAddr::new(args.ip, args.port);
println!(
"Starting HTTP server on {sock} exposing dir {}",
dir.display()
);
println!("Starting HTTP server on {sock} exposing dir {dir}");
HttpServer::new(move || {
App::new().service(
@ -52,7 +39,7 @@ async fn main() -> std::io::Result<()> {
.prefer_utf8(true),
)
})
.workers(available_parallelism().map_or(1, NonZeroUsize::get))
.workers(available_parallelism().unwrap().get())
.bind(sock)?
.run()
.await