New: Show User Agent in System->Tasks for externally triggered commands (#2261)

This commit is contained in:
Robin Dadswell 2021-05-23 06:27:22 +01:00 committed by GitHub
parent 9b673c028a
commit bc6261efb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 1 deletions

View file

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

View file

@ -156,6 +156,7 @@ class QueuedTaskRow extends Component {
status, status,
duration, duration,
message, message,
clientUserAgent,
longDateFormat, longDateFormat,
timeFormat, timeFormat,
onCancelPress onCancelPress
@ -191,7 +192,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}
@ -255,6 +267,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,

View file

@ -57,6 +57,8 @@ namespace Lidarr.Api.V1.Commands
command.SuppressMessages = !command.SendUpdatesToClient; command.SuppressMessages = !command.SendUpdatesToClient;
command.SendUpdatesToClient = true; command.SendUpdatesToClient = true;
command.ClientUserAgent = Request.Headers.UserAgent;
var trackedCommand = _commandQueueManager.Push(command, CommandPriority.Normal, CommandTrigger.Manual); var trackedCommand = _commandQueueManager.Push(command, CommandPriority.Normal, CommandTrigger.Manual);
return trackedCommand.Id; return trackedCommand.Id;
} }

View file

@ -4,6 +4,7 @@ using System.Linq;
using Lidarr.Http.REST; using Lidarr.Http.REST;
using Newtonsoft.Json; using Newtonsoft.Json;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
namespace Lidarr.Api.V1.Commands namespace Lidarr.Api.V1.Commands
@ -23,6 +24,8 @@ namespace Lidarr.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 Lidarr.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
}; };

View file

@ -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;
}
}
}

View file

@ -32,6 +32,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", "");