From 74bd8d3a9001602bfce2a5490dc640e8dfc3c6a4 Mon Sep 17 00:00:00 2001 From: ALLARD Antoine Date: Mon, 23 Jan 2023 17:41:24 +0100 Subject: [PATCH] Demo to show disk space available --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/errors.rs | 7 +++++++ src/main.rs | 7 +++++++ src/renderer.rs | 3 +++ 5 files changed, 25 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e1732fe1c..7edad4cec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -875,6 +875,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" + [[package]] name = "futf" version = "0.1.5" @@ -1565,6 +1571,7 @@ dependencies = [ "comrak", "fake-tty", "fast_qr", + "fs_extra", "futures", "get_if_addrs", "grass", diff --git a/Cargo.toml b/Cargo.toml index 593b56f98..cf4c25732 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ clap_complete = "4" clap_mangen = "0.2" comrak = { version = "0.15", default-features = false } fast_qr = { version = "0.8", features = ["svg"] } +fs_extra = "1.2.0" futures = "0.3" get_if_addrs = "0.5" hex = "0.4" diff --git a/src/errors.rs b/src/errors.rs index e50263422..f0f336063 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -83,8 +83,15 @@ Please set an explicit serve path like: `miniserve /my/path`")] /// In case miniserve was invoked with --no-symlinks but the serve path is a symlink #[error("The -P|--no-symlinks option was provided but the serve path '{0}' is a symlink")] NoSymlinksOptionWithSymlinkServePath(String), + } +impl std::convert::From for ContextualError { + fn from(value: fs_extra::error::Error) -> Self { + todo!() + } +} + impl ResponseError for ContextualError { fn status_code(&self) -> StatusCode { match self { diff --git a/src/main.rs b/src/main.rs index 84eca2b88..eb1ac253c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,8 @@ use fast_qr::QRBuilder; use log::{error, warn}; use yansi::{Color, Paint}; +use fs_extra::dir::get_size; + mod archive; mod args; mod auth; @@ -222,6 +224,11 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { println!("Serving path {}", Color::Yellow.paint(path_string).bold()); + let folder_size = get_size(canon_path.as_path())?; + let kb_size = folder_size / 1024; + let mb_size = kb_size / 1024; + println!("Disk space available: {:?}MB", mb_size); + println!( "Available at (non-exhaustive list):\n {}\n", display_urls diff --git a/src/renderer.rs b/src/renderer.rs index 7da73928b..eb072010a 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -118,6 +118,9 @@ pub fn page( "/" } } + h3.title dir="ltr" { + bdi { ("Disk space available: XXX MB") } + } div.toolbar { @if conf.tar_enabled || conf.tar_gz_enabled || conf.zip_enabled { div.download {