improve webfront command error feedback

This commit is contained in:
RaidMax 2022-10-25 14:52:12 -05:00
parent 797642f3e6
commit b5b01cba4c
4 changed files with 18 additions and 6 deletions

View File

@ -26,12 +26,20 @@ public class RemoteCommandService : IRemoteCommandService
public async Task<IEnumerable<CommandResponseInfo>> Execute(int originId, int? targetId, string command, public async Task<IEnumerable<CommandResponseInfo>> Execute(int originId, int? targetId, string command,
IEnumerable<string> arguments, Server server) IEnumerable<string> arguments, Server server)
{
var (success, result) = await ExecuteWithResult(originId, targetId, command, arguments, server);
return result;
}
public async Task<(bool, IEnumerable<CommandResponseInfo>)> ExecuteWithResult(int originId, int? targetId, string command,
IEnumerable<string> arguments, Server server)
{ {
if (originId < 1) if (originId < 1)
{ {
_logger.LogWarning("Not executing command {Command} for {Originid} because origin id is invalid", command, _logger.LogWarning("Not executing command {Command} for {Originid} because origin id is invalid", command,
originId); originId);
return Enumerable.Empty<CommandResponseInfo>(); return (false, Enumerable.Empty<CommandResponseInfo>());
} }
var client = await _clientService.Get(originId); var client = await _clientService.Get(originId);
@ -94,6 +102,6 @@ public class RemoteCommandService : IRemoteCommandService
}; };
} }
return response; return (!remoteEvent.Failed, response);
} }
} }

View File

@ -7,4 +7,5 @@ namespace SharedLibraryCore.Interfaces;
public interface IRemoteCommandService public interface IRemoteCommandService
{ {
Task<IEnumerable<CommandResponseInfo>> Execute(int originId, int? targetId, string command, IEnumerable<string> arguments, Server server); Task<IEnumerable<CommandResponseInfo>> Execute(int originId, int? targetId, string command, IEnumerable<string> arguments, Server server);
Task<(bool, IEnumerable<CommandResponseInfo>)> ExecuteWithResult(int originId, int? targetId, string command, IEnumerable<string> arguments, Server server);
} }

View File

@ -248,7 +248,9 @@ namespace WebfrontCore.Controllers
} }
var server = Manager.GetServers().First(); 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() public IActionResult BanForm()

View File

@ -47,8 +47,9 @@ namespace WebfrontCore.Controllers
} }
var server = Manager.GetServers().First(s => s.EndPoint == serverId); var server = Manager.GetServers().First(s => s.EndPoint == serverId);
var response = await _remoteCommandService.Execute(Client.ClientId, null, command, Enumerable.Empty<string>(), server); var (success, response) = await _remoteCommandService.ExecuteWithResult(Client.ClientId, null, command,
return !response.Any() ? StatusCode(400, response) : Ok(response); Enumerable.Empty<string>(), server);
return success ? Ok(response) : StatusCode(400, response);
} }
} }
} }