improve webfront command error feedback
This commit is contained in:
parent
797642f3e6
commit
b5b01cba4c
@ -26,12 +26,20 @@ public class RemoteCommandService : IRemoteCommandService
|
||||
|
||||
public async Task<IEnumerable<CommandResponseInfo>> Execute(int originId, int? targetId, string command,
|
||||
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)
|
||||
{
|
||||
_logger.LogWarning("Not executing command {Command} for {Originid} because origin id is invalid", command,
|
||||
originId);
|
||||
return Enumerable.Empty<CommandResponseInfo>();
|
||||
return (false, Enumerable.Empty<CommandResponseInfo>());
|
||||
}
|
||||
|
||||
var client = await _clientService.Get(originId);
|
||||
@ -94,6 +102,6 @@ public class RemoteCommandService : IRemoteCommandService
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
return (!remoteEvent.Failed, response);
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,5 @@ namespace SharedLibraryCore.Interfaces;
|
||||
public interface IRemoteCommandService
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -47,8 +47,9 @@ namespace WebfrontCore.Controllers
|
||||
}
|
||||
|
||||
var server = Manager.GetServers().First(s => s.EndPoint == serverId);
|
||||
var response = await _remoteCommandService.Execute(Client.ClientId, null, command, Enumerable.Empty<string>(), server);
|
||||
return !response.Any() ? StatusCode(400, response) : Ok(response);
|
||||
var (success, response) = await _remoteCommandService.ExecuteWithResult(Client.ClientId, null, command,
|
||||
Enumerable.Empty<string>(), server);
|
||||
return success ? Ok(response) : StatusCode(400, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user