using System; using System.Collections.Generic; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using NzbDrone.Common.Cache; using NzbDrone.Core.Configuration; namespace Lidarr.Http.Ping { public class PingController : Controller { private readonly IConfigRepository _configRepository; private readonly ICached> _cache; public PingController(IConfigRepository configRepository, ICacheManager cacheManager) { _configRepository = configRepository; _cache = cacheManager.GetCache>(GetType()); } [AllowAnonymous] [HttpGet("/ping")] [HttpHead("/ping")] [Produces("application/json")] public ActionResult GetStatus() { try { _cache.Get("ping", _configRepository.All, TimeSpan.FromSeconds(5)); } catch (Exception) { return StatusCode(StatusCodes.Status500InternalServerError, new PingResource { Status = "Error" }); } return StatusCode(StatusCodes.Status200OK, new PingResource { Status = "OK" }); } } }