Show User Agent in System->Tasks for externally triggered commands (#1047)

* Show User Agent in System->Tasks for externally triggered commands

(cherry picked from commit fe8f319f7bfdadb7218b6313ada6cae1d2a35ad8)

* Fix ESLint

(cherry picked from commit c3837c9f7b50534e3eafe1d9fbaf360fee4588b7)

* fixup

Co-authored-by: Taloth Saldono <Taloth@users.noreply.github.com>
Co-authored-by: Mark McDowall <mark@mcdowall.ca>
pull/1052/head
Robin Dadswell 4 years ago committed by GitHub
parent 8711c5d824
commit 6acd42e82b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,6 +10,15 @@
width: 100%; width: 100%;
} }
.commandName {
display: inline-block;
min-width: 220px;
}
.userAgent {
color: #b0b0b0;
}
.queued, .queued,
.started, .started,
.ended { .ended {

@ -157,6 +157,7 @@ class QueuedTaskRow extends Component {
status, status,
duration, duration,
message, message,
clientUserAgent,
longDateFormat, longDateFormat,
timeFormat, timeFormat,
onCancelPress onCancelPress
@ -192,7 +193,18 @@ class QueuedTaskRow extends Component {
</span> </span>
</TableRowCell> </TableRowCell>
<TableRowCell>{commandName}</TableRowCell> <TableRowCell>
<span className={styles.commandName}>
{commandName}
</span>
{
clientUserAgent ?
<span className={styles.userAgent} title="User-Agent provided by the app that called the API">
from: {clientUserAgent}
</span> :
null
}
</TableRowCell>
<TableRowCell <TableRowCell
className={styles.queued} className={styles.queued}
@ -256,6 +268,7 @@ QueuedTaskRow.propTypes = {
status: PropTypes.string.isRequired, status: PropTypes.string.isRequired,
duration: PropTypes.string, duration: PropTypes.string,
message: PropTypes.string, message: PropTypes.string,
clientUserAgent: PropTypes.string,
showRelativeDates: PropTypes.bool.isRequired, showRelativeDates: PropTypes.bool.isRequired,
shortDateFormat: PropTypes.string.isRequired, shortDateFormat: PropTypes.string.isRequired,
longDateFormat: PropTypes.string.isRequired, longDateFormat: PropTypes.string.isRequired,

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NzbDrone.Common.Http
{
public static class UserAgentParser
{
public static string SimplifyUserAgent(string userAgent)
{
if (userAgent == null || userAgent.StartsWith("Mozilla/5.0"))
{
return null;
}
return userAgent;
}
}
}

@ -35,6 +35,8 @@ namespace NzbDrone.Core.Messaging.Commands
public CommandTrigger Trigger { get; set; } public CommandTrigger Trigger { get; set; }
public bool SuppressMessages { get; set; } public bool SuppressMessages { get; set; }
public string ClientUserAgent { get; set; }
public Command() public Command()
{ {
Name = GetType().Name.Replace("Command", ""); Name = GetType().Name.Replace("Command", "");

@ -63,6 +63,7 @@ namespace Readarr.Api.V1.Commands
command.Trigger = CommandTrigger.Manual; command.Trigger = CommandTrigger.Manual;
command.SuppressMessages = !command.SendUpdatesToClient; command.SuppressMessages = !command.SendUpdatesToClient;
command.SendUpdatesToClient = true; command.SendUpdatesToClient = true;
command.ClientUserAgent = Request.Headers["User-Agent"];
var trackedCommand = _commandQueueManager.Push(command, CommandPriority.Normal, CommandTrigger.Manual); var trackedCommand = _commandQueueManager.Push(command, CommandPriority.Normal, CommandTrigger.Manual);
return Created(trackedCommand.Id); return Created(trackedCommand.Id);

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using Readarr.Http.REST; using Readarr.Http.REST;
@ -23,6 +24,8 @@ namespace Readarr.Api.V1.Commands
public string Exception { get; set; } public string Exception { get; set; }
public CommandTrigger Trigger { get; set; } public CommandTrigger Trigger { get; set; }
public string ClientUserAgent { get; set; }
[JsonIgnore] [JsonIgnore]
public string CompletionMessage { get; set; } public string CompletionMessage { get; set; }
@ -106,6 +109,8 @@ namespace Readarr.Api.V1.Commands
Exception = model.Exception, Exception = model.Exception,
Trigger = model.Trigger, Trigger = model.Trigger,
ClientUserAgent = UserAgentParser.SimplifyUserAgent(model.Body.ClientUserAgent),
CompletionMessage = model.Body.CompletionMessage, CompletionMessage = model.Body.CompletionMessage,
LastExecutionTime = model.Body.LastExecutionTime LastExecutionTime = model.Body.LastExecutionTime
}; };

Loading…
Cancel
Save