2021-08-04 20:42:40 +00:00
|
|
|
using System.Collections.Generic;
|
2017-09-04 02:20:56 +00:00
|
|
|
using System.Linq;
|
2020-01-03 12:49:24 +00:00
|
|
|
using Lidarr.Http;
|
2021-08-04 20:42:40 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-09-04 02:20:56 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2021-01-25 04:33:54 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2017-09-04 02:20:56 +00:00
|
|
|
using NzbDrone.Core.Update;
|
2021-01-25 04:33:54 +00:00
|
|
|
using NzbDrone.Core.Update.History;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2017-10-31 01:28:29 +00:00
|
|
|
namespace Lidarr.Api.V1.Update
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2021-08-04 20:42:40 +00:00
|
|
|
[V1ApiController]
|
|
|
|
public class UpdateController : Controller
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
2021-01-25 04:33:54 +00:00
|
|
|
private readonly IUpdateHistoryService _updateHistoryService;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2021-01-25 04:33:54 +00:00
|
|
|
public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService)
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
_recentUpdateProvider = recentUpdateProvider;
|
2021-01-25 04:33:54 +00:00
|
|
|
_updateHistoryService = updateHistoryService;
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
[HttpGet]
|
|
|
|
public List<UpdateResource> GetRecentUpdates()
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2021-01-25 04:33:54 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return resources;
|
|
|
|
}
|
|
|
|
}
|
2020-01-03 12:49:24 +00:00
|
|
|
}
|