-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
376 additions
and
9 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/BUTR.Site.NexusMods.Client/Options/CrashReporterOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace BUTR.Site.NexusMods.Client.Options; | ||
|
||
public sealed record CrashReporterOptions | ||
{ | ||
public required string Endpoint { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/BUTR.Site.NexusMods.Client/Services/HttpClient/ICrashReporterClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using BUTR.Site.NexusMods.ServerClient; | ||
|
||
using Microsoft.Extensions.Options; | ||
|
||
using System; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace BUTR.Site.NexusMods.Client.Services; | ||
|
||
public interface ICrashReporterClient | ||
{ | ||
Task<CrashReportModel?> GetCrashReportModelAsync(string id, CancellationToken ct); | ||
} | ||
|
||
public sealed class CrashReporterClient : ICrashReporterClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly JsonSerializerOptions _jsonSerializerOptions; | ||
|
||
public CrashReporterClient(HttpClient httpClient, IOptions<JsonSerializerOptions> jsonSerializerOptions) | ||
{ | ||
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); | ||
_jsonSerializerOptions = jsonSerializerOptions.Value ?? throw new ArgumentNullException(nameof(jsonSerializerOptions)); | ||
} | ||
|
||
public async Task<CrashReportModel?> GetCrashReportModelAsync(string id, CancellationToken ct) | ||
{ | ||
using var request = new HttpRequestMessage(HttpMethod.Get, $"{id}.json"); | ||
using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, ct); | ||
if (!response.IsSuccessStatusCode) return null; | ||
return await JsonSerializer.DeserializeAsync<CrashReportModel>(await response.Content.ReadAsStreamAsync(ct), _jsonSerializerOptions, ct); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"Backend": { | ||
"Endpoint": "https://sitenexusmods.butr.link/" | ||
}, | ||
"CrashReporter": { | ||
"Endpoint": "https://report.butr.link/" | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/BUTR.Site.NexusMods.Server.ValueObjects.Vogen/Extensions/StringExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Diagnostics.Contracts; | ||
|
||
namespace BUTR.Site.NexusMods.Server.Models; | ||
|
||
internal static class StringExtensions | ||
{ | ||
[Pure] | ||
public static LineSplitEnumerator SplitLines(this string str) => new(str.AsSpan()); | ||
|
||
[StructLayout(LayoutKind.Auto)] | ||
[SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "<Pending>")] | ||
public ref struct LineSplitEnumerator | ||
{ | ||
private ReadOnlySpan<char> _str; | ||
|
||
public LineSplitEnumerator(ReadOnlySpan<char> str) | ||
{ | ||
_str = str; | ||
Current = default; | ||
} | ||
|
||
public readonly LineSplitEnumerator GetEnumerator() => this; | ||
|
||
public bool MoveNext() | ||
{ | ||
if (_str.Length == 0) | ||
return false; | ||
|
||
var span = _str; | ||
var index = span.IndexOfAny('\r', '\n'); | ||
if (index == -1) | ||
{ | ||
_str = ReadOnlySpan<char>.Empty; | ||
Current = new LineSplitEntry(span, ReadOnlySpan<char>.Empty); | ||
return true; | ||
} | ||
|
||
if (index < span.Length - 1 && span[index] == '\r') | ||
{ | ||
var next = span[index + 1]; | ||
if (next == '\n') | ||
{ | ||
Current = new LineSplitEntry(span[..index], span.Slice(index, 2)); | ||
_str = span[(index + 2)..]; | ||
return true; | ||
} | ||
} | ||
|
||
Current = new LineSplitEntry(span[..index], span.Slice(index, 1)); | ||
_str = span[(index + 1)..]; | ||
return true; | ||
} | ||
|
||
public LineSplitEntry Current { get; private set; } | ||
} | ||
|
||
[StructLayout(LayoutKind.Auto)] | ||
[SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "<Pending>")] | ||
public readonly ref struct LineSplitEntry | ||
{ | ||
public LineSplitEntry(ReadOnlySpan<char> line, ReadOnlySpan<char> separator) | ||
{ | ||
Line = line; | ||
Separator = separator; | ||
} | ||
|
||
public ReadOnlySpan<char> Line { get; } | ||
public ReadOnlySpan<char> Separator { get; } | ||
|
||
public void Deconstruct(out ReadOnlySpan<char> line, out ReadOnlySpan<char> separator) | ||
{ | ||
line = Line; | ||
separator = Separator; | ||
} | ||
|
||
public static implicit operator ReadOnlySpan<char>(LineSplitEntry entry) => entry.Line; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.