From d1741c8b757cc839f78023d6049d965c956733c0 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 5 Dec 2022 21:30:27 -0600 Subject: [PATCH] API Updates Fixes #2011 Fixes #1376 Fixes #1379 Co-Authored-By: Mark McDowall --- src/Readarr.Api.V1/System/SystemController.cs | 4 +- src/Readarr.Api.V1/System/SystemResource.cs | 43 +++++++++++++++++++ src/Readarr.Http/Ping/PingController.cs | 39 +++++++++++++++++ src/Readarr.Http/Ping/PingResource.cs | 7 +++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/Readarr.Api.V1/System/SystemResource.cs create mode 100644 src/Readarr.Http/Ping/PingController.cs create mode 100644 src/Readarr.Http/Ping/PingResource.cs diff --git a/src/Readarr.Api.V1/System/SystemController.cs b/src/Readarr.Api.V1/System/SystemController.cs index 9c13bdbc8..f352a7c21 100644 --- a/src/Readarr.Api.V1/System/SystemController.cs +++ b/src/Readarr.Api.V1/System/SystemController.cs @@ -54,9 +54,9 @@ namespace Readarr.Api.V1.System } [HttpGet("status")] - public object GetStatus() + public SystemResource GetStatus() { - return new + return new SystemResource { AppName = BuildInfo.AppName, InstanceName = _configFileProvider.InstanceName, diff --git a/src/Readarr.Api.V1/System/SystemResource.cs b/src/Readarr.Api.V1/System/SystemResource.cs new file mode 100644 index 000000000..ed87bf0ee --- /dev/null +++ b/src/Readarr.Api.V1/System/SystemResource.cs @@ -0,0 +1,43 @@ +using System; +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Core.Authentication; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Update; + +namespace Readarr.Api.V1.System +{ + public class SystemResource + { + public string AppName { get; set; } + public string InstanceName { get; set; } + public 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 string StartupPath { get; set; } + public string AppData { get; set; } + public string OsName { get; set; } + public 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 string Branch { get; set; } + public DatabaseType DatabaseType { get; set; } + public Version DatabaseVersion { get; set; } + public AuthenticationType Authentication { get; set; } + public int MigrationVersion { get; set; } + public string UrlBase { get; set; } + public Version RuntimeVersion { get; set; } + public string RuntimeName { get; set; } + public DateTime StartTime { get; set; } + public string PackageVersion { get; set; } + public string PackageAuthor { get; set; } + public UpdateMechanism PackageUpdateMechanism { get; set; } + public string PackageUpdateMechanismMessage { get; set; } + } +} diff --git a/src/Readarr.Http/Ping/PingController.cs b/src/Readarr.Http/Ping/PingController.cs new file mode 100644 index 000000000..2b1451bef --- /dev/null +++ b/src/Readarr.Http/Ping/PingController.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NzbDrone.Core.Configuration; + +namespace Readarr.Http.Ping +{ + public class PingController : Controller + { + private readonly IConfigRepository _configRepository; + + public PingController(IConfigRepository configRepository) + { + _configRepository = configRepository; + } + + [HttpGet("/ping")] + [Produces("application/json")] + public ActionResult GetStatus() + { + try + { + _configRepository.All(); + } + catch (Exception) + { + return StatusCode(StatusCodes.Status500InternalServerError, new PingResource + { + Status = "Error" + }); + } + + return StatusCode(StatusCodes.Status200OK, new PingResource + { + Status = "OK" + }); + } + } +} diff --git a/src/Readarr.Http/Ping/PingResource.cs b/src/Readarr.Http/Ping/PingResource.cs new file mode 100644 index 000000000..a5a225efb --- /dev/null +++ b/src/Readarr.Http/Ping/PingResource.cs @@ -0,0 +1,7 @@ +namespace Readarr.Http.Ping +{ + public class PingResource + { + public string Status { get; set; } + } +}