mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-27 20:44:00 +02:00
Initial Push
This commit is contained in:
46
src/Prowlarr.Api.V1/Update/UpdateModule.cs
Normal file
46
src/Prowlarr.Api.V1/Update/UpdateModule.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Update;
|
||||
using Prowlarr.Http;
|
||||
|
||||
namespace Prowlarr.Api.V1.Update
|
||||
{
|
||||
public class UpdateModule : ProwlarrRestModule<UpdateResource>
|
||||
{
|
||||
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
||||
|
||||
public UpdateModule(IRecentUpdateProvider recentUpdateProvider)
|
||||
{
|
||||
_recentUpdateProvider = recentUpdateProvider;
|
||||
GetResourceAll = GetRecentUpdates;
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
return resources;
|
||||
}
|
||||
}
|
||||
}
|
57
src/Prowlarr.Api.V1/Update/UpdateResource.cs
Normal file
57
src/Prowlarr.Api.V1/Update/UpdateResource.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Update;
|
||||
using Prowlarr.Http.REST;
|
||||
|
||||
namespace Prowlarr.Api.V1.Update
|
||||
{
|
||||
public class UpdateResource : RestResource
|
||||
{
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
|
||||
public Version Version { get; set; }
|
||||
|
||||
public string Branch { get; set; }
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public string Url { get; set; }
|
||||
public bool Installed { get; set; }
|
||||
public bool Installable { get; set; }
|
||||
public bool Latest { get; set; }
|
||||
public UpdateChanges Changes { get; set; }
|
||||
public string Hash { get; set; }
|
||||
}
|
||||
|
||||
public static class UpdateResourceMapper
|
||||
{
|
||||
public static UpdateResource ToResource(this UpdatePackage model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new UpdateResource
|
||||
{
|
||||
Version = model.Version,
|
||||
|
||||
Branch = model.Branch,
|
||||
ReleaseDate = model.ReleaseDate,
|
||||
FileName = model.FileName,
|
||||
Url = model.Url,
|
||||
|
||||
//Installed
|
||||
//Installable
|
||||
//Latest
|
||||
Changes = model.Changes,
|
||||
Hash = model.Hash,
|
||||
};
|
||||
}
|
||||
|
||||
public static List<UpdateResource> ToResource(this IEnumerable<UpdatePackage> models)
|
||||
{
|
||||
return models.Select(ToResource).ToList();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user