Updates to the AuthoredFiles report

This commit is contained in:
Timothy Baldridge 2023-10-07 13:56:05 -06:00
parent 77f6b8c9cb
commit 63ca2f7c38
4 changed files with 76 additions and 28 deletions

View File

@ -1,12 +1,7 @@
using System; using System.Net;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Security.Claims; using System.Security.Claims;
using System.Threading; using Humanizer;
using System.Threading.Tasks; using Humanizer.Localisation;
using FluentFTP;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -18,7 +13,6 @@ using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Hashing.xxHash64; using Wabbajack.Hashing.xxHash64;
using Wabbajack.Server.DataModels; using Wabbajack.Server.DataModels;
using Wabbajack.Server.DTOs; using Wabbajack.Server.DTOs;
using Wabbajack.Server.Extensions;
using Wabbajack.Server.Services; using Wabbajack.Server.Services;
namespace Wabbajack.BuildServer.Controllers; namespace Wabbajack.BuildServer.Controllers;
@ -27,29 +21,13 @@ namespace Wabbajack.BuildServer.Controllers;
[Route("/authored_files")] [Route("/authored_files")]
public class AuthoredFiles : ControllerBase public class AuthoredFiles : ControllerBase
{ {
private static readonly Func<object, string> HandleGetListTemplate = NettleEngine.GetCompiler().Compile(@"
<html><body>
<table>
{{each $.files }}
<tr>
<td><a href='https://authored-files.wabbajack.org/{{$.Definition.MungedName}}'>{{$.Definition.OriginalFileName}}</a></td>
<td>{{$.HumanSize}}</td>
<td>{{$.Definition.Author}}</td>
<td>{{$.Updated}}</td>
<td><a href='/authored_files/direct_link/{{$.Definition.MungedName}}'>(Slow) HTTP Direct Link</a></td>
</tr>
{{/each}}
</table>
</body></html>
");
private readonly DTOSerializer _dtos; private readonly DTOSerializer _dtos;
private readonly DiscordWebHook _discord; private readonly DiscordWebHook _discord;
private readonly ILogger<AuthoredFiles> _logger; private readonly ILogger<AuthoredFiles> _logger;
private readonly AppSettings _settings; private readonly AppSettings _settings;
private readonly AuthorFiles _authoredFiles; private readonly AuthorFiles _authoredFiles;
private readonly Func<object,string> _authoredFilesTemplate;
public AuthoredFiles(ILogger<AuthoredFiles> logger, AuthorFiles authorFiles, AppSettings settings, DiscordWebHook discord, public AuthoredFiles(ILogger<AuthoredFiles> logger, AuthorFiles authorFiles, AppSettings settings, DiscordWebHook discord,
@ -60,6 +38,9 @@ public class AuthoredFiles : ControllerBase
_discord = discord; _discord = discord;
_dtos = dtos; _dtos = dtos;
_authoredFiles = authorFiles; _authoredFiles = authorFiles;
using var stream = typeof(AuthoredFiles).Assembly
.GetManifestResourceStream("Wabbajack.Server.Resources.Reports.AuthoredFiles.html");
_authoredFilesTemplate = NettleEngine.GetCompiler().Compile(stream.ReadAllText());
} }
[HttpPut] [HttpPut]
@ -165,12 +146,17 @@ public class AuthoredFiles : ControllerBase
public async Task<ContentResult> UploadedFilesGet() public async Task<ContentResult> UploadedFilesGet()
{ {
var files = await _authoredFiles.AllAuthoredFiles(); 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 return new ContentResult
{ {
ContentType = "text/html", ContentType = "text/html",
StatusCode = (int) HttpStatusCode.OK, StatusCode = (int) HttpStatusCode.OK,
Content = response Content = response,
}; };
} }

View File

@ -28,6 +28,21 @@ public class AuthorFiles
} }
public IEnumerable<AbsolutePath> AllDefinitions => AuthorFilesLocation.EnumerateFiles("definition.json.gz"); public IEnumerable<AbsolutePath> AllDefinitions => AuthorFilesLocation.EnumerateFiles("definition.json.gz");
/// <summary>
/// Total unused space available for authored files
/// </summary>
public long FreeSpace => new DriveInfo(AuthorFilesLocation.ToString()).AvailableFreeSpace;
/// <summary>
/// Total space available for authored files
/// </summary>
public long TotalSpace => new DriveInfo(AuthorFilesLocation.ToString()).TotalSize;
/// <summary>
///
/// </summary>
/// <returns></returns>
public async Task<FileDefinitionMetadata[]> AllAuthoredFiles() public async Task<FileDefinitionMetadata[]> AllAuthoredFiles()
{ {

View File

@ -0,0 +1,45 @@
<html>
<head>
<meta charset="UTF-8">
<title>Authored Files Report</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap4.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.12.1/sorting/file-size.js"></script>
</head>
<body>
<H1>Authored Files:</H1>
<H3>{{$.FreeSpace}} remaining of {{$.TotalSpace}} </H3>
<table id="inlined-data" class="table table-striped table-bordered" style="width:100%" >
<thead>
<tr>
<th>Name</th>
<th>Size</th>
<th>Author</th>
<th>Updated</th>
<th>Direct Link</th>
</tr>
</thead>
{{each $.Files }}
<tr>
<td><a href='https://authored-files.wabbajack.org/{{$.Definition.MungedName}}'>{{$.Definition.OriginalFileName}}</a></td>
<td>{{$.HumanSize}}</td>
<td>{{$.Definition.Author}}</td>
<td>{{$.Updated}}</td>
<td><a href='/authored_files/direct_link/{{$.Definition.MungedName}}'>(Slow) HTTP Direct Link</a></td>
</tr>
{{/each}}
</table>
<script>
$(document).ready( function () {
$("#inlined-data").DataTable({
columnDefs: [
{ type: 'file-size', targets: 1},
]
});
} );
</script>
</body></html>

View File

@ -49,6 +49,8 @@
<EmbeddedResource Include="sheo_quotes.txt" /> <EmbeddedResource Include="sheo_quotes.txt" />
<None Remove="Controllers\Templates\TotalListTemplate.html" /> <None Remove="Controllers\Templates\TotalListTemplate.html" />
<EmbeddedResource Include="Controllers\Templates\TotalListTemplate.html" /> <EmbeddedResource Include="Controllers\Templates\TotalListTemplate.html" />
<None Remove="Resources\Reports\AuthoredFiles.html" />
<EmbeddedResource Include="Resources\Reports\AuthoredFiles.html" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>