start member add responder

This commit is contained in:
sam 2024-08-20 21:03:03 +02:00
parent 633ba8f600
commit f0cb5a9d03
3 changed files with 105 additions and 7 deletions

View file

@ -4,7 +4,6 @@ using System.Threading.RateLimiting;
using Humanizer;
using NodaTime;
using Polly;
using Remora.Rest.Json.Policies;
namespace Catalogger.Backend.Services;
@ -33,7 +32,7 @@ public class PluralkitApiService(ILogger logger)
_logger.Debug("Requesting {Path} from PluralKit API", path);
var resp = await _client.SendAsync(req, ct);
var resp = await _pipeline.ExecuteAsync(async ct2 => await _client.SendAsync(req, ct2), ct);
if (resp.StatusCode == HttpStatusCode.NotFound && allowNotFound)
{
_logger.Debug("PluralKit API path {Path} returned 404 but 404 response is valid", path);
@ -48,15 +47,15 @@ public class PluralkitApiService(ILogger logger)
}
return await resp.Content.ReadFromJsonAsync<T>(new JsonSerializerOptions
{ PropertyNamingPolicy = new SnakeCaseNamingPolicy() }, ct) ??
{ PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower }, ct) ??
throw new CataloggerError("JSON response from PluralKit API was null");
}
public async Task<PkMessage?> GetPluralKitMessageAsync(ulong id, CancellationToken ct = default) =>
await DoRequestAsync<PkMessage>($"/messages/{id}", allowNotFound: true, ct);
public async Task<PkSystem> GetPluralKitSystemAsync(ulong id, CancellationToken ct = default) =>
(await DoRequestAsync<PkSystem>($"/systems/{id}", allowNotFound: false, ct))!;
public async Task<PkSystem?> GetPluralKitSystemAsync(ulong id, CancellationToken ct = default) =>
await DoRequestAsync<PkSystem>($"/systems/{id}", allowNotFound: true, ct);
public record PkMessage(
ulong Id,