diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/args.rs | 4 | ||||
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/renderer.rs | 25 |
3 files changed, 26 insertions, 7 deletions
diff --git a/src/args.rs b/src/args.rs index 72ade7b..783d671 100644 --- a/src/args.rs +++ b/src/args.rs @@ -350,6 +350,10 @@ pub struct CliArgs { /// Currently incompatible with -P|--no-symlinks (see https://github.com/messense/dav-server-rs/issues/37) #[arg(long, env = "MINISERVE_ENABLE_WEBDAV", conflicts_with = "no_symlinks")] pub enable_webdav: bool, + + /// Show served file size in exact bytes. + #[arg(long, default_value = "false", env = "MINISERVE_SHOW_SIZE_IN_BYTE")] + pub show_size_in_byte: bool, } /// Checks whether an interface is valid, i.e. it can be parsed into an IP address diff --git a/src/config.rs b/src/config.rs index 4404959..03d3f4b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -158,6 +158,9 @@ pub struct MiniserveConfig { /// If enabled, respond to WebDAV requests (read-only). pub webdav_enabled: bool, + /// If enabled, will show in exact byte size of the file + pub show_size_in_byte: bool, + /// If set, use provided rustls config for TLS #[cfg(feature = "tls")] pub tls_rustls_config: Option<rustls::ServerConfig>, @@ -320,6 +323,7 @@ impl MiniserveConfig { webdav_enabled: args.enable_webdav, tls_rustls_config: tls_rustls_server_config, compress_response: args.compress_response, + show_size_in_byte: args.show_size_in_byte, }) } } diff --git a/src/renderer.rs b/src/renderer.rs index fae3751..e86bb22 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -32,7 +32,7 @@ pub fn page( ) -> Markup { // If query_params.raw is true, we want render a minimal directory listing if query_params.raw.is_some() && query_params.raw.unwrap() { - return raw(entries, is_root); + return raw(entries, is_root, conf); } let upload_route = format!("{}/upload", &conf.route_prefix); @@ -150,7 +150,7 @@ pub fn page( } } @for entry in entries { - (entry_row(entry, sort_method, sort_order, false)) + (entry_row(entry, sort_method, sort_order, false, conf.show_size_in_byte)) } } } @@ -214,7 +214,7 @@ pub fn page( } /// Renders the file listing -pub fn raw(entries: Vec<Entry>, is_root: bool) -> Markup { +pub fn raw(entries: Vec<Entry>, is_root: bool, conf: &MiniserveConfig) -> Markup { html! { (DOCTYPE) html { @@ -238,7 +238,7 @@ pub fn raw(entries: Vec<Entry>, is_root: bool) -> Markup { } } @for entry in entries { - (entry_row(entry, None, None, true)) + (entry_row(entry, None, None, true, conf.show_size_in_byte)) } } } @@ -522,6 +522,7 @@ fn entry_row( sort_method: Option<SortingMethod>, sort_order: Option<SortingOrder>, raw: bool, + show_size_in_byte: bool, ) -> Markup { html! { tr { @@ -554,13 +555,19 @@ fn entry_row( @if !raw { @if let Some(size) = entry.size { - span.mobile-info.size { - (build_link("size", &format!("{}", size), sort_method, sort_order)) + @if show_size_in_byte { + span.mobile-info.size { + (maud::display(format!("{}B", size.as_u64()))) + } + }@else { + span.mobile-info.size { + (build_link("size", &format!("{}", size), sort_method, sort_order)) } } @if let Some(modification_timer) = humanize_systemtime(entry.last_modification_date) { span.mobile-info.history { (build_link("date", &modification_timer, sort_method, sort_order)) + } } } } @@ -569,7 +576,11 @@ fn entry_row( } td.size-cell { @if let Some(size) = entry.size { - (maud::display(size)) + @if show_size_in_byte { + (maud::display(format!("{}B", size.as_u64()))) + }@else { + (maud::display(size)) + } } } td.date-cell { |