From b5b01cba4c2fb22b0f7470ac5ace0212d420cb13 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 25 Oct 2022 14:52:12 -0500 Subject: [PATCH] improve webfront command error feedback --- Application/Misc/RemoteCommandService.cs | 12 ++++++++++-- .../Interfaces/IRemoteCommandService.cs | 1 + WebfrontCore/Controllers/ActionController.cs | 4 +++- WebfrontCore/Controllers/ConsoleController.cs | 7 ++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Application/Misc/RemoteCommandService.cs b/Application/Misc/RemoteCommandService.cs index 0e58f324d..ccd573d3f 100644 --- a/Application/Misc/RemoteCommandService.cs +++ b/Application/Misc/RemoteCommandService.cs @@ -26,12 +26,20 @@ public class RemoteCommandService : IRemoteCommandService public async Task> Execute(int originId, int? targetId, string command, IEnumerable arguments, Server server) + { + var (success, result) = await ExecuteWithResult(originId, targetId, command, arguments, server); + + return result; + } + + public async Task<(bool, IEnumerable)> ExecuteWithResult(int originId, int? targetId, string command, + IEnumerable arguments, Server server) { if (originId < 1) { _logger.LogWarning("Not executing command {Command} for {Originid} because origin id is invalid", command, originId); - return Enumerable.Empty(); + return (false, Enumerable.Empty()); } var client = await _clientService.Get(originId); @@ -94,6 +102,6 @@ public class RemoteCommandService : IRemoteCommandService }; } - return response; + return (!remoteEvent.Failed, response); } } diff --git a/SharedLibraryCore/Interfaces/IRemoteCommandService.cs b/SharedLibraryCore/Interfaces/IRemoteCommandService.cs index 8099cd851..fa07c1d86 100644 --- a/SharedLibraryCore/Interfaces/IRemoteCommandService.cs +++ b/SharedLibraryCore/Interfaces/IRemoteCommandService.cs @@ -7,4 +7,5 @@ namespace SharedLibraryCore.Interfaces; public interface IRemoteCommandService { Task> Execute(int originId, int? targetId, string command, IEnumerable arguments, Server server); + Task<(bool, IEnumerable)> ExecuteWithResult(int originId, int? targetId, string command, IEnumerable arguments, Server server); } diff --git a/WebfrontCore/Controllers/ActionController.cs b/WebfrontCore/Controllers/ActionController.cs index 057117d80..dad7b354f 100644 --- a/WebfrontCore/Controllers/ActionController.cs +++ b/WebfrontCore/Controllers/ActionController.cs @@ -248,7 +248,9 @@ namespace WebfrontCore.Controllers } var server = Manager.GetServers().First(); - return Ok(await _remoteCommandService.Execute(Client.ClientId, targetId, data, inputs.Values.Select(input => input), server)); + var (success, result) = await _remoteCommandService.ExecuteWithResult(Client.ClientId, targetId, data, + inputs.Values.Select(input => input), server); + return success ? Ok(result) : BadRequest(result); } public IActionResult BanForm() diff --git a/WebfrontCore/Controllers/ConsoleController.cs b/WebfrontCore/Controllers/ConsoleController.cs index 3467d7e21..d47b8ffef 100644 --- a/WebfrontCore/Controllers/ConsoleController.cs +++ b/WebfrontCore/Controllers/ConsoleController.cs @@ -45,10 +45,11 @@ namespace WebfrontCore.Controllers } }); } - + var server = Manager.GetServers().First(s => s.EndPoint == serverId); - var response = await _remoteCommandService.Execute(Client.ClientId, null, command, Enumerable.Empty(), server); - return !response.Any() ? StatusCode(400, response) : Ok(response); + var (success, response) = await _remoteCommandService.ExecuteWithResult(Client.ClientId, null, command, + Enumerable.Empty(), server); + return success ? Ok(response) : StatusCode(400, response); } } }