mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Start of admin pages for authored files
This commit is contained in:
parent
131c11809f
commit
43110dd0d4
@ -27,6 +27,7 @@ namespace Wabbajack.Lib.Http
|
||||
};
|
||||
Utils.Log($"Configuring with SSL {_socketsHandler.SslOptions.EnabledSslProtocols}");
|
||||
Client = new SysHttp.HttpClient(_socketsHandler);
|
||||
Client.DefaultRequestHeaders.Add("User-Agent", Consts.UserAgent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,8 +164,12 @@ namespace Wabbajack.Lib.ModListRegistry
|
||||
public string Link => $"/lists/status/{MachineURL}.json";
|
||||
[JsonProperty("report")]
|
||||
public string Report => $"/lists/status/{MachineURL}.html";
|
||||
|
||||
[JsonProperty("modlist_missing")]
|
||||
public bool ModListIsMissing { get; set; }
|
||||
|
||||
[JsonProperty("has_failures")]
|
||||
public bool HasFailures => Failed > 0;
|
||||
public bool HasFailures => Failed > 0 || ModListIsMissing;
|
||||
}
|
||||
|
||||
}
|
||||
|
27
Wabbajack.Server.Test/AuthorControlTests.cs
Normal file
27
Wabbajack.Server.Test/AuthorControlTests.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.BuildServer.Test;
|
||||
using Wabbajack.Common;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Wabbajack.Server.Test
|
||||
{
|
||||
public class AuthorControlTests : ABuildServerSystemTest
|
||||
{
|
||||
public AuthorControlTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LoginRedirects()
|
||||
{
|
||||
var client = new HttpClient();
|
||||
var result =
|
||||
await client.GetStringAsync($"{Consts.WabbajackBuildServerUri}author_controls/login/{Fixture.APIKey}");
|
||||
|
||||
Assert.Contains("Wabbajack Files -", result);
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ namespace Wabbajack.BuildServer
|
||||
{
|
||||
private const string ProblemDetailsContentType = "application/problem+json";
|
||||
private readonly SqlService _sql;
|
||||
private const string ApiKeyHeaderName = "X-Api-Key";
|
||||
public const string ApiKeyHeaderName = "X-Api-Key";
|
||||
|
||||
private MetricsKeyCache _keyCache;
|
||||
|
||||
@ -71,6 +71,10 @@ namespace Wabbajack.BuildServer
|
||||
|
||||
var authorKey = Request.Headers[ApiKeyHeaderName].FirstOrDefault();
|
||||
|
||||
if (authorKey == null)
|
||||
Request.Cookies.TryGetValue(ApiKeyHeaderName, out authorKey);
|
||||
|
||||
|
||||
if (authorKey == null && metricsKey == null)
|
||||
{
|
||||
return AuthenticateResult.NoResult();
|
||||
|
90
Wabbajack.Server/Controllers/AuthorControls.cs
Normal file
90
Wabbajack.Server/Controllers/AuthorControls.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentFTP;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nettle;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Server.DataLayer;
|
||||
|
||||
namespace Wabbajack.BuildServer.Controllers
|
||||
{
|
||||
[Authorize(Roles="Author")]
|
||||
[Route("/author_controls")]
|
||||
public class AuthorControls : ControllerBase
|
||||
{
|
||||
private ILogger<AuthorControls> _logger;
|
||||
private SqlService _sql;
|
||||
|
||||
public AuthorControls(ILogger<AuthorControls> logger, SqlService sql)
|
||||
{
|
||||
_logger = logger;
|
||||
_sql = sql;
|
||||
}
|
||||
|
||||
[Route("login/{authorKey}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> Login(string authorKey)
|
||||
{
|
||||
Response.Cookies.Append(ApiKeyAuthenticationHandler.ApiKeyHeaderName, authorKey);
|
||||
return Redirect($"{Consts.WabbajackBuildServerUri}author_controls/home");
|
||||
}
|
||||
|
||||
private static Func<object, string> _homePageTemplate;
|
||||
|
||||
private static Func<object, string> HomePageTemplate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_homePageTemplate == null)
|
||||
{
|
||||
var resource = Assembly.GetExecutingAssembly()
|
||||
.GetManifestResourceStream("Wabbajack.Server.Controllers.Templates.AuthorControls.html")!
|
||||
.ReadAll();
|
||||
_homePageTemplate = NettleEngine.GetCompiler().Compile(Encoding.UTF8.GetString(resource));
|
||||
}
|
||||
|
||||
return _homePageTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
[Route("home")]
|
||||
[Authorize("")]
|
||||
public async Task<IActionResult> HomePage()
|
||||
{
|
||||
var user = User.FindFirstValue(ClaimTypes.Name);
|
||||
var files = (await _sql.AllAuthoredFiles())
|
||||
.Where(af => af.Author == user)
|
||||
.Select(af => new
|
||||
{
|
||||
Size = af.Size.FileSizeToString(),
|
||||
OriginalSize = af.Size,
|
||||
Name = af.OriginalFileName,
|
||||
MangledName = af.MungedName,
|
||||
UploadedDate = af.LastTouched
|
||||
})
|
||||
.OrderBy(f => f.Name)
|
||||
.ThenBy(f => f.UploadedDate)
|
||||
.ToList();
|
||||
|
||||
var result = HomePageTemplate(new
|
||||
{
|
||||
User = user,
|
||||
TotalUsage = files.Select(f => f.OriginalSize).Sum().ToFileSizeString(),
|
||||
WabbajackFiles = files.Where(f => f.Name.EndsWith(Consts.ModListExtensionString)),
|
||||
OtherFiles = files.Where(f => !f.Name.EndsWith(Consts.ModListExtensionString))
|
||||
});
|
||||
|
||||
return new ContentResult {
|
||||
ContentType = "text/html",
|
||||
StatusCode = (int)HttpStatusCode.OK,
|
||||
Content = result};
|
||||
}
|
||||
}
|
||||
}
|
46
Wabbajack.Server/Controllers/Templates/AuthorControls.html
Normal file
46
Wabbajack.Server/Controllers/Templates/AuthorControls.html
Normal file
@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Author Controls - {{$.User}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Author Controls - {{$.User}}</h2>
|
||||
<br/>
|
||||
<h3>Wabbajack Files - {{$.TotalUsage}}</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>Name</b></td>
|
||||
<td><b>Size</b></td>
|
||||
<td><b>Finished Uploading</b></td>
|
||||
<td><b>Unique Name</b></td>
|
||||
</tr>
|
||||
{{each $.WabbajackFiles }}
|
||||
<tr>
|
||||
<td>{{$.Name}}</td>
|
||||
<td>{{$.Size}}</td>
|
||||
<td>{{$.UploadedDate}}</td>
|
||||
<td>{{$.MangledName}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
|
||||
<h3>Other Files</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>Name</b></td>
|
||||
<td><b>Size</b></td>
|
||||
<td><b>Finished Uploading</b></td>
|
||||
<td><b>Unique Name</b></td>
|
||||
</tr>
|
||||
{{each $.OtherFiles }}
|
||||
<tr>
|
||||
<td>{{$.Name}}</td>
|
||||
<td>{{$.Size}}</td>
|
||||
<td>{{$.UploadedDate}}</td>
|
||||
<td>{{$.MangledName}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@ -16,5 +16,6 @@ namespace Wabbajack.Server.DTOs
|
||||
public ConcurrentHashSet<(Game Game, long ModId)> SlowQueriedFor { get; set; } = new ConcurrentHashSet<(Game Game, long ModId)>();
|
||||
public Dictionary<Hash, bool> Mirrors { get; set; }
|
||||
public Lazy<Task<Dictionary<Hash, string>>> AllowedMirrors { get; set; }
|
||||
public IEnumerable<AuthoredFilesSummary> AllAuthoredFiles { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace Wabbajack.Server.DataLayer
|
||||
var archiveStatus = AllModListArchivesStatus();
|
||||
var modLists = AllModLists();
|
||||
var mirrors = GetAllMirroredHashes();
|
||||
var authoredFiles = AllAuthoredFiles();
|
||||
return new ValidationData
|
||||
{
|
||||
NexusFiles = new ConcurrentHashSet<(long Game, long ModId, long FileId)>((await nexusFiles).Select(f => (f.NexusGameId, f.ModId, f.FileId))),
|
||||
@ -25,6 +26,7 @@ namespace Wabbajack.Server.DataLayer
|
||||
ModLists = await modLists,
|
||||
Mirrors = await mirrors,
|
||||
AllowedMirrors = new Lazy<Task<Dictionary<Hash, string>>>(async () => await GetAllowedMirrors()),
|
||||
AllAuthoredFiles = await authoredFiles,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,32 @@ namespace Wabbajack.Server.Services
|
||||
var oldSummary =
|
||||
oldSummaries.FirstOrDefault(s => s.Summary.MachineURL == metadata.Links.MachineURL);
|
||||
|
||||
var mainFile = await DownloadDispatcher.Infer(new Uri(metadata.Links.Download));
|
||||
var mainArchive = new Archive(mainFile!)
|
||||
{
|
||||
Size = metadata.DownloadMetadata!.Size,
|
||||
Hash = metadata.DownloadMetadata!.Hash
|
||||
};
|
||||
bool mainFailed = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (!await mainArchive.State.Verify(mainArchive))
|
||||
{
|
||||
mainFailed = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
mainFailed = true;
|
||||
}
|
||||
|
||||
var listArchives = await _sql.ModListArchives(metadata.Links.MachineURL);
|
||||
var archives = await listArchives.PMap(queue, async archive =>
|
||||
{
|
||||
if (mainFailed)
|
||||
return (archive, ArchiveStatus.InValid);
|
||||
|
||||
try
|
||||
{
|
||||
ReportStarting(archive.State.PrimaryKeyString);
|
||||
@ -107,6 +130,7 @@ namespace Wabbajack.Server.Services
|
||||
Mirrored = mirroredCount,
|
||||
MachineURL = metadata.Links.MachineURL,
|
||||
Name = metadata.Title,
|
||||
ModListIsMissing = mainFailed
|
||||
};
|
||||
|
||||
var detailed = new DetailedStatus
|
||||
|
@ -144,6 +144,7 @@ namespace Wabbajack.Server
|
||||
//app.UseService<MirrorQueueService>();
|
||||
app.UseService<Watchdog>();
|
||||
app.UseService<DiscordFrontend>();
|
||||
// Don't enable Author Files Cleanup
|
||||
//app.UseService<AuthoredFilesCleanup>();
|
||||
app.UseService<MetricsKeyCache>();
|
||||
|
||||
|
@ -46,6 +46,8 @@
|
||||
<EmbeddedResource Include="sheo_quotes.txt" />
|
||||
<None Remove="Controllers\Templates\TotalListTemplate.html" />
|
||||
<EmbeddedResource Include="Controllers\Templates\TotalListTemplate.html" />
|
||||
<None Remove="Controllers\Templates\AuthorControls.html" />
|
||||
<EmbeddedResource Include="Controllers\Templates\AuthorControls.html" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using ReactiveUI;
|
||||
@ -19,6 +21,7 @@ namespace Wabbajack
|
||||
public ICommand SelectFile { get; }
|
||||
public ICommand HyperlinkCommand { get; }
|
||||
public IReactiveCommand Upload { get; }
|
||||
public IReactiveCommand ManageFiles { get; }
|
||||
|
||||
[Reactive] public double UploadProgress { get; set; }
|
||||
[Reactive] public string FinalUrl { get; set; }
|
||||
@ -42,6 +45,12 @@ namespace Wabbajack
|
||||
|
||||
HyperlinkCommand = ReactiveCommand.Create(() => Clipboard.SetText(FinalUrl));
|
||||
|
||||
ManageFiles = ReactiveCommand.Create(async () =>
|
||||
{
|
||||
var authorApiKey = await AuthorAPI.GetAPIKey();
|
||||
Utils.OpenWebsite(new Uri($"{Consts.WabbajackBuildServerUri}author_controls/login/{authorApiKey}"));
|
||||
});
|
||||
|
||||
Upload = ReactiveCommand.Create(async () =>
|
||||
{
|
||||
_isUploading.OnNext(true);
|
||||
@ -69,5 +78,6 @@ namespace Wabbajack
|
||||
.CombineLatest(Picker.WhenAnyValue(t => t.TargetPath).Select(f => f != default),
|
||||
(a, b) => a && b));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,24 +26,25 @@
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="300" />
|
||||
<ColumnDefinition Width="300" />
|
||||
<ColumnDefinition Width="200" />
|
||||
<ColumnDefinition Width="200" />
|
||||
<ColumnDefinition Width="200" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.ColumnSpan="2"
|
||||
<TextBlock Grid.ColumnSpan="3"
|
||||
Margin="5,0"
|
||||
FontFamily="Lucida Sans"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
Text="File Uploader" />
|
||||
<TextBlock Grid.Row="1" Grid.ColumnSpan="2"
|
||||
<TextBlock Grid.Row="1" Grid.ColumnSpan="3"
|
||||
Margin="5"
|
||||
Text="{Binding AuthorFile.Picker.TargetPath}" />
|
||||
<ProgressBar Grid.Row="2" Grid.ColumnSpan="2"
|
||||
<ProgressBar Grid.Row="2" Grid.ColumnSpan="3"
|
||||
Margin="5"
|
||||
Maximum="1"
|
||||
Minimum="0"
|
||||
Value="{Binding AuthorFile.UploadProgress, Mode=OneWay}" />
|
||||
<TextBlock Grid.Row="3" Grid.ColumnSpan="2"
|
||||
<TextBlock Grid.Row="3" Grid.ColumnSpan="3"
|
||||
Margin="5">
|
||||
<Hyperlink Command="{Binding AuthorFile.HyperlinkCommand}">
|
||||
<TextBlock Text="{Binding AuthorFile.FinalUrl}" />
|
||||
@ -55,10 +56,15 @@
|
||||
Select
|
||||
</Button>
|
||||
<Button Grid.Row="4" Grid.Column="1"
|
||||
Margin="5"
|
||||
Command="{Binding AuthorFile.Upload}">
|
||||
Margin="5"
|
||||
Command="{Binding AuthorFile.Upload}">
|
||||
Upload
|
||||
</Button>
|
||||
<Button Grid.Row="4" Grid.Column="2"
|
||||
Margin="5"
|
||||
Command="{Binding AuthorFile.ManageFiles}">
|
||||
Manage Files
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
</rxui:ReactiveUserControl>
|
||||
|
Loading…
Reference in New Issue
Block a user