diff options
author | Lzzzt <liuzitao0123@gmail.com> | 2023-10-27 13:25:57 +0000 |
---|---|---|
committer | Lzzzt <liuzitao0123@gmail.com> | 2025-03-03 06:49:25 +0000 |
commit | aefe3683d3ff0d579e79f06ccdc7e408ae9b3a4a (patch) | |
tree | cf0cb1d515d74370fda14b84beb79d8e28517684 /src/renderer.rs | |
parent | Add CHANGELOG entry for #1431 (diff) | |
download | miniserve-aefe3683d3ff0d579e79f06ccdc7e408ae9b3a4a.tar.gz miniserve-aefe3683d3ff0d579e79f06ccdc7e408ae9b3a4a.zip |
Show File Size in Bytes
Add a cli option that show file size in bytes rather than KB or MB, etc.
Diffstat (limited to 'src/renderer.rs')
-rw-r--r-- | src/renderer.rs | 25 |
1 files changed, 18 insertions, 7 deletions
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 { |