Skip to content

Commit

Permalink
Client fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Oct 15, 2023
1 parent 7cc06ef commit e6fff36
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/BUTR.Site.NexusMods.Client/Components/Spinner.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Leave raw -->
@* Leave raw *@
<div class="loading">
<div class="loader"></div>
</div>
11 changes: 5 additions & 6 deletions src/BUTR.Site.NexusMods.Client/Models/DemoUser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BUTR.CrashReport.Bannerlord.Parser;
using BUTR.CrashReport.Models;
using BUTR.Site.NexusMods.ServerClient;
using BUTR.Site.NexusMods.Shared.Helpers;

Expand All @@ -10,7 +9,7 @@
using System.Net.Http;
using System.Threading.Tasks;

using CrashReportModel = BUTR.Site.NexusMods.ServerClient.CrashReportModel;
using ExceptionModel = BUTR.CrashReport.Models.ExceptionModel;

namespace BUTR.Site.NexusMods.Client.Models;

Expand All @@ -25,11 +24,11 @@ public static class DemoUser
new(3, "Demo Mod 3", ImmutableArray<int>.Empty, ImmutableArray<int>.Empty, ImmutableArray<string>.Empty, ImmutableArray<string>.Empty),
new(4, "Demo Mod 4", ImmutableArray<int>.Empty, ImmutableArray<int>.Empty, ImmutableArray<string>.Empty, ImmutableArray<string>.Empty),
};
private static List<CrashReportModel>? _crashReports;
private static List<CrashReportModel2>? _crashReports;

public static Task<ProfileModel> GetProfile() => Task.FromResult(_profile);
public static IAsyncEnumerable<NexusModsModModel> GetMods() => _mods.ToAsyncEnumerable();
public static async IAsyncEnumerable<CrashReportModel> GetCrashReports(IHttpClientFactory factory)
public static async IAsyncEnumerable<CrashReportModel2> GetCrashReports(IHttpClientFactory factory)
{
static string GetException(ExceptionModel? exception, bool inner = false) => exception is null ? string.Empty : $"""
Expand All @@ -53,14 +52,14 @@ static string GetException(ExceptionModel? exception, bool inner = false) => exc

if (_crashReports is null)
{
var crm = new List<CrashReportModel>();
var crm = new List<CrashReportModel2>();
const string baseUrl = "https://report.butr.link/";
var client = factory.CreateClient("InternalReports");
var reports = new[] { "4DDA8D", "6FB0EF", "2AE0EA", "F966E3" };
var contents = await Task.WhenAll(reports.Select(r => DownloadReport(client, r)));
foreach (var (id, cr) in contents)
{
var report = new CrashReportModel(cr.Id, cr.Version, cr.GameVersion, cr.Exception.Type, GetException(cr.Exception), DateTime.UtcNow, $"{baseUrl}{id}.html", cr.Modules.Select(x => x.Id).ToArray(), CrashReportStatus.New, string.Empty);
var report = new CrashReportModel2(cr.Id, cr.Version, cr.GameVersion, cr.Exception.Type, GetException(cr.Exception), DateTime.UtcNow, $"{baseUrl}{id}.html", cr.Modules.Select(x => x.Id).ToArray(), CrashReportStatus.New, string.Empty);
crm.Add(report);
yield return report;

Expand Down
4 changes: 2 additions & 2 deletions src/BUTR.Site.NexusMods.Client/Pages/Basic/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<CardTitle Size="4" Margin="@Margin.Is0">Settings</CardTitle>
</CardHeader>
<CardBody>
<!--
@*
<AuthorizeView Roles="@(ApplicationRoles.Administrator)">
<Row>
<Column ColumnSize="@ColumnSize.Is4">
Expand All @@ -24,7 +24,7 @@
</Column>
</Row>
</AuthorizeView>
-->
*@
<Row>
<Column ColumnSize="@ColumnSize.Is4">
<Card Shadow="@Shadow.Small">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
<FigureImage Margin="@Margin.Is0" Source="@_image" AlternateText="A meme image displaying success or failure. Success is Brent Rambo giving a thumbs up. Failure is a horse failing to play with a gymnastics by kinda lying onto it ball and falling."></FigureImage>
</Row>
}
<!--
@*
<Row Margin="@Margin.Is2">
<Span>Use the "Linked Roles" option in servers with the BUTR Discord bot to claim your roles.</Span>
</Row>
-->
*@

<Row Margin="@Margin.Is2">
<Button Border="@Border.RoundedPill"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@attribute [Authorize(Roles = $"{ApplicationRoles.Administrator}, {ApplicationRoles.Moderator}")]
@*
@attribute [Authorize(Roles = $"{ApplicationRoles.Administrator}, {ApplicationRoles.Moderator}")]
@page "/recreate-stacktrace/{Id}"
@inject IRecreateStacktraceClient _recreateStacktraceClient
Expand Down Expand Up @@ -35,4 +36,5 @@
recreatedStacktraces = response.Data;
}
}
}
*@
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@attribute [Authorize(Roles = $"{ApplicationRoles.Administrator}, {ApplicationRoles.Moderator}")]
@*
@attribute [Authorize(Roles = $"{ApplicationRoles.Administrator}, {ApplicationRoles.Moderator}")]
@page "/recreate-stacktrace-prerendered/{Id}"
@inject IRecreateStacktraceClient _recreateStacktraceClient
Expand All @@ -22,4 +23,5 @@
html = await _recreateStacktraceClient.HtmlAsync(Id, CancellationToken.None);
}
}
}
*@
20 changes: 10 additions & 10 deletions src/BUTR.Site.NexusMods.Client/Pages/User/CrashReportsViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@
</CardTitle>
</CardHeader>
<CardBody>
<DataGridStreamingPaging @ref="@_datagridPagingRef" TItem="CrashReportModel" GetFilters="@GetFilters" GetItems="@GetCrashReports" Sortable Filterable DefaultPageSize="@UserSettings.DefaultCrashReportPageSize" PageSizes="@UserSettings.AvailableCrashReportPageSizes" GetPageSize="@(x => x.CrashReportPageSize)">
<DataGridStreamingPaging @ref="@_datagridPagingRef" TItem="CrashReportModel2" GetFilters="@GetFilters" GetItems="@GetCrashReports" Sortable Filterable DefaultPageSize="@UserSettings.DefaultCrashReportPageSize" PageSizes="@UserSettings.AvailableCrashReportPageSizes" GetPageSize="@(x => x.CrashReportPageSize)">
<DataGridColumns>
<DataGridColumnText TItem="CrashReportModel" Field="@nameof(CrashReportModel.GameVersion)" Caption="Game Version" Filterable Placeholder="v1.0.0" Sortable SortField="@nameof(EntityFields.GameVersion)"/>
<DataGridColumnTextAutocomplete TItem="CrashReportModel" Field="@nameof(CrashReportModel.InvolvedModules)" Caption="Top Involved Module" Filterable Sortable SortField="@nameof(EntityFields.TopInvolvedModuleId)" GetAutocompleteValues="@GetAutocompleteValues">
<DataGridColumnText TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.GameVersion)" Caption="Game Version" Filterable Placeholder="v1.0.0" Sortable SortField="@nameof(EntityFields.GameVersion)"/>
<DataGridColumnTextAutocomplete TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.InvolvedModules)" Caption="Top Involved Module" Filterable Sortable SortField="@nameof(EntityFields.TopInvolvedModuleId)" GetAutocompleteValues="@GetAutocompleteValues">
<DisplayTemplate>@(context.InvolvedModules.FirstOrDefault())</DisplayTemplate>
</DataGridColumnTextAutocomplete>
<DataGridColumnText TItem="CrashReportModel" Field="@nameof(CrashReportModel.ExceptionType)" Caption="Exception" Filterable Placeholder="System.NullReferenceException" Sortable SortField="@nameof(EntityFields.ExceptionType)"/>
<DataGridColumnText TItem="CrashReportModel" Field="@nameof(CrashReportModel.Version)" Caption="Version" Filterable Placeholder="1" Sortable SortField="@nameof(EntityFields.Version)"/>
<DataGridColumnDate TItem="CrashReportModel" Field="@nameof(CrashReportModel.Date)" Caption="Date (UTC)" Filterable Sortable SortField="@nameof(EntityFields.CreatedAt)">
<DataGridColumnText TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.ExceptionType)" Caption="Exception" Filterable Placeholder="System.NullReferenceException" Sortable SortField="@nameof(EntityFields.ExceptionType)"/>
<DataGridColumnText TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.Version)" Caption="Version" Filterable Placeholder="1" Sortable SortField="@nameof(EntityFields.Version)"/>
<DataGridColumnDate TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.Date)" Caption="Date (UTC)" Filterable Sortable SortField="@nameof(EntityFields.CreatedAt)">
<DisplayTemplate>@(context.Date.ToString("yyyy-MM-dd HH:mm:ss"))</DisplayTemplate>
</DataGridColumnDate>
<DataGridColumnEnum TItem="CrashReportModel" Field="@nameof(CrashReportModel.Status)" Caption="Status" Filterable Sortable SortField="@nameof(EntityFields.Status)">
<DataGridColumnEnum TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.Status)" Caption="Status" Filterable Sortable SortField="@nameof(EntityFields.Status)">
<DisplayTemplate>@(context.Status.GetDisplayName())</DisplayTemplate>
</DataGridColumnEnum>
<DataGridColumnText TItem="CrashReportModel" Field="@nameof(CrashReportModel.Comment)" Caption="Comment" Filterable Sortable SortField="@nameof(EntityFields.Comment)"/>
<DataGridColumnText TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.Comment)" Caption="Comment" Filterable Sortable SortField="@nameof(EntityFields.Comment)"/>
</DataGridColumns>

<ButtonRowTemplate>
Expand All @@ -95,7 +95,7 @@
private enum EntityFields { GameVersion, Version, TopInvolvedModuleId, ExceptionType, CreatedAt, Status, Comment }

private Modal _modalRef = default!;
private DataGridStreamingPaging<CrashReportModel>? _datagridPagingRef;
private DataGridStreamingPaging<CrashReportModel2>? _datagridPagingRef;
private UserSettings? _userSettings;

/// <inheritdoc />
Expand Down Expand Up @@ -129,7 +129,7 @@
await _jsRuntime.InvokeVoidAsync("open", report.Url, "_blank");
}

private async Task<PagingStreamingData<CrashReportModel>?> GetCrashReports(int page, int pageSize, ICollection<Filtering> filterings, ICollection<Sorting> sortings, CancellationToken ct = default) =>
private async Task<PagingStreamingData<CrashReportModel2>?> GetCrashReports(int page, int pageSize, ICollection<Filtering> filterings, ICollection<Sorting> sortings, CancellationToken ct = default) =>
await _crashReportsClient.PaginatedStreamingAsync(new(page, pageSize, filterings, sortings), ct);

private async Task<ICollection<string>> GetAutocompleteValues(string filter) => await _crashReportsClient.AutocompleteAsync(new(filter)) is { Data: { } data } ? data : Array.Empty<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.Site.NexusMods.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static WebAssemblyHostBuilder CreateHostBuilder(string[] args)
services.AddTransient<IGOGClient, GOGClient>(sp => ConfigureClient(sp, (http, opt) => new GOGClient(http, opt)));
services.AddTransient<IStatisticsClient, StatisticsClient>(sp => ConfigureClient(sp, (http, opt) => new StatisticsClient(http, opt)));
services.AddTransient<IQuartzClient, QuartzClient>(sp => ConfigureClient(sp, (http, opt) => new QuartzClient(http, opt)));
services.AddTransient<IRecreateStacktraceClient, RecreateStacktraceClient>(sp => ConfigureClient(sp, (http, opt) => new RecreateStacktraceClient(http, opt)));
//services.AddTransient<IRecreateStacktraceClient, RecreateStacktraceClient>(sp => ConfigureClient(sp, (http, opt) => new RecreateStacktraceClient(http, opt)));

services.AddScoped<TenantProvider>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ public CrashReportsClientWithDemo(IServiceProvider serviceProvider, ITokenContai
_httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
}

public async Task<PagingStreamingData<CrashReportModel>> PaginatedStreamingAsync(PaginatedQuery? body = null, CancellationToken ct = default)
public async Task<PagingStreamingData<CrashReportModel2>> PaginatedStreamingAsync(PaginatedQuery? body = null, CancellationToken ct = default)
{
var token = await _tokenContainer.GetTokenAsync(ct);
if (token?.Type.Equals("demo", StringComparison.OrdinalIgnoreCase) == true)
{
var crashReports = await DemoUser.GetCrashReports(_httpClientFactory).ToListAsync(ct);
return PagingStreamingData<CrashReportModel>.Create(new PagingMetadata(1, (int) Math.Ceiling((double) crashReports.Count / body.PageSize), body.PageSize, crashReports.Count), crashReports.ToAsyncEnumerable(), PagingAdditionalMetadata.Empty);
return PagingStreamingData<CrashReportModel2>.Create(new PagingMetadata(1, (int) Math.Ceiling((double) crashReports.Count / body.PageSize), body.PageSize, crashReports.Count), crashReports.ToAsyncEnumerable(), PagingAdditionalMetadata.Empty);

Check warning on line 49 in src/BUTR.Site.NexusMods.Client/Services/CrashReportsClientWithDemo.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

return await _implementation.PaginatedStreamingAsync(new PaginatedQuery(body.Page, body.PageSize, body.Filters, body.Sotings), ct);

Check warning on line 52 in src/BUTR.Site.NexusMods.Client/Services/CrashReportsClientWithDemo.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

public async Task<CrashReportModelPagingDataAPIResponse> PaginatedAsync(PaginatedQuery? body, CancellationToken ct)
public async Task<CrashReportModel2PagingDataAPIResponse> PaginatedAsync(PaginatedQuery? body, CancellationToken ct)
{
var token = await _tokenContainer.GetTokenAsync(ct);
if (token?.Type.Equals("demo", StringComparison.OrdinalIgnoreCase) == true)
{
var crashReports = await DemoUser.GetCrashReports(_httpClientFactory).ToListAsync(ct);
return new CrashReportModelPagingDataAPIResponse(new CrashReportModelPagingData(PagingAdditionalMetadata.Empty, crashReports, new PagingMetadata(1, (int) Math.Ceiling((double) crashReports.Count / body.PageSize), body.PageSize, crashReports.Count)), string.Empty);
return new CrashReportModel2PagingDataAPIResponse(new CrashReportModel2PagingData(PagingAdditionalMetadata.Empty, crashReports, new PagingMetadata(1, (int) Math.Ceiling((double) crashReports.Count / body.PageSize), body.PageSize, crashReports.Count)), string.Empty);
}

return await _implementation.PaginatedAsync(new PaginatedQuery(body.Page, body.PageSize, body.Filters, body.Sotings), ct);
Expand All @@ -76,7 +76,7 @@ public async Task<StringIQueryableAPIResponse> AutocompleteAsync(string? modId,
return new StringIQueryableAPIResponse((await _implementation.AutocompleteAsync(modId, ct)).Data ?? Array.Empty<string>(), string.Empty);
}

public async Task<StringAPIResponse> UpdateAsync(CrashReportModel? body, CancellationToken ct)
public async Task<StringAPIResponse> UpdateAsync(CrashReportModel2? body, CancellationToken ct)
{
var token = await _tokenContainer.GetTokenAsync(ct);
if (token?.Type.Equals("demo", StringComparison.OrdinalIgnoreCase) == true)
Expand All @@ -86,4 +86,9 @@ public async Task<StringAPIResponse> UpdateAsync(CrashReportModel? body, Cancell

return await _implementation.UpdateAsync(body, ct);
}

public async Task<ModuleUpdateIEnumerableAPIResponse> GetUpdatesAsync(int? tenant, CrashReportModel? body, CancellationToken ct)
{
return await _implementation.GetUpdatesAsync(tenant, body, ct);
}
}
4 changes: 2 additions & 2 deletions src/BUTR.Site.NexusMods.Client/Shared/Header.razor
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@
<BarDropdownItem Background="@Background.Dark">
<BarLink To="statistics-involved-mods">Statistics Involved Mods</BarLink>
</BarDropdownItem>
<!--
@*
<BarDropdownItem Background="@Background.Dark">
<BarLink To="game-public-api-diff">Public API Diff</BarLink>
</BarDropdownItem>
<BarDropdownItem Background="@Background.Dark">
<BarLink To="game-public-api-diff-search">Public API Diff Search</BarLink>
</BarDropdownItem>
-->
*@
</Authorized>
</AuthorizeView>
<BarDropdownItem Background="@Background.Dark">
Expand Down
16 changes: 6 additions & 10 deletions src/BUTR.Site.NexusMods.ServerClient/Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AuthenticationClient(HttpClient client, JsonSerializerOptions options) :

public partial interface ICrashReportsClient
{
Task<PagingStreamingData<CrashReportModel>> PaginatedStreamingAsync(PaginatedQuery? body = null, CancellationToken cancellationToken = default);
Task<PagingStreamingData<CrashReportModel2>> PaginatedStreamingAsync(PaginatedQuery? body = null, CancellationToken cancellationToken = default);
}

public partial class CrashReportsClient
Expand All @@ -36,7 +36,7 @@ partial void PrepareRequest(HttpClient client, HttpRequestMessage request, Syste
OnPrepareRequest(client, request, urlBuilder);
}

public virtual async Task<PagingStreamingData<CrashReportModel>> PaginatedStreamingAsync(PaginatedQuery? body = null, CancellationToken cancellationToken = default)
public virtual async Task<PagingStreamingData<CrashReportModel2>> PaginatedStreamingAsync(PaginatedQuery? body = null, CancellationToken cancellationToken = default)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append("api/v1/CrashReports/PaginatedStreaming");
Expand Down Expand Up @@ -79,11 +79,11 @@ public virtual async Task<PagingStreamingData<CrashReportModel>> PaginatedStream
{
try
{
return PagingStreamingData<CrashReportModel>.Create(response_, JsonSerializerSettings, cancellationToken);
return PagingStreamingData<CrashReportModel2>.Create(response_, JsonSerializerSettings, cancellationToken);
}
catch (System.Text.Json.JsonException exception)
{
var message = "Could not deserialize the response body stream as " + typeof(PagingStreamingData<CrashReportModel>).FullName + ".";
var message = "Could not deserialize the response body stream as " + typeof(PagingStreamingData<CrashReportModel2>).FullName + ".";
throw new ApiException(message, (int) response_.StatusCode, string.Empty, headers_, exception);
}
}
Expand Down Expand Up @@ -217,19 +217,15 @@ public QuartzClient(HttpClient client, JsonSerializerOptions options) : this(cli
}
}

/*
public partial class RecreateStacktraceClient
{
public RecreateStacktraceClient(HttpClient client, JsonSerializerOptions options) : this(client)
{
_settings = new Lazy<JsonSerializerOptions>(options);
}
}

public partial record CrashReportModel
{
[JsonIgnore]
public string ExceptionHtml => Exception.Replace("\r", "<br/>").Replace("\r\n", "<br/>");
}
*/

public partial record NexusModsModModel
{
Expand Down

0 comments on commit e6fff36

Please sign in to comment.