feat: aware RUST_LOG

pull/8/head
sigoden 2022-05-28 20:42:32 +08:00
parent d9a917176a
commit 3673a64ec7
5 changed files with 14 additions and 12 deletions

2
Cargo.lock generated
View File

@ -258,7 +258,7 @@ dependencies = [
[[package]] [[package]]
name = "duf" name = "duf"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"async-walkdir", "async-walkdir",
"async_zip", "async_zip",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "duf" name = "duf"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
authors = ["sigoden <sigoden@gmail.com>"] authors = ["sigoden <sigoden@gmail.com>"]
description = "Duf is a simple file server." description = "Duf is a simple file server."

View File

@ -49,8 +49,6 @@ duf --static
Finally, run this command to see a list of all available option Finally, run this command to see a list of all available option
### Curl ### Curl
Download a file Download a file

View File

@ -25,14 +25,18 @@ async fn main() {
async fn run() -> BoxResult<()> { async fn run() -> BoxResult<()> {
let args = Args::parse(matches())?; let args = Args::parse(matches())?;
let level = if args.log { if std::env::var("RUST_LOG").is_ok() {
LevelFilter::Info simple_logger::init()?;
} else { } else {
LevelFilter::Error let level = if args.log {
}; LevelFilter::Info
simple_logger::SimpleLogger::default() } else {
.with_level(level) LevelFilter::Error
.init()?; };
simple_logger::SimpleLogger::default()
.with_level(level)
.init()?;
}
serve(args).await serve(args).await
} }

View File

@ -187,7 +187,7 @@ impl InnerService {
} }
async fn handle_send_dir_zip(&self, path: &Path) -> BoxResult<Response> { async fn handle_send_dir_zip(&self, path: &Path) -> BoxResult<Response> {
let (mut writer, reader) = tokio::io::duplex(65536); let (mut writer, reader) = tokio::io::duplex(1024 * 1024 * 20);
dir_zip(&mut writer, path).await?; dir_zip(&mut writer, path).await?;
let stream = ReaderStream::new(reader); let stream = ReaderStream::new(reader);
let body = Body::wrap_stream(stream); let body = Body::wrap_stream(stream);