General code cleanups

This commit is contained in:
Łukasz Domeradzki
2025-03-31 00:06:05 +02:00
parent c2b1d1356c
commit 61f876480a
20 changed files with 81 additions and 117 deletions

View File

@@ -301,8 +301,7 @@ internal static class ArchiKestrel {
}
// Add support for proxies
services.Configure<ForwardedHeadersOptions>(
options => {
services.Configure<ForwardedHeadersOptions>(options => {
options.ForwardedHeaders = ForwardedHeaders.All;
if (knownNetworks != null) {
@@ -351,8 +350,7 @@ internal static class ArchiKestrel {
}
}
services.ConfigureHttpJsonOptions(
static options => {
services.ConfigureHttpJsonOptions(static options => {
JsonSerializerOptions jsonSerializerOptions = Debugging.IsUserDebugging ? JsonUtilities.IndentedJsonSerialierOptions : JsonUtilities.DefaultJsonSerialierOptions;
options.SerializerOptions.PropertyNamingPolicy = jsonSerializerOptions.PropertyNamingPolicy;
@@ -377,8 +375,7 @@ internal static class ArchiKestrel {
mvc.AddControllersAsServices();
// Modify default JSON options
mvc.AddJsonOptions(
static options => {
mvc.AddJsonOptions(static options => {
JsonSerializerOptions jsonSerializerOptions = Debugging.IsUserDebugging ? JsonUtilities.IndentedJsonSerialierOptions : JsonUtilities.DefaultJsonSerialierOptions;
options.JsonSerializerOptions.PropertyNamingPolicy = jsonSerializerOptions.PropertyNamingPolicy;
@@ -439,8 +436,7 @@ internal static class ArchiKestrel {
builder.WebHost.UseConfiguration(new ConfigurationBuilder().SetBasePath(absoluteConfigDirectory).AddJsonFile(SharedInfo.IPCConfigFile, false, true).Build());
}
builder.WebHost.ConfigureKestrel(
options => {
builder.WebHost.ConfigureKestrel(options => {
options.AddServerHeader = false;
if (customConfigExists) {

View File

@@ -279,30 +279,6 @@ public sealed class BotController : ArchiController {
return Ok(results.All(static result => result) ? new GenericResponse(true) : new GenericResponse(false, Strings.WarningFailed));
}
[EndpointSummary("Fetches general inventory information of given bots")]
[HttpGet("{botNames:required}/Inventory")]
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, ImmutableDictionary<uint, InventoryAppData>>>>((int) HttpStatusCode.OK)]
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.BadRequest)]
public async Task<ActionResult<GenericResponse>> InventoryInfoGet(string botNames) {
ArgumentException.ThrowIfNullOrEmpty(botNames);
HashSet<Bot>? bots = Bot.GetBots(botNames);
if ((bots == null) || (bots.Count == 0)) {
return BadRequest(new GenericResponse(false, Strings.FormatBotNotFound(botNames)));
}
IList<ImmutableDictionary<uint, InventoryAppData>?> results = await Utilities.InParallel(bots.Select(static bot => bot.ArchiWebHandler.GetInventoryContextData())).ConfigureAwait(false);
Dictionary<string, ImmutableDictionary<uint, InventoryAppData>?> result = new(bots.Count, Bot.BotsComparer);
foreach (Bot bot in bots) {
result[bot.BotName] = results[result.Count];
}
return Ok(new GenericResponse<IReadOnlyDictionary<string, ImmutableDictionary<uint, InventoryAppData>?>>(result));
}
[EndpointSummary("Fetches specific inventory of given bots")]
[HttpGet("{botNames:required}/Inventory/{appID}/{contextID}")]
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, BotInventoryResponse>>>((int) HttpStatusCode.OK)]
@@ -354,6 +330,30 @@ public sealed class BotController : ArchiController {
return Ok(new GenericResponse<IReadOnlyDictionary<string, BotInventoryResponse>>(result));
}
[EndpointSummary("Fetches general inventory information of given bots")]
[HttpGet("{botNames:required}/Inventory")]
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, ImmutableDictionary<uint, InventoryAppData>>>>((int) HttpStatusCode.OK)]
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.BadRequest)]
public async Task<ActionResult<GenericResponse>> InventoryInfoGet(string botNames) {
ArgumentException.ThrowIfNullOrEmpty(botNames);
HashSet<Bot>? bots = Bot.GetBots(botNames);
if ((bots == null) || (bots.Count == 0)) {
return BadRequest(new GenericResponse(false, Strings.FormatBotNotFound(botNames)));
}
IList<ImmutableDictionary<uint, InventoryAppData>?> results = await Utilities.InParallel(bots.Select(static bot => bot.ArchiWebHandler.GetInventoryContextData())).ConfigureAwait(false);
Dictionary<string, ImmutableDictionary<uint, InventoryAppData>?> result = new(bots.Count, Bot.BotsComparer);
foreach (Bot bot in bots) {
result[bot.BotName] = results[result.Count];
}
return Ok(new GenericResponse<IReadOnlyDictionary<string, ImmutableDictionary<uint, InventoryAppData>?>>(result));
}
[EndpointSummary("Pauses given bots")]
[HttpPost("{botNames:required}/Pause")]
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.OK)]

View File

@@ -52,7 +52,7 @@ internal sealed class OperationTransformer : IOpenApiOperationTransformer {
}
},
Array.Empty<string>()
[]
}
}
);