diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-08-29 13:53:23 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2025-08-20 00:48:44 +1000 |
| commit | d4f0eae4dc54f356f296ff26aba006e69d21ec0b (patch) | |
| tree | 715e26a52e20dcc12e7502fe9cf33e36ea988dd8 | |
| parent | 4aa0c3d2c063040f4ad0a85c8ceb0aace48147f7 (diff) | |
Added file size to ViewMedia page
| -rw-r--r-- | Pages/ViewMedia.razor | 5 | ||||
| -rw-r--r-- | Util.cs | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/Pages/ViewMedia.razor b/Pages/ViewMedia.razor index 935b4ca..bb6a207 100644 --- a/Pages/ViewMedia.razor +++ b/Pages/ViewMedia.razor @@ -1,4 +1,5 @@ @page "/ViewMedia" +@using HyperBooru.Util @inject IJSRuntime jsRuntime @inject IDbContextFactory<HBContext> dbFactory @inject ITagService tagService @@ -39,6 +40,7 @@ <th>Last Write</th> <th>Uploaded On</th> <th>Filename</th> + <th>Size</th> <th>Original Checksum</th> </tr> @foreach(var file in media.UploadedFiles) { @@ -47,7 +49,8 @@ <td title=@file.LastWriteTime?.ToString()>@(file.LastWriteTime?.ToString("d") ?? "N/A")</td> <td title=@file.UploadTime>@(file.UploadTime.ToString("d"))</td> <td>@file.Filename</td> - <td>@file.OriginalChecksum</td> + <td title=@file.Length>@file.Length.ToBytesSI()</td> + <td title=@file.OriginalChecksum>@file.OriginalChecksum.Substring(0, 8)</td> </tr> } </table> @@ -1,8 +1,21 @@ namespace HyperBooru.Util; public static class Extensions { + public static readonly string[] MagnitudeOrders = new[] { + "K", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q" + }; + public static DateTime? TryParseDateTimeUtc(this string s) { bool success = DateTime.TryParse(s, out var dateTime); return success ? DateTime.SpecifyKind(dateTime, DateTimeKind.Utc) : null; } + + public static string ToBytesSI(this long x) { + var exp = (int) Math.Log10(x); + var suffix = MagnitudeOrders.ElementAtOrDefault(exp / 3 - 1); + if(suffix is null) + return x.ToString(); + double n = x / Math.Pow(10, exp / 3 * 3); + return $"{Math.Round(n, 2 - (exp % 3))} {suffix}B"; + } } |
