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

This commit is contained in:
Taloth Saldono 2021-05-16 12:41:53 +02:00
parent 91fe47ef31
commit fe8f319f7b
7 changed files with 56 additions and 1 deletions

View File

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

View File

@ -156,6 +156,7 @@ class QueuedTaskRow extends Component {
status,
duration,
message,
clientUserAgent,
longDateFormat,
timeFormat,
onCancelPress
@ -191,7 +192,17 @@ class QueuedTaskRow extends Component {
</span>
</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>
}
</TableRowCell>
<TableRowCell
className={styles.queued}

View File

@ -4,6 +4,7 @@ using System.Linq;
using Newtonsoft.Json;
using Sonarr.Http.REST;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Common.Http;
namespace NzbDrone.Api.Commands
{
@ -21,6 +22,8 @@ namespace NzbDrone.Api.Commands
public string Exception { get; set; }
public CommandTrigger Trigger { get; set; }
public string ClientUserAgent { get; set; }
[JsonIgnore]
public string CompletionMessage { get; set; }
@ -117,6 +120,8 @@ namespace NzbDrone.Api.Commands
Exception = model.Exception,
Trigger = model.Trigger,
ClientUserAgent = UserAgentParser.SimplifyUserAgent(model.Body.ClientUserAgent),
CompletionMessage = model.Body.CompletionMessage,
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

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

View File

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

View File

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