Improve HTML page for authored files

This commit is contained in:
Timothy Baldridge 2020-05-09 19:35:42 -06:00
parent 33c1de3ad3
commit 4b2822c589
5 changed files with 73 additions and 0 deletions

View File

@ -1,9 +1,11 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.AuthorApi;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Server.DataLayer;
using Xunit;
using Xunit.Abstractions;
@ -26,6 +28,9 @@ namespace Wabbajack.BuildServer.Test
using var queue = new WorkQueue(2);
var uri = await client.UploadFile(queue, file.Path, (s, percent) => Utils.Log($"({percent}) {s}"));
var data = await Fixture.GetService<SqlService>().AllAuthoredFiles();
Assert.Contains((string)file.Path.FileName, data.Select(f => f.OriginalFileName));
var state = await DownloadDispatcher.Infer(uri);
Assert.IsType<WabbajackCDNDownloader.State>(state);

View File

@ -417,6 +417,19 @@ CREATE TABLE [dbo].[AuthoredFiles](
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[AuthoredFilesSummaries] Script Date: 5/9/2020 6:06:00 PM ******/
CREATE VIEW AuthoredFilesSummaries
AS
SELECT
[ServerAssignedUniqueId]
,[LastTouched]
,[Finalized]
,JSON_VALUE(CDNFileDefinition, '$.OriginalFileName') as OriginalFileName
,JSON_VALUE(CDNFileDefinition, '$.MungedName') as MungedName
,JSON_VALUE(CDNFileDefinition, '$.Author') as Author
,JSON_VALUE(CDNFILEDefinition, '$.Size') as Size
FROM [wabbajack_prod].[dbo].[AuthoredFiles]
GO
/****** Uploaded Files [UploadedFiles] *************/
CREATE TABLE [dbo].[UploadedFiles](

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using FluentFTP;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Nettle;
using SharpCompress.Compressors.LZMA;
using Wabbajack.Common;
using Wabbajack.Lib.AuthorApi;
@ -138,6 +139,32 @@ namespace Wabbajack.BuildServer.Controllers
_logger.Log(LogLevel.Information, $"Delete failed for {path}");
}
}
private static readonly Func<object, string> HandleGetListTemplate = NettleEngine.GetCompiler().Compile(@"
<html><body>
<table>
{{each $.files }}
<tr><td><a href='https//wabbajack.b-cdn.net/{{$.MungedName}}'>{{$.OriginalFileName}}</a></td><td>{{$.Size}}</td><td>{{$.LastTouched}}</td><td>{{$.Finalized}}</td><td>{{$.Uploader}}</td></tr>
{{/each}}
</table>
</body></html>
");
[HttpGet]
[Route("")]
public async Task<ContentResult> UploadedFilesGet()
{
var files = await _sql.AllAuthoredFiles();
var response = HandleGetListTemplate(files);
return new ContentResult
{
ContentType = "text/html",
StatusCode = (int) HttpStatusCode.OK,
Content = response
};
}
}
}

View File

@ -0,0 +1,15 @@
using System;
namespace Wabbajack.Server.DTOs
{
public class AuthoredFilesSummary
{
public long Size { get; set; }
public string OriginalFileName { get; set; }
public string Author { get; set; }
public DateTime LastTouched { get; set; }
public DateTime? Finalized { get; set; }
public string MungedName { get; set; }
public string ServerAssignedUniqueId { get; set; }
}
}

View File

@ -1,9 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Wabbajack.BuildServer.Controllers;
using Wabbajack.Common;
using Wabbajack.Lib.AuthorApi;
using Wabbajack.Server.DTOs;
namespace Wabbajack.Server.DataLayer
{
@ -57,6 +63,13 @@ namespace Wabbajack.Server.DataLayer
new {Uid = definition.ServerAssignedUniqueId})).First();
}
public async Task<IEnumerable<AuthoredFilesSummary>> AllAuthoredFiles()
{
await using var conn = await Open();
var results = await conn.QueryAsync<AuthoredFilesSummary>("SELECT CONVERT(NVARCHAR(50), ServerAssignedUniqueId) as ServerAssignedUniqueId, Size, OriginalFileName, Author, LastTouched, Finalized, MungedName from dbo.AuthoredFilesSummaries ORDER BY LastTouched DESC");
return results;
}
}
}