From 4885b2c5b68f50e96dfeee97d597aa06f5273480 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Fri, 1 Jan 2021 23:14:02 -0500 Subject: [PATCH] Fix /Configuration pagination --- .../Controllers/ConfigurationController.cs | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs index 1e07d538ce..f4688a200c 100644 --- a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs +++ b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api; @@ -186,45 +187,40 @@ namespace Tgstation.Server.Host.Controllers [FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) - => Paginated( - async () => - { - if (ForbidDueToModeConflicts(directoryPath, out var systemIdentity)) - return new PaginatableResult( - Forbid()); + => WithComponentInstance( + instance => Paginated( + async () => + { + if (ForbidDueToModeConflicts(directoryPath, out var systemIdentity)) + return new PaginatableResult( + Forbid()); - try - { - return new PaginatableResult( - await WithComponentInstance( - async instance => - { - var result = await instance - .Configuration - .ListDirectory(directoryPath, systemIdentity, cancellationToken) - .ConfigureAwait(false); - if (result == null) - return Gone(); + try + { + var result = await instance + .Configuration + .ListDirectory(directoryPath, systemIdentity, cancellationToken) + .ConfigureAwait(false); + if (result == null) + return new PaginatableResult(Gone()); - return Json(result); - }) - .ConfigureAwait(false)); - } - catch (NotImplementedException) - { - return new PaginatableResult( - RequiresPosixSystemIdentity()); - } - catch (UnauthorizedAccessException) - { - return new PaginatableResult( - Forbid()); - } - }, - null, - page, - pageSize, - cancellationToken); + return new PaginatableResult(result.AsQueryable()); + } + catch (NotImplementedException) + { + return new PaginatableResult( + RequiresPosixSystemIdentity()); + } + catch (UnauthorizedAccessException) + { + return new PaginatableResult( + Forbid()); + } + }, + null, + page, + pageSize, + cancellationToken)); /// /// Get the contents of the root configuration directory.