diff --git a/Application/Misc/RemoteCommandService.cs b/Application/Misc/RemoteCommandService.cs index 0e58f324..ccd573d3 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 8099cd85..fa07c1d8 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 057117d8..dad7b354 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 3467d7e2..d47b8ffe 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); } } }