From 63ca2f7c389b94348903b1506e65c1c5eacd032e Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sat, 7 Oct 2023 13:56:05 -0600 Subject: [PATCH] Updates to the AuthoredFiles report --- Wabbajack.Server/Controllers/AuthoredFiles.cs | 42 ++++++----------- Wabbajack.Server/DataModels/AuthorFiles.cs | 15 +++++++ .../Resources/Reports/AuthoredFiles.html | 45 +++++++++++++++++++ Wabbajack.Server/Wabbajack.Server.csproj | 2 + 4 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 Wabbajack.Server/Resources/Reports/AuthoredFiles.html diff --git a/Wabbajack.Server/Controllers/AuthoredFiles.cs b/Wabbajack.Server/Controllers/AuthoredFiles.cs index bed9f18f..6abd80ed 100644 --- a/Wabbajack.Server/Controllers/AuthoredFiles.cs +++ b/Wabbajack.Server/Controllers/AuthoredFiles.cs @@ -1,12 +1,7 @@ -using System; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net; +using System.Net; using System.Security.Claims; -using System.Threading; -using System.Threading.Tasks; -using FluentFTP; +using Humanizer; +using Humanizer.Localisation; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -18,7 +13,6 @@ using Wabbajack.DTOs.JsonConverters; using Wabbajack.Hashing.xxHash64; using Wabbajack.Server.DataModels; using Wabbajack.Server.DTOs; -using Wabbajack.Server.Extensions; using Wabbajack.Server.Services; namespace Wabbajack.BuildServer.Controllers; @@ -27,29 +21,13 @@ namespace Wabbajack.BuildServer.Controllers; [Route("/authored_files")] public class AuthoredFiles : ControllerBase { - private static readonly Func HandleGetListTemplate = NettleEngine.GetCompiler().Compile(@" - - - {{each $.files }} - - - - - - - - {{/each}} -
{{$.Definition.OriginalFileName}}{{$.HumanSize}}{{$.Definition.Author}}{{$.Updated}}(Slow) HTTP Direct Link
- - "); - - private readonly DTOSerializer _dtos; private readonly DiscordWebHook _discord; private readonly ILogger _logger; private readonly AppSettings _settings; private readonly AuthorFiles _authoredFiles; + private readonly Func _authoredFilesTemplate; public AuthoredFiles(ILogger logger, AuthorFiles authorFiles, AppSettings settings, DiscordWebHook discord, @@ -60,6 +38,9 @@ public class AuthoredFiles : ControllerBase _discord = discord; _dtos = dtos; _authoredFiles = authorFiles; + using var stream = typeof(AuthoredFiles).Assembly + .GetManifestResourceStream("Wabbajack.Server.Resources.Reports.AuthoredFiles.html"); + _authoredFilesTemplate = NettleEngine.GetCompiler().Compile(stream.ReadAllText()); } [HttpPut] @@ -165,12 +146,17 @@ public class AuthoredFiles : ControllerBase public async Task UploadedFilesGet() { var files = await _authoredFiles.AllAuthoredFiles(); - var response = HandleGetListTemplate(new {files = files.OrderByDescending(f => f.Updated).ToArray()}); + var response = _authoredFilesTemplate(new + { + Files = files.OrderByDescending(f => f.Updated).ToArray(), + TotalSpace = _authoredFiles.TotalSpace.Bytes().Humanize("#.##"), + FreeSpace = _authoredFiles.FreeSpace.Bytes().Humanize("#.##") + }); return new ContentResult { ContentType = "text/html", StatusCode = (int) HttpStatusCode.OK, - Content = response + Content = response, }; } diff --git a/Wabbajack.Server/DataModels/AuthorFiles.cs b/Wabbajack.Server/DataModels/AuthorFiles.cs index 1a166a3a..5f76efb9 100644 --- a/Wabbajack.Server/DataModels/AuthorFiles.cs +++ b/Wabbajack.Server/DataModels/AuthorFiles.cs @@ -28,6 +28,21 @@ public class AuthorFiles } public IEnumerable AllDefinitions => AuthorFilesLocation.EnumerateFiles("definition.json.gz"); + + /// + /// Total unused space available for authored files + /// + public long FreeSpace => new DriveInfo(AuthorFilesLocation.ToString()).AvailableFreeSpace; + + /// + /// Total space available for authored files + /// + public long TotalSpace => new DriveInfo(AuthorFilesLocation.ToString()).TotalSize; + + /// + /// + /// + /// public async Task AllAuthoredFiles() { diff --git a/Wabbajack.Server/Resources/Reports/AuthoredFiles.html b/Wabbajack.Server/Resources/Reports/AuthoredFiles.html new file mode 100644 index 00000000..42a4ed20 --- /dev/null +++ b/Wabbajack.Server/Resources/Reports/AuthoredFiles.html @@ -0,0 +1,45 @@ + + + + Authored Files Report + + + + + + + + +

Authored Files:

+

{{$.FreeSpace}} remaining of {{$.TotalSpace}}

+ + + + + + + + + + + {{each $.Files }} + + + + + + + + {{/each}} +
NameSizeAuthorUpdatedDirect Link
{{$.Definition.OriginalFileName}}{{$.HumanSize}}{{$.Definition.Author}}{{$.Updated}}(Slow) HTTP Direct Link
+ + + \ No newline at end of file diff --git a/Wabbajack.Server/Wabbajack.Server.csproj b/Wabbajack.Server/Wabbajack.Server.csproj index eb548414..9abb308e 100644 --- a/Wabbajack.Server/Wabbajack.Server.csproj +++ b/Wabbajack.Server/Wabbajack.Server.csproj @@ -49,6 +49,8 @@ + +