1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-03-05 13:20:20 -05:00

Add v5 System endpoints

This commit is contained in:
Mark McDowall
2025-10-12 13:15:51 +09:00
parent 4f7425086e
commit fc0c26c2b3
2 changed files with 167 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Internal;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Lifecycle;
using Sonarr.Http;
using Sonarr.Http.Validation;
namespace Sonarr.Api.V5.System;
[V5ApiController]
public class SystemController : Controller
{
private readonly IAppFolderInfo _appFolderInfo;
private readonly IRuntimeInfo _runtimeInfo;
private readonly IPlatformInfo _platformInfo;
private readonly IOsInfo _osInfo;
private readonly IConfigFileProvider _configFileProvider;
private readonly IMainDatabase _database;
private readonly ILifecycleService _lifecycleService;
private readonly IDeploymentInfoProvider _deploymentInfoProvider;
private readonly EndpointDataSource _endpointData;
private readonly DfaGraphWriter _graphWriter;
private readonly DuplicateEndpointDetector _detector;
public SystemController(IAppFolderInfo appFolderInfo,
IRuntimeInfo runtimeInfo,
IPlatformInfo platformInfo,
IOsInfo osInfo,
IConfigFileProvider configFileProvider,
IMainDatabase database,
ILifecycleService lifecycleService,
IDeploymentInfoProvider deploymentInfoProvider,
EndpointDataSource endpoints,
DfaGraphWriter graphWriter,
DuplicateEndpointDetector detector)
{
_appFolderInfo = appFolderInfo;
_runtimeInfo = runtimeInfo;
_platformInfo = platformInfo;
_osInfo = osInfo;
_configFileProvider = configFileProvider;
_database = database;
_lifecycleService = lifecycleService;
_deploymentInfoProvider = deploymentInfoProvider;
_endpointData = endpoints;
_graphWriter = graphWriter;
_detector = detector;
}
[HttpGet("status")]
[Produces("application/json")]
public SystemResource GetStatus()
{
return new SystemResource
{
AppName = BuildInfo.AppName,
InstanceName = _configFileProvider.InstanceName,
Version = BuildInfo.Version.ToString(),
BuildTime = BuildInfo.BuildDateTime,
IsDebug = BuildInfo.IsDebug,
IsProduction = RuntimeInfo.IsProduction,
IsAdmin = _runtimeInfo.IsAdmin,
IsUserInteractive = RuntimeInfo.IsUserInteractive,
StartupPath = _appFolderInfo.StartUpFolder,
AppData = _appFolderInfo.GetAppDataPath(),
OsName = _osInfo.Name,
OsVersion = _osInfo.Version,
IsNetCore = true,
IsLinux = OsInfo.IsLinux,
IsOsx = OsInfo.IsOsx,
IsWindows = OsInfo.IsWindows,
IsDocker = _osInfo.IsDocker,
Mode = _runtimeInfo.Mode,
Branch = _configFileProvider.Branch,
Authentication = _configFileProvider.AuthenticationMethod,
DatabaseType = _database.DatabaseType,
DatabaseVersion = _database.Version,
MigrationVersion = _database.Migration,
UrlBase = _configFileProvider.UrlBase,
RuntimeVersion = _platformInfo.Version,
RuntimeName = PlatformInfo.PlatformName,
StartTime = _runtimeInfo.StartTime,
PackageVersion = _deploymentInfoProvider.PackageVersion,
PackageAuthor = _deploymentInfoProvider.PackageAuthor,
PackageUpdateMechanism = _deploymentInfoProvider.PackageUpdateMechanism,
PackageUpdateMechanismMessage = _deploymentInfoProvider.PackageUpdateMechanismMessage
};
}
[HttpGet("routes")]
[Produces("application/json")]
public IActionResult GetRoutes()
{
using (var sw = new StringWriter())
{
_graphWriter.Write(_endpointData, sw);
var graph = sw.ToString();
return Content(graph, "text/plain");
}
}
[HttpGet("routes/duplicate")]
[Produces("application/json")]
public object DuplicateRoutes()
{
return _detector.GetDuplicateEndpoints(_endpointData);
}
[HttpPost("shutdown")]
public object Shutdown()
{
Task.Factory.StartNew(() => _lifecycleService.Shutdown());
return new { ShuttingDown = true };
}
[HttpPost("restart")]
public object Restart()
{
Task.Factory.StartNew(() => _lifecycleService.Restart());
return new { Restarting = true };
}
}

View File

@@ -0,0 +1,41 @@
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Authentication;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Update;
namespace Sonarr.Api.V5.System;
public class SystemResource
{
public required string AppName { get; set; }
public required string InstanceName { get; set; }
public required string Version { get; set; }
public DateTime BuildTime { get; set; }
public bool IsDebug { get; set; }
public bool IsProduction { get; set; }
public bool IsAdmin { get; set; }
public bool IsUserInteractive { get; set; }
public required string StartupPath { get; set; }
public required string AppData { get; set; }
public required string OsName { get; set; }
public required string OsVersion { get; set; }
public bool IsNetCore { get; set; }
public bool IsLinux { get; set; }
public bool IsOsx { get; set; }
public bool IsWindows { get; set; }
public bool IsDocker { get; set; }
public RuntimeMode Mode { get; set; }
public required string Branch { get; set; }
public AuthenticationType Authentication { get; set; }
public int MigrationVersion { get; set; }
public required string UrlBase { get; set; }
public required Version RuntimeVersion { get; set; }
public required string RuntimeName { get; set; }
public DateTime StartTime { get; set; }
public required string PackageVersion { get; set; }
public required string PackageAuthor { get; set; }
public UpdateMechanism PackageUpdateMechanism { get; set; }
public required string PackageUpdateMechanismMessage { get; set; }
public required Version DatabaseVersion { get; set; }
public DatabaseType DatabaseType { get; set; }
}