summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Pages/ViewMedia.razor5
-rw-r--r--Util.cs13
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>
diff --git a/Util.cs b/Util.cs
index 9cbccdf..31a2e84 100644
--- a/Util.cs
+++ b/Util.cs
@@ -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";
+ }
}