You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/Lidarr.Api.V1/Update/UpdateController.cs

65 lines
2.1 KiB

using System.Collections.Generic;
using System.Linq;
using Lidarr.Http;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Update;
using NzbDrone.Core.Update.History;
namespace Lidarr.Api.V1.Update
{
[V1ApiController]
public class UpdateController : Controller
{
private readonly IRecentUpdateProvider _recentUpdateProvider;
private readonly IUpdateHistoryService _updateHistoryService;
public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService)
{
_recentUpdateProvider = recentUpdateProvider;
_updateHistoryService = updateHistoryService;
}
[HttpGet]
[Produces("application/json")]
public List<UpdateResource> GetRecentUpdates()
{
var resources = _recentUpdateProvider.GetRecentUpdatePackages()
.OrderByDescending(u => u.Version)
.ToResource();
if (resources.Any())
{
var first = resources.First();
first.Latest = true;
if (first.Version > BuildInfo.Version)
{
first.Installable = true;
}
var installed = resources.SingleOrDefault(r => r.Version == BuildInfo.Version);
if (installed != null)
{
installed.Installed = true;
}
var installDates = _updateHistoryService.InstalledSince(resources.Last().ReleaseDate)
.DistinctBy(v => v.Version)
.ToDictionary(v => v.Version);
foreach (var resource in resources)
{
if (installDates.TryGetValue(resource.Version, out var installDate))
{
resource.InstalledOn = installDate.Date;
}
}
}
return resources;
}
}
}